cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmnPath.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Anton Deguet
7  Created on: 2005-04-18
8 
9  (C) Copyright 2005-2012 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 
20 */
21 
22 
28 #pragma once
29 
30 #ifndef _cmnPath_h
31 #define _cmnPath_h
32 
36 
37 #include <string>
38 #include <list>
39 #include <sstream>
40 #include <iostream>
41 
42 // Always the last cisst include
43 #include <cisstCommon/cmnExport.h>
44 
45 
46 #if (CISST_OS == CISST_WINDOWS)
47 # include <io.h>
48 #else
49 # include <unistd.h>
50 #endif
51 
52 
70 
71 public:
73  typedef std::list<std::string> ContainerType;
74 
77  typedef ContainerType::iterator iterator;
78  typedef ContainerType::const_iterator const_iterator;
80 
81 private:
82  ContainerType Path;
83  cmnTokenizer Tokenizer;
84 
87  void ConfigureTokenizer(void);
88 
91  static std::string FromNative(const std::string & nativePath);
92 
93 public:
95  enum {HEAD = true,
96  TAIL = false
97  };
98 
100 #if (CISST_OS == CISST_WINDOWS)
101  enum {EXIST = 00,
102  WRITE = 02,
103  READ = 04,
104  EXECUTE = 04
105  };
106 #else
107  enum {READ = R_OK,
108  WRITE = W_OK,
109  EXECUTE = X_OK,
110  EXIST = F_OK
111  };
112 #endif
113 
114  cmnPath(void);
115 
117  cmnPath(const std::string & path);
118 
120  virtual ~cmnPath(void) {}
121 
123  void Set(const std::string & path);
124 
126  void Add(const std::string & path, bool head = HEAD);
127 
129  bool AddFromEnvironment(const std::string & variableName, bool head = HEAD);
130 
134  bool AddRelativeToCisstRoot(const std::string & relativePath, bool head = HEAD);
135 
138  bool AddRelativeToCisstShare(const std::string & relativePath, bool head = HEAD);
139 
143  std::string Find(const std::string & filename, short mode = READ) const;
144 
154  std::string FindWithSubdirectory(const std::string & filename,
155  const std::string & subdirectory,
156  short mode = READ) const;
157 
159  bool Remove(const std::string & directory);
160 
162  bool Has(const std::string & directory) const;
163 
165  void ToStream(std::ostream & outputStream) const;
166 
171  static const std::string & DirectorySeparator(void);
172 
174  static std::string GetWorkingDirectory(void);
175 
177  static bool GetCisstRoot(std::string & result);
178 
181  static bool GetCisstShare(std::string & result);
182 
186  static bool Exists(const std::string & fullPath, short more = READ);
187 };
188 
189 
190 // Add services instantiation
192 
193 
194 #endif // _cmnPath_h
195 
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
ContainerType::iterator iterator
Definition: cmnPath.h:77
Portability across compilers and operating systems tools.
Search path to find a file. This class contains a list of directories used to locate a file...
Definition: cmnPath.h:68
Base class for high level objects.
Definition: cmnGenericObject.h:51
Definition: cmnTokenizer.h:65
virtual ~cmnPath(void)
Definition: cmnPath.h:120
Macros to export the symbols of cisstCommon (in a Dll).
virtual void ToStream(std::ostream &outputStream) const
Defines cmnGenericObject.
Break strings into tokens.
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
std::list< std::string > ContainerType
Definition: cmnPath.h:73
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
ContainerType::const_iterator const_iterator
Definition: cmnPath.h:78
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition: cmnClassRegisterMacros.h:202
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76