ViSP  2.8.0
vpIoTools.h
1 /****************************************************************************
2  *
3  * $Id: vpIoTools.h 4275 2013-06-25 12:35:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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(std::string &env);
163  static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch);
164  static bool checkDirectory(const char *dirname);
165  static bool checkDirectory(const std::string &dirname);
166  static bool checkFilename(const char *filename);
167  static bool checkFilename(const std::string &filename);
168  static bool copy(const char *src, const char *dst);
169  static bool copy(const std::string &src, const std::string &dst);
170  static void makeDirectory(const char *dirname);
171  static void makeDirectory(const std::string &dirname);
172  static bool remove(const char *filename);
173  static bool remove(const std::string &filename);
174  static bool rename(const char *oldfilename, const char *newfilename);
175  static bool rename(const std::string &oldfilename,
176  const std::string &newfilename);
177 
178  static std::string path(const char * pathname);
179  static std::string path(const std::string &pathname);
180 
181  // read configuration file
182  static bool loadConfigFile(const std::string &confFile);
183  static bool readConfigVar(const std::string &var, float &value);
184  static bool readConfigVar(const std::string &var, double &value);
185  static bool readConfigVar(const std::string &var, int &value);
186  static bool readConfigVar(const std::string &var, unsigned int &value);
187  static bool readConfigVar(const std::string &var, bool &value);
188  static bool readConfigVar(const std::string &var, std::string &value);
189  static bool readConfigVar(const std::string &var, vpColor &value);
190  static bool readConfigVar(const std::string &var, vpMatrix &value,
191  const unsigned int &nCols = 0,
192  const unsigned int &nRows = 0);
193 
194  // construct experiment filename & path
200  inline static void setBaseName(const std::string &s) {baseName = s;}
206  static inline void setBaseDir(const std::string &dir) {baseDir = dir + "/";}
207  static void addNameElement(const std::string &strTrue,
208  const bool &cond=true,
209  const std::string &strFalse="");
210  static void addNameElement(const std::string &strTrue, const double &val);
216  inline static std::string getBaseName() {return baseName;}
222  inline static std::string getFullName() {return baseDir + baseName;}
223 
224  // write files
225  static void saveConfigFile(const bool &actuallySave = true);
226  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
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
static void setBaseDir(const std::string &dir)
Definition: vpIoTools.h:206
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:230
static std::string getBaseName()
Definition: vpIoTools.h:216
static std::string getFullName()
Definition: vpIoTools.h:222
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 void setBaseName(const std::string &s)
Definition: vpIoTools.h:200
static std::vector< std::string > configValues
Definition: vpIoTools.h:233