Visual Servoing Platform  version 3.0.0
vpIoTools.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 void getUserName(std::string &username);
156  static std::string getUserName();
157  static std::string getenv(const char *env);
158  static std::string getenv(const std::string &env);
159  static std::string getViSPImagesDataPath();
160  static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch);
161  static bool checkDirectory(const char *dirname);
162  static bool checkDirectory(const std::string &dirname);
163  static bool checkFilename(const char *filename);
164  static bool checkFilename(const std::string &filename);
165  static bool copy(const char *src, const char *dst);
166  static bool copy(const std::string &src, const std::string &dst);
167  static void makeDirectory(const char *dirname);
168  static void makeDirectory(const std::string &dirname);
169  static bool remove(const char *filename);
170  static bool remove(const std::string &filename);
171  static bool rename(const char *oldfilename, const char *newfilename);
172  static bool rename(const std::string &oldfilename, const std::string &newfilename);
173 
174  static std::string path(const char * pathname);
175  static std::string path(const std::string &pathname);
176 
180  static const char separator =
181  #if defined(_WIN32)
182  '\\';
183  #else
184  '/';
185  #endif
186 
187  static std::string getFileExtension(const std::string &pathname, const bool checkFile=false);
188  static std::string getName(const std::string &pathname);
189  static std::string getNameWE(const std::string &pathname);
190  static std::string getParent(const std::string& pathname);
191  static std::string createFilePath(const std::string& parent, const std::string child);
192  static bool isAbsolutePathname(const std::string& pathname);
193  static std::pair<std::string, std::string> splitDrive(const std::string& pathname);
194  static std::vector<std::string> splitChain(const std::string & chain, const std::string & sep);
195 
200  // read configuration file
201  static bool loadConfigFile(const std::string &confFile);
202  static bool readConfigVar(const std::string &var, float &value);
203  static bool readConfigVar(const std::string &var, double &value);
204  static bool readConfigVar(const std::string &var, int &value);
205  static bool readConfigVar(const std::string &var, unsigned int &value);
206  static bool readConfigVar(const std::string &var, bool &value);
207  static bool readConfigVar(const std::string &var, std::string &value);
208  static bool readConfigVar(const std::string &var, vpColor &value);
209  static bool readConfigVar(const std::string &var, vpArray2D<double> &value,
210  const unsigned int &nCols = 0,
211  const unsigned int &nRows = 0);
212 
213  // construct experiment filename & path
214  static void setBaseName(const std::string &s);
215  static void setBaseDir(const std::string &dir);
216  static void addNameElement(const std::string &strTrue,
217  const bool &cond=true,
218  const std::string &strFalse="");
219  static void addNameElement(const std::string &strTrue, const double &val);
220  static std::string getBaseName();
221  static std::string getFullName();
222 
223  // write files
224  static void saveConfigFile(const bool &actuallySave = true);
225  static void createBaseNamePath(const bool &empty = false);
227 
228  protected:
229  static std::string baseName;
230  static std::string baseDir;
231  static std::string configFile;
232  static std::vector<std::string> configVars;
233  static std::vector<std::string> configValues;
234 } ;
235 
236 
237 #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:230
static std::vector< std::string > configVars
Definition: vpIoTools.h:232
static std::string baseName
Definition: vpIoTools.h:229
static std::string configFile
Definition: vpIoTools.h:231
static std::vector< std::string > configValues
Definition: vpIoTools.h:233