ViSP  2.10.0
vpIoTools.h
1 /****************************************************************************
2  *
3  * $Id: vpIoTools.h 5197 2015-01-23 17:24:22Z strinh $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Directory management.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
42 
43 #ifndef vpIoTools_HH
44 #define vpIoTools_HH
45 
51 #include <visp/vpConfig.h>
52 
53 #include <iostream>
54 #include <sstream>
55 #include <string>
56 #include <stdlib.h>
57 #include <vector>
58 #include <visp/vpColor.h>
59 
155 class VISP_EXPORT vpIoTools
156 {
157 
158 public:
159  static void getUserName(std::string &username);
160  static std::string getUserName();
161  static std::string getenv(const char *env);
162  static std::string getenv(const std::string &env);
163  static std::string getViSPImagesDataPath();
164  static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch);
165  static bool checkDirectory(const char *dirname);
166  static bool checkDirectory(const std::string &dirname);
167  static bool checkFilename(const char *filename);
168  static bool checkFilename(const std::string &filename);
169  static bool copy(const char *src, const char *dst);
170  static bool copy(const std::string &src, const std::string &dst);
171  static void makeDirectory(const char *dirname);
172  static void makeDirectory(const std::string &dirname);
173  static bool remove(const char *filename);
174  static bool remove(const std::string &filename);
175  static bool rename(const char *oldfilename, const char *newfilename);
176  static bool rename(const std::string &oldfilename, const std::string &newfilename);
177 
178  static std::string path(const char * pathname);
179  static std::string path(const std::string &pathname);
180 
184  static const char separator =
185  #if defined(_WIN32)
186  '\\';
187  #else
188  '/';
189  #endif
190 
191  static std::string getFileExtension(const std::string &pathname, const bool checkFile=false);
192  static std::string getName(const std::string &pathname);
193  static std::string getNameWE(const std::string &pathname);
194  static std::string getParent(const std::string& pathname);
195  static std::string createFilePath(const std::string& parent, const std::string child);
196  static bool isAbsolutePathname(const std::string& pathname);
197  static std::pair<std::string, std::string> splitDrive(const std::string& pathname);
198 
199  // read configuration file
200  static bool loadConfigFile(const std::string &confFile);
201  static bool readConfigVar(const std::string &var, float &value);
202  static bool readConfigVar(const std::string &var, double &value);
203  static bool readConfigVar(const std::string &var, int &value);
204  static bool readConfigVar(const std::string &var, unsigned int &value);
205  static bool readConfigVar(const std::string &var, bool &value);
206  static bool readConfigVar(const std::string &var, std::string &value);
207  static bool readConfigVar(const std::string &var, vpColor &value);
208  static bool readConfigVar(const std::string &var, vpMatrix &value,
209  const unsigned int &nCols = 0,
210  const unsigned int &nRows = 0);
211 
212  // construct experiment filename & path
218  inline static void setBaseName(const std::string &s) {baseName = s;}
224  static inline void setBaseDir(const std::string &dir) {baseDir = dir + "/";}
225  static void addNameElement(const std::string &strTrue,
226  const bool &cond=true,
227  const std::string &strFalse="");
228  static void addNameElement(const std::string &strTrue, const double &val);
234  inline static std::string getBaseName() {return baseName;}
240  inline static std::string getFullName() {return baseDir + baseName;}
241 
242  // write files
243  static void saveConfigFile(const bool &actuallySave = true);
244  static void createBaseNamePath(const bool &empty = false);
245 
246  protected:
247  static std::string baseName;
248  static std::string baseDir;
249  static std::string configFile;
250  static std::vector<std::string> configVars;
251  static std::vector<std::string> configValues;
252 } ;
253 
254 
255 #endif
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
static void setBaseDir(const std::string &dir)
Definition: vpIoTools.h:224
File and directories basic tools.
Definition: vpIoTools.h:155
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
static std::string baseDir
Definition: vpIoTools.h:248
static std::string getBaseName()
Definition: vpIoTools.h:234
static std::string getFullName()
Definition: vpIoTools.h:240
static std::vector< std::string > configVars
Definition: vpIoTools.h:250
static std::string baseName
Definition: vpIoTools.h:247
static std::string configFile
Definition: vpIoTools.h:249
static void setBaseName(const std::string &s)
Definition: vpIoTools.h:218
static std::vector< std::string > configValues
Definition: vpIoTools.h:251