/usr/include/visp/vpIoTools.h is in libvisp-dev 2.8.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | /****************************************************************************
*
* $Id: vpIoTools.h 4275 2013-06-25 12:35:42Z fspindle $
*
* This file is part of the ViSP software.
* Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* ("GPL") version 2 as published by the Free Software Foundation.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact INRIA about acquiring a ViSP Professional
* Edition License.
*
* See http://www.irisa.fr/lagadic/visp/visp.html for more information.
*
* This software was developed at:
* INRIA Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
* http://www.irisa.fr/lagadic
*
* If you have questions regarding the use of this file, please contact
* INRIA at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*
* Description:
* Directory management.
*
* Authors:
* Fabien Spindler
*
*****************************************************************************/
#ifndef vpIoTools_HH
#define vpIoTools_HH
/*!
\file vpIoTools.h
\brief File and directories basic tools.
*/
#include <visp/vpConfig.h>
#include <iostream>
#include <sstream>
#include <string>
#include <stdlib.h>
#include <vector>
#include <visp/vpColor.h>
/*!
\class vpIoTools
\ingroup FileDirectories
\brief File and directories basic tools.
The example below shows how to manipulate the functions of this
class to create first a directory which name corresponds to the user
name and then create a file in this directory.
\code
#include <iostream>
#include <string>
#include <fstream>
#include <visp/vpIoTools.h>
int main()
{
std::string username;
vpIoTools::getUserName(username);
// Test if a username directory exist. If no try to create it
if (vpIoTools::checkDirectory(username) == false) {
try {
// Create a directory with name "username"
vpIoTools::makeDirectory(username);
}
catch (...) {
std::cout << "Cannot create " << username << " directory" << std::endl;
return false;
}
}
// Create a empty filename with name "username/file.txt"
std::ofstream f;
std::string filename = username + "/file.txt";
filename = vpIoTools::path(filename); // Under Windows converts the filename string into "username\\file.txt"
std::cout << "Create: " << filename << std::endl;
f.open(filename.c_str());
f.close();
// Rename the file
std::string newfilename = username + "/newfile.txt";
std::cout << "Rename: " << filename << " in: " << newfilename << std::endl;
if (vpIoTools::rename(filename, newfilename) == false)
std::cout << "Unable to rename: " << filename << std::endl;
// Remove the file
std::cout << "Remove: " << newfilename << std::endl;
if (vpIoTools::remove(newfilename) == false)
std::cout << "Unable to remove: " << newfilename << std::endl;
}
\endcode
The example below shows how to read a configuration file and how to create a name for experiment files.
We assume the following file "/home/user/demo/config.txt" :
\code
expNumber 2
save 0
lambda 0.4
use2D 0
use3D 1
\endcode
\code
#include <iostream>
#include <string>
#include <visp/vpIoTools.h>
int main()
{
// reading configuration file
vpIoTools::loadConfigFile("/home/user/demo/config.txt");
std::string nExp;vpIoTools::readConfigVar("expNumber", nExp); // nExp <- "2"
double lambda;vpIoTools::readConfigVar("lambda", lambda); // lambda <- 0.4
bool use2D;vpIoTools::readConfigVar("use2D", use2D); // use2D <- false
bool use3D;vpIoTools::readConfigVar("use3D", use3D); // use3D <- true
bool doSave;vpIoTools::readConfigVar("save", doSave); // doSave <- false
// creating name for experiment files
vpIoTools::setBaseDir("/home/user/data");
vpIoTools::setBaseName("exp" + nExp); // full name <- "/home/user/data/exp2"
vpIoTools::addNameElement("2D", use2D); // full name <- "/home/user/data/exp2" since use2D==false
vpIoTools::addNameElement("3D", use3D); // full name <- "/home/user/data/exp2_3D"
vpIoTools::addNameElement("lambda", lambda); // full name <- "/home/user/data/exp2_3D_lambda0.4"
// saving file
vpIoTools::saveConfigFile(doSave); // would copy "/home/user/demo/config.txt" to "/home/user/data/exp2_3D_lambda0.4_config.txt" if doSave was true
// create sub directory
vpIoTools::createBaseNamePath(); // creates "/home/user/data/exp2_3D_lambda0.4/"
}
\endcode
*/
class VISP_EXPORT vpIoTools
{
public:
static void getUserName(std::string &username);
static std::string getUserName();
static std::string getenv(const char *env);
static std::string getenv(std::string &env);
static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch);
static bool checkDirectory(const char *dirname);
static bool checkDirectory(const std::string &dirname);
static bool checkFilename(const char *filename);
static bool checkFilename(const std::string &filename);
static bool copy(const char *src, const char *dst);
static bool copy(const std::string &src, const std::string &dst);
static void makeDirectory(const char *dirname);
static void makeDirectory(const std::string &dirname);
static bool remove(const char *filename);
static bool remove(const std::string &filename);
static bool rename(const char *oldfilename, const char *newfilename);
static bool rename(const std::string &oldfilename,
const std::string &newfilename);
static std::string path(const char * pathname);
static std::string path(const std::string &pathname);
// read configuration file
static bool loadConfigFile(const std::string &confFile);
static bool readConfigVar(const std::string &var, float &value);
static bool readConfigVar(const std::string &var, double &value);
static bool readConfigVar(const std::string &var, int &value);
static bool readConfigVar(const std::string &var, unsigned int &value);
static bool readConfigVar(const std::string &var, bool &value);
static bool readConfigVar(const std::string &var, std::string &value);
static bool readConfigVar(const std::string &var, vpColor &value);
static bool readConfigVar(const std::string &var, vpMatrix &value,
const unsigned int &nCols = 0,
const unsigned int &nRows = 0);
// construct experiment filename & path
/*!
Sets the base name (prefix) of the experiment files.
\param s : Prefix of the experiment files.
*/
inline static void setBaseName(const std::string &s) {baseName = s;}
/*!
Sets the base directory of the experiment files.
\param dir : Directory where the data will be saved.
*/
static inline void setBaseDir(const std::string &dir) {baseDir = dir + "/";}
static void addNameElement(const std::string &strTrue,
const bool &cond=true,
const std::string &strFalse="");
static void addNameElement(const std::string &strTrue, const double &val);
/*!
Gets the base name (prefix) of the experiment files.
\return the base name of the experiment files.
*/
inline static std::string getBaseName() {return baseName;}
/*!
Gets the full path of the experiment files : baseDir/baseName
\return the full path of the experiment files.
*/
inline static std::string getFullName() {return baseDir + baseName;}
// write files
static void saveConfigFile(const bool &actuallySave = true);
static void createBaseNamePath(const bool &empty = false);
protected:
static std::string baseName;
static std::string baseDir;
static std::string configFile;
static std::vector<std::string> configVars;
static std::vector<std::string> configValues;
} ;
#endif
|