torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DirectoryTree.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Source for the DirectoryTree class.
18 
20 #include <boost/filesystem/convenience.hpp>
21 #include <cstdio>
22 
23 namespace torc {
24 namespace common {
25 
31 
32  /// \brief Name of the devices directory.
33  /// \todo This should be obtained from a configuration file.
34  const std::string cDevicesNameConst("devices");
35 
36  /// \brief Name of the torc directory.
37  /// \todo This should be obtained from a configuration file.
38  const std::string cTorcNameConst("torc");
39 
40  DirectoryTree::DirectoryTree(const char* argv0) {
41  // resolve symbolic links for the executable if necessary
42  boost::filesystem::path argvPath(argv0);
43  char buffer[FILENAME_MAX];
44  ssize_t count = readlink(argv0, buffer, sizeof(buffer));
45  if(count != -1) {
46  buffer[count] = 0;
47  argvPath = buffer;
48  //std::cout << "Resolving symbolic link " << argv[0] << " to executable name " << path
49  // << std::endl;
50  }
51  //std::cout << ">>>> argvPath: " << argvPath << std::endl;
52  // get the working directory and the relative executable path
53  sWorkingPath = boost::filesystem::initial_path();
54  //std::cout << ">>>> sWorkingPath: " << sWorkingPath << std::endl;
55  sRelativePath = argvPath.parent_path(); // so much for relative paths ...
56  //std::cout << ">>>> sRelativePath: " << sRelativePath << std::endl;
57  // get the executable path
59  // build the eda and log paths
61  // build the database path
63  if(!exists(sDevicesPath))
65 
66  // normalize each of the paths
67  sRelativePath.normalize();
68  sWorkingPath.normalize();
69  sExecutablePath.normalize();
70  sDevicesPath.normalize();
71  sLogPath.normalize();
72  }
73 
74 } // namespace common
75 } // namespace torc
DirectoryTree(const char *argv0)
Mandatory constructor.
Header for the DirectoryTree class.
static boost::filesystem::path sWorkingPath
Absolute path to the working directory.
std::string string
boost::filesystem::path path
const std::string cTorcNameConst("torc")
Name of the torc directory.
static boost::filesystem::path sExecutablePath
Absolute path to the executable directory.
static boost::filesystem::path sLogPath
Absolute path to the log files directory.
static boost::filesystem::path sRelativePath
Relative path from the working directory to the executable home.
const std::string cDevicesNameConst("devices")
Name of the devices directory.
static boost::filesystem::path sDevicesPath
Absolute path to the family and device database directory.