Visual Servoing Platform  version 3.5.1 under development (2023-09-22)
vpIoTools.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 
34 #ifndef _vpIoTools_h_
35 #define _vpIoTools_h_
36 
42 #include <visp3/core/vpConfig.h>
43 
44 #include <iostream>
45 #include <sstream>
46 #include <stdint.h> //for uint32_t related types ; works also with >= VS2010 / _MSC_VER >= 1600
47 #include <stdlib.h>
48 #include <string>
49 #include <vector>
50 #include <visp3/core/vpColor.h>
51 
153 class VISP_EXPORT vpIoTools
154 {
155 
156 public:
157  static const std::string &getBuildInformation();
158  static std::string getTempPath();
159  static void getUserName(std::string &username);
160  static std::string getUserName();
161  static std::string getenv(const std::string &env);
162  static std::string getViSPImagesDataPath();
163  static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch);
164  static bool checkDirectory(const std::string &dirname);
165  static bool checkFifo(const std::string &filename);
166  static bool checkFilename(const std::string &filename);
167  static bool copy(const std::string &src, const std::string &dst);
168 
169  static void makeDirectory(const std::string &dirname);
170  static void makeFifo(const std::string &dirname);
171  static std::string makeTempDirectory(const std::string &dirname);
172  static std::string path(const std::string &pathname);
173 
174  static bool remove(const std::string &filename);
175  static bool rename(const std::string &oldfilename, const std::string &newfilename);
176 
181  static const char separator =
182 #if defined(_WIN32)
183  '\\';
184 #else
185  '/';
186 #endif
187  static std::string toUpperCase(const std::string &input);
188  static std::string toLowerCase(const std::string &input);
189  static std::string getAbsolutePathname(const std::string &pathname);
190  static std::string getFileExtension(const std::string &pathname, bool checkFile = false);
191  static long getIndex(const std::string &filename, const std::string &format);
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 bool isSamePathname(const std::string &pathname1, const std::string &pathname2);
198  static std::pair<std::string, std::string> splitDrive(const std::string &pathname);
199  static std::vector<std::string> splitChain(const std::string &chain, const std::string &sep);
200  static std::vector<std::string> getDirFiles(const std::string &dirname);
201 
206  // read configuration file
207  static bool loadConfigFile(const std::string &confFile);
208  static bool readConfigVar(const std::string &var, float &value);
209  static bool readConfigVar(const std::string &var, double &value);
210  static bool readConfigVar(const std::string &var, int &value);
211  static bool readConfigVar(const std::string &var, unsigned int &value);
212  static bool readConfigVar(const std::string &var, bool &value);
213  static bool readConfigVar(const std::string &var, std::string &value);
214  static bool readConfigVar(const std::string &var, vpColor &value);
215  static bool readConfigVar(const std::string &var, vpArray2D<double> &value, const unsigned int &nCols = 0,
216  const unsigned int &nRows = 0);
217 
218  // construct experiment filename & path
219  static void setBaseName(const std::string &s);
220  static void setBaseDir(const std::string &dir);
221  static void addNameElement(const std::string &strTrue, const bool &cond = true, 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  static void readBinaryValueLE(std::ifstream &file, int16_t &short_value);
232  static void readBinaryValueLE(std::ifstream &file, uint16_t &ushort_value);
233  static void readBinaryValueLE(std::ifstream &file, int32_t &int_value);
234  static void readBinaryValueLE(std::ifstream &file, uint32_t &int_value);
235  static void readBinaryValueLE(std::ifstream &file, float &float_value);
236  static void readBinaryValueLE(std::ifstream &file, double &double_value);
237 
238  static void writeBinaryValueLE(std::ofstream &file, const int16_t short_value);
239  static void writeBinaryValueLE(std::ofstream &file, const uint16_t ushort_value);
240  static void writeBinaryValueLE(std::ofstream &file, const int32_t int_value);
241  static void writeBinaryValueLE(std::ofstream &file, const uint32_t int_value);
242  static void writeBinaryValueLE(std::ofstream &file, float float_value);
243  static void writeBinaryValueLE(std::ofstream &file, double double_value);
244 
245  static bool parseBoolean(std::string input);
246  static std::string trim(std::string s);
247 
248 protected:
249  static std::string baseName;
250  static std::string baseDir;
251  static std::string configFile;
252  static std::vector<std::string> configVars;
253  static std::vector<std::string> configValues;
254 
255 #ifndef DOXYGEN_SHOULD_SKIP_THIS
256  static int mkdir_p(const std::string &path, int mode);
257 #endif
258 };
259 #endif
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
File and directories basic tools.
Definition: vpIoTools.h:154
static std::vector< std::string > configVars
Definition: vpIoTools.h:252
static std::string baseDir
Definition: vpIoTools.h:250
static std::string baseName
Definition: vpIoTools.h:249
static std::string configFile
Definition: vpIoTools.h:251
static std::vector< std::string > configValues
Definition: vpIoTools.h:253