Visual Servoing Platform  version 3.1.0
vpIoTools.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 
43 #include <algorithm>
44 #include <cmath>
45 #include <errno.h>
46 #include <fcntl.h>
47 #include <fstream>
48 #include <limits>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <sys/stat.h>
53 #include <sys/types.h>
54 #include <visp3/core/vpDebug.h>
55 #include <visp3/core/vpIoException.h>
56 #include <visp3/core/vpIoTools.h>
57 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
58 #include <dirent.h>
59 #include <unistd.h>
60 #elif defined(_WIN32)
61 #include <direct.h>
62 #include <windows.h>
63 #endif
64 #if !defined(_WIN32)
65 #include <wordexp.h>
66 #endif
67 
68 #if defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin)
69 #include <TargetConditionals.h> // To detect OSX or IOS using TARGET_OS_IOS macro
70 #endif
71 
72 #ifndef PATH_MAX
73 #define PATH_MAX _MAX_PATH
74 #endif
75 
76 std::string vpIoTools::baseName = "";
77 std::string vpIoTools::baseDir = "";
78 std::string vpIoTools::configFile = "";
79 std::vector<std::string> vpIoTools::configVars = std::vector<std::string>();
80 std::vector<std::string> vpIoTools::configValues = std::vector<std::string>();
81 
82 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
83  // wordexp() is not available
84 namespace
85 {
86 void replaceAll(std::string &str, const std::string &search, const std::string &replace)
87 {
88  size_t start_pos = 0;
89  while ((start_pos = str.find(search, start_pos)) != std::string::npos) {
90  str.replace(start_pos, search.length(), replace);
91  start_pos += replace.length(); // Handles case where 'replace' is a
92  // substring of 'search'
93  }
94 }
95 }
96 #endif
97 
101 const std::string &vpIoTools::getBuildInformation()
102 {
103  static std::string build_info =
104 #include "version_string.inc"
105  ;
106  return build_info;
107 }
108 
114 void vpIoTools::setBaseName(const std::string &s) { baseName = s; }
120 void vpIoTools::setBaseDir(const std::string &dir) { baseDir = dir + "/"; }
126 std::string vpIoTools::getBaseName() { return baseName; }
132 std::string vpIoTools::getFullName() { return baseDir + baseName; }
133 
151 void vpIoTools::getUserName(std::string &username)
152 {
153 // With MinGW, UNIX and _WIN32 are defined
154 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
155  // Get the user name.
156  char *_username = NULL;
157  _username = ::getenv("LOGNAME");
158  if (_username == NULL) {
159  vpERROR_TRACE("Cannot get the username. Check your LOGNAME environment variable");
160  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username"));
161  }
162  username = _username;
163 #elif defined(_WIN32)
164 #if (!defined(WINRT))
165  unsigned int info_buffer_size = 1024;
166  TCHAR *infoBuf = new TCHAR[info_buffer_size];
167  DWORD bufCharCount = (DWORD)info_buffer_size;
168  // Get the user name.
169  if (!GetUserName(infoBuf, &bufCharCount)) {
170  delete[] infoBuf;
171  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username"));
172  }
173  username = infoBuf;
174  delete[] infoBuf;
175 #else
176  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username: not implemented on Universal "
177  "Windows Platform"));
178 #endif
179 #endif
180 }
199 {
200  std::string username;
201 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
202  // Get the user name.
203  char *_username = NULL;
204  _username = ::getenv("LOGNAME");
205  if (_username == NULL) {
206  vpERROR_TRACE("Cannot get the username. Check your LOGNAME environment variable");
207  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username"));
208  }
209  username = _username;
210 #elif defined(_WIN32)
211 #if (!defined(WINRT))
212  unsigned int info_buffer_size = 1024;
213  TCHAR *infoBuf = new TCHAR[info_buffer_size];
214  DWORD bufCharCount = (DWORD)info_buffer_size;
215  // Get the user name.
216  if (!GetUserName(infoBuf, &bufCharCount)) {
217  delete[] infoBuf;
218  vpERROR_TRACE("Cannot get the username");
219  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username"));
220  }
221  username = infoBuf;
222  delete[] infoBuf;
223 #else
224  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username: not implemented on Universal "
225  "Windows Platform"));
226 #endif
227 #endif
228  return username;
229 }
230 
262 std::string vpIoTools::getenv(const char *env)
263 {
264 #if defined(_WIN32) && defined(WINRT)
265  throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value: not "
266  "implemented on Universal Windows Platform"));
267 #else
268  std::string value;
269  // Get the environment variable value.
270  char *_value = NULL;
271  _value = ::getenv(env);
272  if (_value == NULL) {
273  throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value"));
274  }
275  value = _value;
276 
277  return value;
278 #endif
279 }
280 
313 std::string vpIoTools::getenv(const std::string &env) { return (vpIoTools::getenv(env.c_str())); }
314 
324 void vpIoTools::getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
325 {
326  if (version.size() == 0) {
327  major = 0;
328  minor = 0;
329  patch = 0;
330  } else {
331  size_t major_pos = version.find('.');
332  std::string major_str = version.substr(0, major_pos);
333  major = (unsigned)atoi(major_str.c_str());
334 
335  if (major_pos != std::string::npos) {
336  size_t minor_pos = version.find('.', major_pos + 1);
337  std::string minor_str = version.substr(major_pos + 1, (minor_pos - (major_pos + 1)));
338  minor = (unsigned)atoi(minor_str.c_str());
339 
340  if (minor_pos != std::string::npos) {
341  std::string patch_str = version.substr(minor_pos + 1);
342  patch = (unsigned)atoi(patch_str.c_str());
343  } else {
344  patch = 0;
345  }
346  } else {
347  minor = 0;
348  patch = 0;
349  }
350  }
351 }
352 
367 bool vpIoTools::checkDirectory(const char *dirname)
368 {
369 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
370  struct stat stbuf;
371 #elif defined(_WIN32) && defined(__MINGW32__)
372  struct stat stbuf;
373 #elif defined(_WIN32)
374  struct _stat stbuf;
375 #endif
376 
377  if (dirname == NULL || dirname[0] == '\0') {
378  return false;
379  }
380 
381  std::string _dirname = path(dirname);
382 
383 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
384  if (stat(_dirname.c_str(), &stbuf) != 0)
385 #elif defined(_WIN32) && defined(__MINGW32__)
386  // Remove trailing separator character if any
387  // AppVeyor: Windows 6.3.9600 AMD64 ; C:/MinGW/bin/g++.exe (ver 5.3.0) ;
388  // GNU Make 3.82.90 Built for i686-pc-mingw32
389  if (!_dirname.empty() && _dirname.at(_dirname.size() - 1) == vpIoTools::separator)
390  _dirname = _dirname.substr(0, _dirname.size() - 1);
391  if (stat(_dirname.c_str(), &stbuf) != 0)
392 #elif defined(_WIN32)
393  if (_stat(_dirname.c_str(), &stbuf) != 0)
394 #endif
395  {
396  return false;
397  }
398 #if defined(_WIN32) || (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
399  if ((stbuf.st_mode & S_IFDIR) == 0)
400 #endif
401  {
402  return false;
403  }
404 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
405  if ((stbuf.st_mode & S_IWUSR) == 0)
406 #elif defined(_WIN32)
407  if ((stbuf.st_mode & S_IWRITE) == 0)
408 #endif
409  {
410  return false;
411  }
412  return true;
413 }
414 
428 bool vpIoTools::checkDirectory(const std::string &dirname) { return vpIoTools::checkDirectory(dirname.c_str()); }
429 
430 // See:
431 // https://gist.github.com/JonathonReinhart/8c0d90191c38af2dcadb102c4e202950
432 int vpIoTools::mkdir_p(const char *path, const int mode)
433 {
434  /* Adapted from http://stackoverflow.com/a/2336245/119527 */
435  const size_t len = strlen(path);
436  char _path[PATH_MAX];
437  char *p = NULL;
438  const char sep = vpIoTools::separator;
439 
440  errno = 0;
441  if (len > sizeof(_path) - 1) {
442  errno = ENAMETOOLONG;
443  return -1;
444  }
445  /* Copy string so its mutable */
446  strcpy(_path, path);
447 
448  /* Iterate over the string */
449  for (p = _path + 1; *p; p++) { // path cannot be empty
450  if (*p == sep) {
451  /* Temporarily truncate */
452  *p = '\0';
453 
454 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
455  if (mkdir(_path, (mode_t)mode) != 0)
456 #elif defined(_WIN32)
457  (void)mode; // var not used
458  if (!checkDirectory(_path) && _mkdir(_path) != 0)
459 #endif
460  {
461  if (errno != EEXIST)
462  return -1;
463  }
464  *p = sep;
465  }
466  }
467 
468 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
469  if (mkdir(_path, (mode_t)mode) != 0)
470 #elif defined(_WIN32)
471  if (_mkdir(_path) != 0)
472 #endif
473  {
474  if (errno != EEXIST)
475  return -1;
476  }
477 
478  return 0;
479 }
480 
495 void vpIoTools::makeDirectory(const char *dirname)
496 {
497 #if ((!defined(__unix__) && !defined(__unix) && (!defined(__APPLE__) || !defined(__MACH__)))) && !defined(_WIN32)
498  std::cerr << "Unsupported platform for vpIoTools::makeDirectory()!" << std::endl;
499  return;
500 #endif
501 
502 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
503  struct stat stbuf;
504 #elif defined(_WIN32) && defined(__MINGW32__)
505  struct stat stbuf;
506 #elif defined(_WIN32)
507  struct _stat stbuf;
508 #endif
509 
510  if (dirname == NULL || dirname[0] == '\0') {
511  vpERROR_TRACE("invalid directory name\n");
512  throw(vpIoException(vpIoException::invalidDirectoryName, "invalid directory name"));
513  }
514 
515  std::string _dirname = path(dirname);
516 
517 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
518  if (stat(_dirname.c_str(), &stbuf) != 0)
519 #elif defined(_WIN32) && defined(__MINGW32__)
520  if (stat(_dirname.c_str(), &stbuf) != 0)
521 #elif defined(_WIN32)
522  if (_stat(_dirname.c_str(), &stbuf) != 0)
523 #endif
524  {
525  if (vpIoTools::mkdir_p(_dirname.c_str(), 0755) != 0) {
526  vpERROR_TRACE("unable to create directory '%s'\n", dirname);
527  throw(vpIoException(vpIoException::cantCreateDirectory, "unable to create directory"));
528  }
529 
530  vpDEBUG_TRACE(2, "has created directory '%s'\n", dirname);
531  }
532 
533  if (checkDirectory(dirname) == false) {
534  vpERROR_TRACE("unable to create directory '%s'\n", dirname);
535  throw(vpIoException(vpIoException::cantCreateDirectory, "unable to create directory"));
536  }
537 }
538 
551 void vpIoTools::makeDirectory(const std::string &dirname)
552 {
553  try {
554  vpIoTools::makeDirectory(dirname.c_str());
555  } catch (...) {
556  vpERROR_TRACE("unable to create directory '%s'\n", dirname.c_str());
557  throw(vpIoException(vpIoException::cantCreateDirectory, "unable to create directory"));
558  }
559 }
560 
573 bool vpIoTools::checkFilename(const char *filename)
574 {
575 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
576  struct stat stbuf;
577 #elif defined(_WIN32)
578  struct _stat stbuf;
579 #endif
580 
581  if (filename == NULL || filename[0] == '\0') {
582  return false;
583  }
584 
585  std::string _filename = path(filename);
586 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
587  if (stat(_filename.c_str(), &stbuf) != 0)
588 #elif defined(_WIN32)
589  if (_stat(_filename.c_str(), &stbuf) != 0)
590 #endif
591  {
592  return false;
593  }
594  if ((stbuf.st_mode & S_IFREG) == 0) {
595  return false;
596  }
597 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
598  if ((stbuf.st_mode & S_IRUSR) == 0)
599 #elif defined(_WIN32)
600  if ((stbuf.st_mode & S_IREAD) == 0)
601 #endif
602  {
603  return false;
604  }
605  return true;
606 }
607 
620 bool vpIoTools::checkFilename(const std::string &filename) { return vpIoTools::checkFilename(filename.c_str()); }
621 
634 bool vpIoTools::copy(const char *src, const char *dst)
635 {
636  // Check if we have to consider a file or a directory
637  if (vpIoTools::checkFilename(src)) {
638 // std::cout << "copy file: " << src << " in " << dst << std::endl;
639 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
640 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
641  // wordexp() is not available
642  char cmd[FILENAME_MAX];
643  int ret;
644  sprintf(cmd, "cp -p %s %s", src, dst);
645  ret = system(cmd);
646  if (ret) {
647  }; // to avoid a warning
648  // std::cout << cmd << " return value: " << ret << std::endl;
649  return true;
650 #else
651  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src, dst));
652 #endif
653 #elif defined(_WIN32)
654 #if (!defined(WINRT))
655  char cmd[FILENAME_MAX];
656  int ret;
657  std::string src_ = vpIoTools::path(src);
658  std::string dst_ = vpIoTools::path(dst);
659  sprintf(cmd, "copy %s %s", src_.c_str(), dst_.c_str());
660  ret = system(cmd);
661  if (ret) {
662  }; // to avoid a warning
663  // std::cout << cmd << " return value: " << ret << std::endl;
664  return true;
665 #else
666  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
667  src, dst));
668 #endif
669 #endif
670  } else if (vpIoTools::checkDirectory(src)) {
671 // std::cout << "copy directory: " << src << " in " << dst << std::endl;
672 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
673 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
674  // wordexp() is not available
675  char cmd[FILENAME_MAX];
676  int ret;
677  sprintf(cmd, "cp -p -r %s %s", src, dst);
678  ret = system(cmd);
679  if (ret) {
680  }; // to avoid a warning
681  // std::cout << cmd << " return value: " << ret << std::endl;
682  return true;
683 #else
684  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src, dst));
685 #endif
686 #elif defined(_WIN32)
687 #if (!defined(WINRT))
688  char cmd[FILENAME_MAX];
689  int ret;
690  std::string src_ = vpIoTools::path(src);
691  std::string dst_ = vpIoTools::path(dst);
692  sprintf(cmd, "copy %s %s", src_.c_str(), dst_.c_str());
693  ret = system(cmd);
694  if (ret) {
695  }; // to avoid a warning
696  // std::cout << cmd << " return value: " << ret << std::endl;
697  return true;
698 #else
699  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
700  src, dst));
701 #endif
702 #endif
703  } else {
704  std::cout << "Cannot copy: " << src << " in " << dst << std::endl;
705  return false;
706  }
707 }
720 bool vpIoTools::copy(const std::string &src, const std::string &dst)
721 {
722  return vpIoTools::copy(src.c_str(), dst.c_str());
723 }
724 
735 bool vpIoTools::remove(const char *file_or_dir)
736 {
737  // Check if we have to consider a file or a directory
738  if (vpIoTools::checkFilename(file_or_dir)) {
739  // std::cout << "remove file: " << file_or_dir << std::endl;
740  if (::remove(file_or_dir) != 0)
741  return false;
742  else
743  return true;
744  } else if (vpIoTools::checkDirectory(file_or_dir)) {
745 // std::cout << "remove directory: " << file_or_dir << std::endl;
746 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
747 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
748  // wordexp() is not available
749  char cmd[FILENAME_MAX];
750  sprintf(cmd, "rm -rf %s", file_or_dir);
751  int ret = system(cmd);
752  if (ret) {
753  }; // to avoid a warning
754  // std::cout << cmd << " return value: " << ret << std::endl;
755  return true;
756 #else
757  throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on iOS Platform", file_or_dir));
758 #endif
759 #elif defined(_WIN32)
760 #if (!defined(WINRT))
761  char cmd[FILENAME_MAX];
762  std::string file_or_dir_ = vpIoTools::path(file_or_dir);
763  sprintf(cmd, "rmdir /S /Q %s", file_or_dir_.c_str());
764  int ret = system(cmd);
765  if (ret) {
766  }; // to avoid a warning
767  // std::cout << cmd << " return value: " << ret << std::endl;
768  return true;
769 #else
770  throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on Universal Windows Platform",
771  file_or_dir));
772 #endif
773 #endif
774  } else {
775  std::cout << "Cannot remove: " << file_or_dir << std::endl;
776  return false;
777  }
778 }
790 bool vpIoTools::remove(const std::string &file_or_dir) { return vpIoTools::remove(file_or_dir.c_str()); }
791 
803 bool vpIoTools::rename(const char *oldfilename, const char *newfilename)
804 {
805  if (::rename(oldfilename, newfilename) != 0)
806  return false;
807  else
808  return true;
809 }
810 
822 bool vpIoTools::rename(const std::string &oldfilename, const std::string &newfilename)
823 {
824  return vpIoTools::rename(oldfilename.c_str(), newfilename.c_str());
825 }
826 
839 std::string vpIoTools::path(const char *pathname)
840 {
841  std::string path(pathname);
842 
843 #if defined(_WIN32)
844  for (unsigned int i = 0; i < path.length(); i++)
845  if (path[i] == '/')
846  path[i] = '\\';
847 #elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
848  for (unsigned int i = 0; i < path.length(); i++)
849  if (path[i] == '\\')
850  path[i] = '/';
851 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
852  // wordexp() is not available
853  wordexp_t exp_result;
854 
855  // escape quote character
856  replaceAll(path, "'", "'\\''");
857  // add quotes to handle special characters like parentheses and spaces
858  wordexp(std::string("'" + path + "'").c_str(), &exp_result, 0);
859  path = exp_result.we_wordc == 1 ? exp_result.we_wordv[0] : "";
860  wordfree(&exp_result);
861 #endif
862 #endif
863 
864  return path;
865 }
866 
879 std::string vpIoTools::path(const std::string &pathname) { return path(pathname.c_str()); }
880 
889 bool vpIoTools::loadConfigFile(const std::string &confFile)
890 {
891  configFile = path(confFile);
892  configVars.clear();
893  configValues.clear();
894  std::ifstream confContent(configFile.c_str(), std::ios::in);
895 
896  if (confContent.is_open()) {
897  std::string line, var, val;
898  long unsigned int k;
899  int c;
900  std::string stop[3] = {" ", "\t", "#"};
901  while (std::getline(confContent, line)) {
902  if ((line.compare(0, 1, "#") != 0) && (line.size() > 2)) {
903  try {
904  // name of the variable
905  k = (unsigned long)line.find(" ");
906  var = line.substr(0, k);
907  // look for the end of the actual value
908  c = 200;
909  for (unsigned i = 0; i < 3; ++i)
910  c = vpMath::minimum(c, (int)line.find(stop[i], k + 1));
911  if (c == -1)
912  c = (int)line.size();
913  long unsigned int c_ = (long unsigned int)c;
914  val = line.substr(k + 1, c_ - k - 1);
915  configVars.push_back(var);
916  configValues.push_back(val);
917  } catch (...) {
918  }
919  }
920  }
921  confContent.close();
922  } else {
923  return false;
924  }
925  return true;
926 }
927 
936 bool vpIoTools::readConfigVar(const std::string &var, float &value)
937 {
938  bool found = false;
939  for (unsigned int k = 0; k < configVars.size() && found == false; ++k) {
940  if (configVars[k] == var) {
941  if (configValues[k].compare("PI") == 0)
942  value = (float)M_PI;
943  else if (configValues[k].compare("PI/2") == 0)
944  value = (float)(M_PI / 2.0);
945  else if (configValues[k].compare("-PI/2") == 0)
946  value = (float)(-M_PI / 2.0);
947  else
948  value = (float)atof(configValues[k].c_str());
949  found = true;
950  }
951  }
952  if (found == false)
953  std::cout << var << " not found in config file" << std::endl;
954  return found;
955 }
964 bool vpIoTools::readConfigVar(const std::string &var, double &value)
965 {
966  bool found = false;
967  for (unsigned int k = 0; k < configVars.size() && found == false; ++k) {
968  if (configVars[k] == var) {
969  if (configValues[k].compare("PI") == 0)
970  value = M_PI;
971  else if (configValues[k].compare("PI/2") == 0)
972  value = M_PI / 2;
973  else if (configValues[k].compare("-PI/2") == 0)
974  value = -M_PI / 2;
975  else
976  value = atof(configValues[k].c_str());
977  found = true;
978  }
979  }
980  if (found == false)
981  std::cout << var << " not found in config file" << std::endl;
982  return found;
983 }
984 
993 bool vpIoTools::readConfigVar(const std::string &var, int &value)
994 {
995  bool found = false;
996  for (unsigned int k = 0; k < configVars.size() && found == false; ++k) {
997  if (configVars[k] == var) {
998  value = atoi(configValues[k].c_str());
999  found = true;
1000  }
1001  }
1002  if (found == false)
1003  std::cout << var << " not found in config file" << std::endl;
1004  return found;
1005 }
1006 
1015 bool vpIoTools::readConfigVar(const std::string &var, unsigned int &value)
1016 {
1017  int v = 0;
1018  bool found = readConfigVar(var, v);
1019  value = (unsigned int)v;
1020  return found;
1021 }
1022 
1031 bool vpIoTools::readConfigVar(const std::string &var, bool &value)
1032 {
1033  int v = 0;
1034  bool found = readConfigVar(var, v);
1035  value = (v != 0);
1036  return found;
1037 }
1038 
1047 bool vpIoTools::readConfigVar(const std::string &var, vpColor &value)
1048 {
1049  unsigned int v = 0;
1050  bool found = readConfigVar(var, v);
1051  value = vpColor::getColor(v);
1052  return found;
1053 }
1054 
1063 bool vpIoTools::readConfigVar(const std::string &var, std::string &value)
1064 {
1065  bool found = false;
1066  for (unsigned int k = 0; k < configVars.size() && found == false; ++k) {
1067  if (configVars[k] == var) {
1068  value = configValues[k];
1069  found = true;
1070  }
1071  }
1072  if (found == false)
1073  std::cout << var << " not found in config file" << std::endl;
1074  return found;
1075 }
1076 
1090 bool vpIoTools::readConfigVar(const std::string &var, vpArray2D<double> &value, const unsigned int &nCols,
1091  const unsigned int &nRows)
1092 {
1093  bool found = false;
1094  std::string nb;
1095  for (unsigned int k = 0; k < configVars.size() && found == false; ++k) {
1096  if (configVars[k] == var) {
1097  found = true;
1098  // resize or not
1099  if (nCols != 0 && nRows != 0)
1100  value.resize(nRows, nCols);
1101  size_t ind = 0, ind2;
1102  for (unsigned int i = 0; i < value.getRows(); ++i)
1103  for (unsigned int j = 0; j < value.getCols(); ++j) {
1104  ind2 = configValues[k].find(",", ind);
1105  nb = configValues[k].substr(ind, ind2 - ind);
1106  if (nb.compare("PI") == 0)
1107  value[i][j] = M_PI;
1108  else if (nb.compare("PI/2") == 0)
1109  value[i][j] = M_PI / 2;
1110  else if (nb.compare("-PI/2") == 0)
1111  value[i][j] = -M_PI / 2;
1112  else
1113  value[i][j] = atof(nb.c_str());
1114  ind = ind2 + 1;
1115  }
1116  }
1117  }
1118  if (found == false)
1119  std::cout << var << " not found in config file" << std::endl;
1120  return found;
1121 }
1122 
1123 // construct experiment filename & path
1124 
1133 void vpIoTools::addNameElement(const std::string &strTrue, const bool &cond, const std::string &strFalse)
1134 {
1135  if (cond)
1136  baseName += "_" + strTrue;
1137  else if (strFalse != "")
1138  baseName += "_" + strFalse;
1139 }
1140 
1149 void vpIoTools::addNameElement(const std::string &strTrue, const double &val)
1150 {
1151  // if(val != 0.)
1152  if (std::fabs(val) < std::numeric_limits<double>::epsilon()) {
1153  char valC[256];
1154  sprintf(valC, "%.3f", val);
1155  std::string valS(valC);
1156  baseName += "_" + strTrue + valS;
1157  }
1158 }
1159 
1168 void vpIoTools::createBaseNamePath(const bool &empty)
1169 {
1170  if (vpIoTools::checkDirectory(baseDir + baseName) == false) {
1172  std::cout << "creating directory " + baseDir + baseName << std::endl;
1173  } else {
1174  if (empty) {
1175  std::cout << "emptying directory " + baseDir + baseName << std::endl;
1177  }
1178  }
1179 }
1180 
1187 void vpIoTools::saveConfigFile(const bool &actuallySave)
1188 {
1189  if (actuallySave) {
1190  std::string dest = baseDir + "/" + baseName + "_config.txt";
1191  // file copy
1192  vpIoTools::copy(configFile, dest);
1193  }
1194 }
1195 
1211 {
1212  std::string data_path;
1213  std::string file_to_test("mbt/cube.cao");
1214  std::string filename;
1215 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1216  // Test if visp-images-data package is u-installed (Ubuntu and Debian)
1217  data_path = "/usr/share/visp-images-data/ViSP-images";
1218  filename = data_path + "/" + file_to_test;
1219  if (vpIoTools::checkFilename(filename))
1220  return data_path;
1221  data_path = "/usr/share/visp-images-data/visp-images";
1222  filename = data_path + "/" + file_to_test;
1223  if (vpIoTools::checkFilename(filename))
1224  return data_path;
1225 #endif
1226  // Test if VISP_INPUT_IMAGE_PATH env var is set
1227  try {
1228  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH");
1229  filename = data_path + "/" + file_to_test;
1230  if (vpIoTools::checkFilename(filename))
1231  return data_path;
1232  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/ViSP-images";
1233  filename = data_path + "/" + file_to_test;
1234  if (vpIoTools::checkFilename(filename))
1235  return data_path;
1236  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/visp-images";
1237  filename = data_path + "/" + file_to_test;
1238  if (vpIoTools::checkFilename(filename))
1239  return data_path;
1240  } catch (...) {
1241  }
1242  data_path = "";
1243  return data_path;
1244 }
1245 
1257 std::string vpIoTools::getFileExtension(const std::string &pathname, const bool checkFile)
1258 {
1259  if (checkFile && (vpIoTools::checkDirectory(pathname) || !vpIoTools::checkFilename(pathname))) {
1260  return "";
1261  }
1262 
1263 #if defined(_WIN32)
1264  std::string sep = "\\";
1265  std::string altsep = "/";
1266  std::string extsep = ".";
1267 #else
1268  // On Unix, or on the Mac
1269  std::string sep = "/";
1270  std::string altsep = "";
1271  std::string extsep = ".";
1272 #endif
1273 
1274  // Python 2.7.8 module.
1275  //# Split a path in root and extension.
1276  //# The extension is everything starting at the last dot in the last
1277  //# pathname component; the root is everything before that.
1278  //# It is always true that root + ext == p.
1279  //
1280  //# Generic implementation of splitext, to be parametrized with
1281  //# the separators
1282  // def _splitext(p, sep, altsep, extsep):
1283  // """Split the extension from a pathname.
1284  //
1285  // Extension is everything from the last dot to the end, ignoring
1286  // leading dots. Returns "(root, ext)"; ext may be empty."""
1287  //
1288  // sepIndex = p.rfind(sep)
1289  // if altsep:
1290  // altsepIndex = p.rfind(altsep)
1291  // sepIndex = max(sepIndex, altsepIndex)
1292  //
1293  // dotIndex = p.rfind(extsep)
1294  // if dotIndex > sepIndex:
1295  // # skip all leading dots
1296  // filenameIndex = sepIndex + 1
1297  // while filenameIndex < dotIndex:
1298  // if p[filenameIndex] != extsep:
1299  // return p[:dotIndex], p[dotIndex:]
1300  // filenameIndex += 1
1301  //
1302  // return p, ''
1303 
1304  int sepIndex = (int)pathname.rfind(sep);
1305  if (!altsep.empty()) {
1306  int altsepIndex = (int)pathname.rfind(altsep);
1307  sepIndex = ((std::max))(sepIndex, altsepIndex);
1308  }
1309 
1310  size_t dotIndex = pathname.rfind(extsep);
1311  if (dotIndex != std::string::npos) {
1312  // The extsep character exists
1313  if ((sepIndex != (int)std::string::npos && (int)dotIndex > sepIndex) || sepIndex == (int)std::string::npos) {
1314  if (sepIndex == (int)std::string::npos) {
1315  sepIndex = -1;
1316  }
1317  size_t filenameIndex = (size_t)(sepIndex + 1);
1318 
1319  while (filenameIndex < dotIndex) {
1320  if (pathname.compare(filenameIndex, 1, extsep) != 0) {
1321  return pathname.substr(dotIndex);
1322  }
1323  filenameIndex++;
1324  }
1325  }
1326  }
1327 
1328  return "";
1329 }
1330 
1336 std::string vpIoTools::getName(const std::string &pathname)
1337 {
1338  if (pathname.size() > 0) {
1339  std::string convertedPathname = vpIoTools::path(pathname);
1340 
1341  size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1342  if (index != std::string::npos) {
1343  return convertedPathname.substr(index + 1);
1344  }
1345 
1346  return convertedPathname;
1347  }
1348 
1349  return "";
1350 }
1351 
1358 std::string vpIoTools::getNameWE(const std::string &pathname)
1359 {
1360  std::string name = vpIoTools::getName(pathname);
1361  size_t found = name.find_last_of(".");
1362  std::string name_we = name.substr(0, found);
1363  return name_we;
1364 }
1365 
1371 std::string vpIoTools::getParent(const std::string &pathname)
1372 {
1373  if (pathname.size() > 0) {
1374  std::string convertedPathname = vpIoTools::path(pathname);
1375 
1376  size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1377  if (index != std::string::npos) {
1378  return convertedPathname.substr(0, index);
1379  }
1380  }
1381 
1382  return "";
1383 }
1384 
1393 std::string vpIoTools::getAbsolutePathname(const std::string &pathname)
1394 {
1395 
1396 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1397  std::string real_path_str = pathname;
1398  char *real_path = realpath(pathname.c_str(), NULL);
1399 
1400  if (real_path != NULL) {
1401  real_path_str = real_path;
1402  free(real_path);
1403  }
1404  return real_path_str;
1405 #elif defined(_WIN32)
1406 #if (!defined(WINRT))
1407  std::string real_path_str = pathname;
1408  DWORD retval = 0;
1409  TCHAR buffer[4096] = TEXT("");
1410 
1411  retval = GetFullPathName(pathname.c_str(), 4096, buffer, 0);
1412  if (retval != 0) {
1413  real_path_str = buffer;
1414  }
1415  return real_path_str;
1416 #else
1418  "Cannot get absolute path of %s: not implemented on "
1419  "Universal Windows Platform",
1420  pathname.c_str()));
1421 #endif
1422 #endif
1423 }
1424 
1435 std::string vpIoTools::createFilePath(const std::string &parent, const std::string &child)
1436 {
1437  if (child.size() == 0 && parent.size() == 0) {
1438  return "";
1439  }
1440 
1441  if (child.size() == 0) {
1442  return vpIoTools::path(parent);
1443  }
1444 
1445  if (parent.size() == 0) {
1446  return vpIoTools::path(child);
1447  }
1448 
1449  std::string convertedParent = vpIoTools::path(parent);
1450  std::string convertedChild = vpIoTools::path(child);
1451 
1452  std::stringstream ss;
1453  ss << vpIoTools::separator;
1454  std::string stringSeparator;
1455  ss >> stringSeparator;
1456 
1457  std::string lastConvertedParentChar = convertedParent.substr(convertedParent.size() - 1);
1458  std::string firstConvertedChildChar = convertedChild.substr(0, 1);
1459 
1460  if (lastConvertedParentChar == stringSeparator) {
1461  convertedParent = convertedParent.substr(0, convertedParent.size() - 1);
1462  }
1463 
1464  if (firstConvertedChildChar == stringSeparator) {
1465  convertedChild = convertedChild.substr(1);
1466  }
1467 
1468  return std::string(convertedParent + vpIoTools::separator + convertedChild);
1469 }
1470 
1476 bool vpIoTools::isAbsolutePathname(const std::string &pathname)
1477 {
1478  //# Inspired by the Python 2.7.8 module.
1479  //# Return whether a path is absolute.
1480  //# Trivial in Posix, harder on the Mac or MS-DOS.
1481  //# For DOS it is absolute if it starts with a slash or backslash (current
1482  //# volume), or if a pathname after the volume letter and colon / UNC
1483  // resource # starts with a slash or backslash.
1484  //
1485  // def isabs(s):
1486  // """Test whether a path is absolute"""
1487  // s = splitdrive(s)[1]
1488  // return s != '' and s[:1] in '/\\'
1489  std::string path = splitDrive(pathname).second;
1490  return path.size() > 0 && (path.substr(0, 1) == "/" || path.substr(0, 1) == "\\");
1491 }
1492 
1500 bool vpIoTools::isSamePathname(const std::string &pathname1, const std::string &pathname2)
1501 {
1502  // Normalize path
1503  std::string path1_normalize = vpIoTools::path(pathname1);
1504  std::string path2_normalize = vpIoTools::path(pathname2);
1505 
1506  // Get absolute path
1507  path1_normalize = vpIoTools::getAbsolutePathname(path1_normalize);
1508  path2_normalize = vpIoTools::getAbsolutePathname(path2_normalize);
1509 
1510  return (path1_normalize == path2_normalize);
1511 }
1512 
1520 std::pair<std::string, std::string> vpIoTools::splitDrive(const std::string &pathname)
1521 {
1522 //# Split a path in a drive specification (a drive letter followed by a
1523 //# colon) and the path specification.
1524 //# It is always true that drivespec + pathspec == p
1525 // def splitdrive(p):
1526 // """Split a pathname into drive/UNC sharepoint and relative path
1527 // specifiers. Returns a 2-tuple (drive_or_unc, path); either part may be
1528 // empty.
1529 //
1530 // If you assign
1531 // result = splitdrive(p)
1532 // It is always true that:
1533 // result[0] + result[1] == p
1534 //
1535 // If the path contained a drive letter, drive_or_unc will contain
1536 // everything up to and including the colon. e.g. splitdrive("c:/dir")
1537 // returns ("c:", "/dir")
1538 //
1539 // If the path contained a UNC path, the drive_or_unc will contain the host
1540 // name and share up to but not including the fourth directory separator
1541 // character. e.g. splitdrive("//host/computer/dir") returns
1542 // ("//host/computer", "/dir")
1543 //
1544 // Paths cannot contain both a drive letter and a UNC path.
1545 //
1546 // """
1547 // if len(p) > 1:
1548 // normp = p.replace(altsep, sep)
1549 // if (normp[0:2] == sep*2) and (normp[2] != sep):
1550 // # is a UNC path:
1551 // # vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1552 // # \\machine\mountpoint\directory\etc\...
1553 // # directory ^^^^^^^^^^^^^^^
1554 // index = normp.find(sep, 2)
1555 // if index == -1:
1556 // return '', p
1557 // index2 = normp.find(sep, index + 1)
1558 // # a UNC path can't have two slashes in a row
1559 // # (after the initial two)
1560 // if index2 == index + 1:
1561 // return '', p
1562 // if index2 == -1:
1563 // index2 = len(p)
1564 // return p[:index2], p[index2:]
1565 // if normp[1] == ':':
1566 // return p[:2], p[2:]
1567 // return '', p
1568 
1569 // On Unix, the drive is always empty.
1570 // On the Mac, the drive is always empty (don't use the volume name -- it
1571 // doesn't have the same syntactic and semantic oddities as DOS drive
1572 // letters, such as there being a separate current directory per drive).
1573 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
1574  return std::pair<std::string, std::string>("", pathname);
1575 #else
1576  const std::string sep = "\\";
1577  const std::string sepsep = "\\\\";
1578  const std::string altsep = "/";
1579 
1580  if (pathname.size() > 1) {
1581  std::string normPathname = pathname;
1582  std::replace(normPathname.begin(), normPathname.end(), *altsep.c_str(), *sep.c_str());
1583 
1584  if (normPathname.substr(0, 2) == sepsep && normPathname.substr(2, 1) != sep) {
1585  // is a UNC path:
1586  // vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1587  // \\machine\mountpoint\directory\etc\...
1588  // directory ^^^^^^^^^^^^^^^
1589  size_t index = normPathname.find(sep, 2);
1590  if (index == std::string::npos) {
1591  return std::pair<std::string, std::string>("", pathname);
1592  }
1593 
1594  size_t index2 = normPathname.find(sep, index + 1);
1595  //# a UNC path can't have two slashes in a row
1596  //# (after the initial two)
1597  if (index2 == index + 1) {
1598  return std::pair<std::string, std::string>("", pathname);
1599  }
1600 
1601  if (index2 == std::string::npos) {
1602  index2 = pathname.size();
1603  }
1604 
1605  return std::pair<std::string, std::string>(pathname.substr(0, index2), pathname.substr(index2));
1606  }
1607 
1608  if (normPathname[1] == ':') {
1609  return std::pair<std::string, std::string>(pathname.substr(0, 2), pathname.substr(2));
1610  }
1611  }
1612 
1613  return std::pair<std::string, std::string>("", pathname);
1614 #endif
1615 }
1616 
1665 std::vector<std::string> vpIoTools::splitChain(const std::string &chain, const std::string &sep)
1666 {
1667  size_t startIndex = 0;
1668 
1669  std::string chainToSplit = chain;
1670  std::vector<std::string> subChain;
1671  size_t sepIndex = chainToSplit.find(sep);
1672 
1673  while (sepIndex != std::string::npos) {
1674  std::string sub = chainToSplit.substr(startIndex, sepIndex);
1675  if (!sub.empty())
1676  subChain.push_back(sub);
1677  chainToSplit = chainToSplit.substr(sepIndex + 1, chain.size() - 1);
1678 
1679  sepIndex = chainToSplit.find(sep);
1680  }
1681  if (!chainToSplit.empty())
1682  subChain.push_back(chainToSplit);
1683 
1684  return subChain;
1685 }
1686 
1694 std::vector<std::string> vpIoTools::getDirFiles(const std::string &pathname)
1695 {
1696 
1697  if (!checkDirectory(pathname)) {
1698  throw(vpIoException(vpException::fatalError, "Directory %s doesn't exist'", pathname.c_str()));
1699  }
1700  std::string dirName = path(pathname);
1701 
1702 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1703 
1704  std::vector<std::string> files;
1705  struct dirent **list = NULL;
1706  int filesCount = scandir(dirName.c_str(), &list, NULL, NULL);
1707  if (filesCount == -1) {
1708  throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1709  }
1710  for (int i = 0; i < filesCount; i++) {
1711  std::string fileName = list[i]->d_name;
1712  if (fileName != "." && fileName != "..") {
1713  files.push_back(fileName);
1714  }
1715  free(list[i]);
1716  }
1717  free(list);
1718  std::sort(files.begin(), files.end());
1719  return files;
1720 
1721 #elif defined(_WIN32)
1722 #if (!defined(WINRT))
1723 
1724  std::vector<std::string> files;
1725  std::string fileMask = dirName;
1726  fileMask.append("\\*");
1727  WIN32_FIND_DATA FindFileData;
1728  HANDLE hFind = FindFirstFile(fileMask.c_str(), &FindFileData);
1729  // Directory is empty
1730  if (HandleToLong(&hFind) == ERROR_FILE_NOT_FOUND) {
1731  return files;
1732  }
1733  if (hFind == INVALID_HANDLE_VALUE) {
1734  throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1735  }
1736  do {
1737  std::string fileName = FindFileData.cFileName;
1738  if (fileName != "." && fileName != "..") {
1739  files.push_back(fileName);
1740  }
1741  } while (FindNextFile(hFind, &FindFileData));
1742  FindClose(hFind);
1743  std::sort(files.begin(), files.end());
1744  return files;
1745 
1746 #else
1748  "Cannot read files of directory %s: not implemented on "
1749  "Universal Windows Platform",
1750  dirName.c_str()));
1751 #endif
1752 #endif
1753 }
static bool remove(const char *filename)
Definition: vpIoTools.cpp:735
static bool checkDirectory(const char *dirname)
Definition: vpIoTools.cpp:367
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1210
static bool isAbsolutePathname(const std::string &pathname)
Definition: vpIoTools.cpp:1476
static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
Definition: vpIoTools.cpp:324
static std::string getFileExtension(const std::string &pathname, const bool checkFile=false)
Definition: vpIoTools.cpp:1257
#define vpERROR_TRACE
Definition: vpDebug.h:393
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
Definition: vpArray2D.h:171
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
static const char separator
Definition: vpIoTools.h:186
static std::string getenv(const char *env)
Definition: vpIoTools.cpp:262
static bool rename(const char *oldfilename, const char *newfilename)
Definition: vpIoTools.cpp:803
static std::string path(const char *pathname)
Definition: vpIoTools.cpp:839
unsigned int getRows() const
Definition: vpArray2D.h:156
Error that can be emited by the vpIoTools class and its derivates.
Definition: vpIoException.h:72
static std::vector< std::string > getDirFiles(const std::string &dirname)
Definition: vpIoTools.cpp:1694
static std::string getParent(const std::string &pathname)
Definition: vpIoTools.cpp:1371
static void createBaseNamePath(const bool &empty=false)
Definition: vpIoTools.cpp:1168
static const std::string & getBuildInformation()
Definition: vpIoTools.cpp:101
static std::string baseDir
Definition: vpIoTools.h:236
unsigned int getCols() const
Definition: vpArray2D.h:146
static void makeDirectory(const char *dirname)
Definition: vpIoTools.cpp:495
static bool checkFilename(const char *filename)
Definition: vpIoTools.cpp:573
static void setBaseName(const std::string &s)
Definition: vpIoTools.cpp:114
static std::string createFilePath(const std::string &parent, const std::string &child)
Definition: vpIoTools.cpp:1435
static int mkdir_p(const char *path, const int mode)
Definition: vpIoTools.cpp:432
static bool copy(const char *src, const char *dst)
Definition: vpIoTools.cpp:634
static std::pair< std::string, std::string > splitDrive(const std::string &pathname)
Definition: vpIoTools.cpp:1520
static bool isSamePathname(const std::string &pathname1, const std::string &pathname2)
Definition: vpIoTools.cpp:1500
static std::string getUserName()
Definition: vpIoTools.cpp:198
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
Definition: vpIoTools.cpp:1665
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:145
static void saveConfigFile(const bool &actuallySave=true)
Definition: vpIoTools.cpp:1187
static std::vector< std::string > configVars
Definition: vpIoTools.h:238
static std::string getName(const std::string &pathname)
Definition: vpIoTools.cpp:1336
static std::string baseName
Definition: vpIoTools.h:235
static std::string getFullName()
Definition: vpIoTools.cpp:132
static std::string configFile
Definition: vpIoTools.h:237
static void setBaseDir(const std::string &dir)
Definition: vpIoTools.cpp:120
static std::string getNameWE(const std::string &pathname)
Definition: vpIoTools.cpp:1358
static std::string getBaseName()
Definition: vpIoTools.cpp:126
#define vpDEBUG_TRACE
Definition: vpDebug.h:487
static std::string getAbsolutePathname(const std::string &pathname)
Definition: vpIoTools.cpp:1393
static vpColor getColor(const unsigned int &i)
Definition: vpColor.h:249
static bool readConfigVar(const std::string &var, float &value)
Definition: vpIoTools.cpp:936
static std::vector< std::string > configValues
Definition: vpIoTools.h:239
static bool loadConfigFile(const std::string &confFile)
Definition: vpIoTools.cpp:889
static void addNameElement(const std::string &strTrue, const bool &cond=true, const std::string &strFalse="")
Definition: vpIoTools.cpp:1133