cisst-saw
Loading...
Searching...
No Matches
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 Author(s): Anton Deguet
6 Created on: 2005-04-18
7
8 (C) Copyright 2005-2023 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17
18*/
19
20
26#pragma once
27
28#ifndef _cmnPath_h
29#define _cmnPath_h
30
34
35#include <string>
36#include <list>
37#include <sstream>
38#include <iostream>
39
40// Always the last cisst include
42
43
44#if (CISST_OS == CISST_WINDOWS)
45# include <io.h>
46#else
47# include <unistd.h>
48#endif
49
50
68
69public:
71 typedef std::list<std::string> ContainerType;
72
75 typedef ContainerType::iterator iterator;
76 typedef ContainerType::const_iterator const_iterator;
78
79private:
80 ContainerType Path;
81 cmnTokenizer Tokenizer;
82
85 void ConfigureTokenizer(void);
86
89 static std::string FromNative(const std::string & nativePath);
90
91public:
93 enum {HEAD = true,
94 TAIL = false
95 };
96
98#if (CISST_OS == CISST_WINDOWS)
99 enum {EXIST = 00,
100 WRITE = 02,
101 READ = 04,
103 };
104#else
105 enum {READ = R_OK,
106 WRITE = W_OK,
107 EXECUTE = X_OK,
108 EXIST = F_OK
109 };
110#endif
111
112 cmnPath(void);
113
115 cmnPath(const std::string & path);
116
118 virtual ~cmnPath(void) {}
119
121 void Set(const std::string & path);
122
124 void Add(const std::string & path, bool head = HEAD);
125
127 bool AddFromEnvironment(const std::string & variableName, bool head = HEAD);
128
132 bool AddRelativeToCisstRoot(const std::string & relativePath, bool head = HEAD);
133
136 bool AddRelativeToCisstShare(const std::string & relativePath, bool head = HEAD);
137
141 std::string Find(const std::string & filename, short mode = READ) const;
142
152 std::string FindWithSubdirectory(const std::string & filename,
153 const std::string & subdirectory,
154 short mode = READ) const;
155
157 bool Remove(const std::string & directory);
158
160 bool Has(const std::string & directory) const;
161
163 void ToStream(std::ostream & outputStream) const override;
164
169 static const std::string & DirectorySeparator(void);
170
172 static std::string GetWorkingDirectory(void);
173
175 static bool GetCisstRoot(std::string & result);
176
179 static bool GetCisstShare(std::string & result);
180
184 static bool Exists(const std::string & fullPath, short more = READ);
185
187 static bool DeleteFile(const std::string & fullPath);
188
190 static bool RenameFile(const std::string & fullPathOld,
191 const std::string & fullPathNew);
192
197 inline static std::string SharedLibrary(const std::string & name) {
199 }
200
205 inline static std::string Executable(const std::string & name) {
206 return name + CISST_EXECUTABLE_SUFFIX;
207 }
208};
209
210
211// Add services instantiation
213
214
215#endif // _cmnPath_h
#define CISST_SHARED_LIBRARY_SUFFIX
Definition cisstConfig.h:37
#define CISST_EXECUTABLE_SUFFIX
Definition cisstConfig.h:40
#define CISST_SHARED_LIBRARY_PREFIX
Definition cisstConfig.h:36
Base class for high level objects.
Definition cmnGenericObject.h:53
Search path to find a file. This class contains a list of directories used to locate a file.
Definition cmnPath.h:66
void ToStream(std::ostream &outputStream) const override
static const std::string & DirectorySeparator(void)
void Set(const std::string &path)
std::string FindWithSubdirectory(const std::string &filename, const std::string &subdirectory, short mode=READ) const
static bool DeleteFile(const std::string &fullPath)
std::string Find(const std::string &filename, short mode=READ) const
ContainerType::iterator iterator
Definition cmnPath.h:75
static bool GetCisstShare(std::string &result)
@ HEAD
Definition cmnPath.h:93
@ TAIL
Definition cmnPath.h:94
static std::string GetWorkingDirectory(void)
bool AddRelativeToCisstShare(const std::string &relativePath, bool head=HEAD)
@ EXIST
Definition cmnPath.h:99
@ WRITE
Definition cmnPath.h:100
@ EXECUTE
Definition cmnPath.h:102
@ READ
Definition cmnPath.h:101
bool AddFromEnvironment(const std::string &variableName, bool head=HEAD)
void Add(const std::string &path, bool head=HEAD)
bool Remove(const std::string &directory)
ContainerType::const_iterator const_iterator
Definition cmnPath.h:76
virtual ~cmnPath(void)
Definition cmnPath.h:118
std::list< std::string > ContainerType
Definition cmnPath.h:71
static std::string Executable(const std::string &name)
Definition cmnPath.h:205
cmnPath(const std::string &path)
bool AddRelativeToCisstRoot(const std::string &relativePath, bool head=HEAD)
bool Has(const std::string &directory) const
static bool Exists(const std::string &fullPath, short more=READ)
cmnPath(void)
static bool RenameFile(const std::string &fullPathOld, const std::string &fullPathNew)
static std::string SharedLibrary(const std::string &name)
Definition cmnPath.h:197
static bool GetCisstRoot(std::string &result)
Definition cmnTokenizer.h:66
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition cmnClassRegisterMacros.h:199
const int CMN_NO_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:325
Macros to export the symbols of cisstCommon (in a Dll).
#define CISST_EXPORT
Definition cmnExportMacros.h:50
Defines cmnGenericObject.
#define CMN_LOG_ALLOW_DEFAULT
Definition cmnLogLoD.h:76
Portability across compilers and operating systems tools.
Break strings into tokens.