Visual Servoing Platform  version 3.5.1 under development (2022-12-04)
vpIoTools.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Directory management.
33  *
34  * Authors:
35  * Fabien Spindler
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 <stdint.h> //for uint32_t related types ; works also with >= VS2010 / _MSC_VER >= 1600
52 #include <stdlib.h>
53 #include <string>
54 #include <vector>
55 #include <visp3/core/vpColor.h>
56 
158 class VISP_EXPORT vpIoTools
159 {
160 
161 public:
162  static const std::string &getBuildInformation();
163  static std::string getTempPath();
164  static void getUserName(std::string &username);
165  static std::string getUserName();
166  static std::string getenv(const std::string &env);
167  static std::string getViSPImagesDataPath();
168  static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch);
169  static bool checkDirectory(const std::string &dirname);
170  static bool checkFifo(const std::string &filename);
171  static bool checkFilename(const std::string &filename);
172  static bool copy(const std::string &src, const std::string &dst);
173 
174  static void makeDirectory(const std::string &dirname);
175  static void makeFifo(const std::string &dirname);
176  static std::string makeTempDirectory(const std::string &dirname);
177  static std::string path(const std::string &pathname);
178 
179  static bool remove(const std::string &filename);
180  static bool rename(const std::string &oldfilename, const std::string &newfilename);
181 
186  static const char separator =
187 #if defined(_WIN32)
188  '\\';
189 #else
190  '/';
191 #endif
192 
193  static std::string getAbsolutePathname(const std::string &pathname);
194  static std::string getFileExtension(const std::string &pathname, bool checkFile = false);
195  static long getIndex(const std::string &filename, const std::string &format);
196  static std::string getName(const std::string &pathname);
197  static std::string getNameWE(const std::string &pathname);
198  static std::string getParent(const std::string &pathname);
199  static std::string createFilePath(const std::string &parent, const std::string &child);
200  static bool isAbsolutePathname(const std::string &pathname);
201  static bool isSamePathname(const std::string &pathname1, const std::string &pathname2);
202  static std::pair<std::string, std::string> splitDrive(const std::string &pathname);
203  static std::vector<std::string> splitChain(const std::string &chain, const std::string &sep);
204  static std::vector<std::string> getDirFiles(const std::string &dirname);
205 
210  // read configuration file
211  static bool loadConfigFile(const std::string &confFile);
212  static bool readConfigVar(const std::string &var, float &value);
213  static bool readConfigVar(const std::string &var, double &value);
214  static bool readConfigVar(const std::string &var, int &value);
215  static bool readConfigVar(const std::string &var, unsigned int &value);
216  static bool readConfigVar(const std::string &var, bool &value);
217  static bool readConfigVar(const std::string &var, std::string &value);
218  static bool readConfigVar(const std::string &var, vpColor &value);
219  static bool readConfigVar(const std::string &var, vpArray2D<double> &value, const unsigned int &nCols = 0,
220  const unsigned int &nRows = 0);
221 
222  // construct experiment filename & path
223  static void setBaseName(const std::string &s);
224  static void setBaseDir(const std::string &dir);
225  static void addNameElement(const std::string &strTrue, const bool &cond = true, const std::string &strFalse = "");
226  static void addNameElement(const std::string &strTrue, const double &val);
227  static std::string getBaseName();
228  static std::string getFullName();
229 
230  // write files
231  static void saveConfigFile(const bool &actuallySave = true);
232  static void createBaseNamePath(const bool &empty = false);
234 
235  static void readBinaryValueLE(std::ifstream &file, int16_t &short_value);
236  static void readBinaryValueLE(std::ifstream &file, uint16_t &ushort_value);
237  static void readBinaryValueLE(std::ifstream &file, int32_t &int_value);
238  static void readBinaryValueLE(std::ifstream &file, uint32_t &int_value);
239  static void readBinaryValueLE(std::ifstream &file, float &float_value);
240  static void readBinaryValueLE(std::ifstream &file, double &double_value);
241 
242  static void writeBinaryValueLE(std::ofstream &file, const int16_t short_value);
243  static void writeBinaryValueLE(std::ofstream &file, const uint16_t ushort_value);
244  static void writeBinaryValueLE(std::ofstream &file, const int32_t int_value);
245  static void writeBinaryValueLE(std::ofstream &file, const uint32_t int_value);
246  static void writeBinaryValueLE(std::ofstream &file, float float_value);
247  static void writeBinaryValueLE(std::ofstream &file, double double_value);
248 
249  static bool parseBoolean(std::string input);
250  static std::string trim(std::string s);
251 
252 protected:
253  static std::string baseName;
254  static std::string baseDir;
255  static std::string configFile;
256  static std::vector<std::string> configVars;
257  static std::vector<std::string> configValues;
258 
259 #ifndef DOXYGEN_SHOULD_SKIP_THIS
260  static int mkdir_p(const char *path, int mode);
261 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
262 };
263 #endif
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:158
File and directories basic tools.
Definition: vpIoTools.h:159
static std::vector< std::string > configVars
Definition: vpIoTools.h:256
static std::string baseDir
Definition: vpIoTools.h:254
static std::string baseName
Definition: vpIoTools.h:253
static std::string configFile
Definition: vpIoTools.h:255
static std::vector< std::string > configValues
Definition: vpIoTools.h:257