CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Path.cpp
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2022 by Sofia Contarini *
3  * sofia.contarini3@unibo.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ********************************************************************/
20 
34 #include "Path.h"
35 
36 // ============================================================================
37 
39 {
40  SetDirs(DIRCOSMO, "./");
41 }
42 
43 // ============================================================================
44 
45 std::string cbl::Path::fullpath (std::string path, const bool isDir)
46 {
47  const std::string find = "~";
48  const std::string replace = getenv("HOME");
49  char buff[PATH_MAX];
50 
51  size_t pos = 0;
52  while ((pos=path.find(find, pos))!=std::string::npos) {
53  path.replace(pos, find.length(), replace);
54  pos += replace.length();
55  }
56 
57  return std::string(realpath(path.c_str(),buff))+((isDir) ? "/" : "");
58 }
The class Path used to handle the Cosmobolognalib paths.
std::string fullpath(std::string path, const bool isDir=true)
substitute ~ with the full path
Definition: Path.cpp:45
void SetDirs(const std::string input_DirCosmo, const std::string input_DirLoc="./")
set the default directories
Definition: Path.h:195
Path()
default constructor
Definition: Path.cpp:38