Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpIoTools.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Directory management.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
38 
39 #ifndef vpIoTools_HH
40 #define vpIoTools_HH
41 
47 #include <visp3/core/vpConfig.h>
48 
49 #include <iostream>
50 #include <sstream>
51 #include <string>
52 #include <stdlib.h>
53 #include <vector>
54 #include <visp3/core/vpColor.h>
55 
151 class VISP_EXPORT vpIoTools
152 {
153 
154 public:
155  static const std::string& getBuildInformation();
156  static void getUserName(std::string &username);
157  static std::string getUserName();
158  static std::string getenv(const char *env);
159  static std::string getenv(const std::string &env);
160  static std::string getViSPImagesDataPath();
161  static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch);
162  static bool checkDirectory(const char *dirname);
163  static bool checkDirectory(const std::string &dirname);
164  static bool checkFilename(const char *filename);
165  static bool checkFilename(const std::string &filename);
166  static bool copy(const char *src, const char *dst);
167  static bool copy(const std::string &src, const std::string &dst);
168  static void makeDirectory(const char *dirname);
169  static void makeDirectory(const std::string &dirname);
170  static bool remove(const char *filename);
171  static bool remove(const std::string &filename);
172  static bool rename(const char *oldfilename, const char *newfilename);
173  static bool rename(const std::string &oldfilename, const std::string &newfilename);
174 
175  static std::string path(const char * pathname);
176  static std::string path(const std::string &pathname);
177 
181  static const char separator =
182  #if defined(_WIN32)
183  '\\';
184  #else
185  '/';
186  #endif
187 
188  static std::string getAbsolutePathname(const std::string &pathname);
189  static std::string getFileExtension(const std::string &pathname, const bool checkFile=false);
190  static std::string getName(const std::string &pathname);
191  static std::string getNameWE(const std::string &pathname);
192  static std::string getParent(const std::string& pathname);
193  static std::string createFilePath(const std::string& parent, const std::string child);
194  static bool isAbsolutePathname(const std::string& pathname);
195  static bool isSamePathname(const std::string& pathname1, const std::string& pathname2);
196  static std::pair<std::string, std::string> splitDrive(const std::string& pathname);
197  static std::vector<std::string> splitChain(const std::string & chain, const std::string & sep);
198 
203  // read configuration file
204  static bool loadConfigFile(const std::string &confFile);
205  static bool readConfigVar(const std::string &var, float &value);
206  static bool readConfigVar(const std::string &var, double &value);
207  static bool readConfigVar(const std::string &var, int &value);
208  static bool readConfigVar(const std::string &var, unsigned int &value);
209  static bool readConfigVar(const std::string &var, bool &value);
210  static bool readConfigVar(const std::string &var, std::string &value);
211  static bool readConfigVar(const std::string &var, vpColor &value);
212  static bool readConfigVar(const std::string &var, vpArray2D<double> &value,
213  const unsigned int &nCols = 0,
214  const unsigned int &nRows = 0);
215 
216  // construct experiment filename & path
217  static void setBaseName(const std::string &s);
218  static void setBaseDir(const std::string &dir);
219  static void addNameElement(const std::string &strTrue,
220  const bool &cond=true,
221  const std::string &strFalse="");
222  static void addNameElement(const std::string &strTrue, const double &val);
223  static std::string getBaseName();
224  static std::string getFullName();
225 
226  // write files
227  static void saveConfigFile(const bool &actuallySave = true);
228  static void createBaseNamePath(const bool &empty = false);
230 
231  protected:
232  static std::string baseName;
233  static std::string baseDir;
234  static std::string configFile;
235  static std::vector<std::string> configVars;
236  static std::vector<std::string> configValues;
237 } ;
238 
239 
240 #endif
File and directories basic tools.
Definition: vpIoTools.h:151
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
static std::string baseDir
Definition: vpIoTools.h:233
static std::vector< std::string > configVars
Definition: vpIoTools.h:235
static std::string baseName
Definition: vpIoTools.h:232
static std::string configFile
Definition: vpIoTools.h:234
static std::vector< std::string > configValues
Definition: vpIoTools.h:236