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 # ifdef _MAX_PATH
74 # define PATH_MAX _MAX_PATH
75 # else
76 # define PATH_MAX 1024
77 # endif
78 #endif
79 
80 std::string vpIoTools::baseName = "";
81 std::string vpIoTools::baseDir = "";
82 std::string vpIoTools::configFile = "";
83 std::vector<std::string> vpIoTools::configVars = std::vector<std::string>();
84 std::vector<std::string> vpIoTools::configValues = std::vector<std::string>();
85 
86 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
87  // wordexp() is not available
88 namespace
89 {
90 void replaceAll(std::string &str, const std::string &search, const std::string &replace)
91 {
92  size_t start_pos = 0;
93  while ((start_pos = str.find(search, start_pos)) != std::string::npos) {
94  str.replace(start_pos, search.length(), replace);
95  start_pos += replace.length(); // Handles case where 'replace' is a
96  // substring of 'search'
97  }
98 }
99 }
100 #endif
101 
105 const std::string &vpIoTools::getBuildInformation()
106 {
107  static std::string build_info =
108 #include "version_string.inc"
109  ;
110  return build_info;
111 }
112 
118 void vpIoTools::setBaseName(const std::string &s) { baseName = s; }
124 void vpIoTools::setBaseDir(const std::string &dir) { baseDir = dir + "/"; }
130 std::string vpIoTools::getBaseName() { return baseName; }
136 std::string vpIoTools::getFullName() { return baseDir + baseName; }
137 
155 void vpIoTools::getUserName(std::string &username)
156 {
157 // With MinGW, UNIX and _WIN32 are defined
158 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
159  // Get the user name.
160  char *_username = NULL;
161  _username = ::getenv("LOGNAME");
162  if (_username == NULL) {
163  vpERROR_TRACE("Cannot get the username. Check your LOGNAME environment variable");
164  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username"));
165  }
166  username = _username;
167 #elif defined(_WIN32)
168 #if (!defined(WINRT))
169  unsigned int info_buffer_size = 1024;
170  TCHAR *infoBuf = new TCHAR[info_buffer_size];
171  DWORD bufCharCount = (DWORD)info_buffer_size;
172  // Get the user name.
173  if (!GetUserName(infoBuf, &bufCharCount)) {
174  delete[] infoBuf;
175  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username"));
176  }
177  username = infoBuf;
178  delete[] infoBuf;
179 #else
180  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username: not implemented on Universal "
181  "Windows Platform"));
182 #endif
183 #endif
184 }
203 {
204  std::string username;
205 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
206  // Get the user name.
207  char *_username = NULL;
208  _username = ::getenv("LOGNAME");
209  if (_username == NULL) {
210  vpERROR_TRACE("Cannot get the username. Check your LOGNAME environment variable");
211  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username"));
212  }
213  username = _username;
214 #elif defined(_WIN32)
215 #if (!defined(WINRT))
216  unsigned int info_buffer_size = 1024;
217  TCHAR *infoBuf = new TCHAR[info_buffer_size];
218  DWORD bufCharCount = (DWORD)info_buffer_size;
219  // Get the user name.
220  if (!GetUserName(infoBuf, &bufCharCount)) {
221  delete[] infoBuf;
222  vpERROR_TRACE("Cannot get the username");
223  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username"));
224  }
225  username = infoBuf;
226  delete[] infoBuf;
227 #else
228  throw(vpIoException(vpIoException::cantGetUserName, "Cannot get the username: not implemented on Universal "
229  "Windows Platform"));
230 #endif
231 #endif
232  return username;
233 }
234 
266 std::string vpIoTools::getenv(const char *env)
267 {
268 #if defined(_WIN32) && defined(WINRT)
269  throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value: not "
270  "implemented on Universal Windows Platform"));
271 #else
272  std::string value;
273  // Get the environment variable value.
274  char *_value = NULL;
275  _value = ::getenv(env);
276  if (_value == NULL) {
277  throw(vpIoException(vpIoException::cantGetenv, "Cannot get the environment variable value"));
278  }
279  value = _value;
280 
281  return value;
282 #endif
283 }
284 
317 std::string vpIoTools::getenv(const std::string &env) { return (vpIoTools::getenv(env.c_str())); }
318 
328 void vpIoTools::getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
329 {
330  if (version.size() == 0) {
331  major = 0;
332  minor = 0;
333  patch = 0;
334  } else {
335  size_t major_pos = version.find('.');
336  std::string major_str = version.substr(0, major_pos);
337  major = (unsigned)atoi(major_str.c_str());
338 
339  if (major_pos != std::string::npos) {
340  size_t minor_pos = version.find('.', major_pos + 1);
341  std::string minor_str = version.substr(major_pos + 1, (minor_pos - (major_pos + 1)));
342  minor = (unsigned)atoi(minor_str.c_str());
343 
344  if (minor_pos != std::string::npos) {
345  std::string patch_str = version.substr(minor_pos + 1);
346  patch = (unsigned)atoi(patch_str.c_str());
347  } else {
348  patch = 0;
349  }
350  } else {
351  minor = 0;
352  patch = 0;
353  }
354  }
355 }
356 
371 bool vpIoTools::checkDirectory(const char *dirname)
372 {
373 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
374  struct stat stbuf;
375 #elif defined(_WIN32) && defined(__MINGW32__)
376  struct stat stbuf;
377 #elif defined(_WIN32)
378  struct _stat stbuf;
379 #endif
380 
381  if (dirname == NULL || dirname[0] == '\0') {
382  return false;
383  }
384 
385  std::string _dirname = path(dirname);
386 
387 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
388  if (stat(_dirname.c_str(), &stbuf) != 0)
389 #elif defined(_WIN32) && defined(__MINGW32__)
390  // Remove trailing separator character if any
391  // AppVeyor: Windows 6.3.9600 AMD64 ; C:/MinGW/bin/g++.exe (ver 5.3.0) ;
392  // GNU Make 3.82.90 Built for i686-pc-mingw32
393  if (!_dirname.empty() && _dirname.at(_dirname.size() - 1) == vpIoTools::separator)
394  _dirname = _dirname.substr(0, _dirname.size() - 1);
395  if (stat(_dirname.c_str(), &stbuf) != 0)
396 #elif defined(_WIN32)
397  if (_stat(_dirname.c_str(), &stbuf) != 0)
398 #endif
399  {
400  return false;
401  }
402 #if defined(_WIN32) || (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
403  if ((stbuf.st_mode & S_IFDIR) == 0)
404 #endif
405  {
406  return false;
407  }
408 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
409  if ((stbuf.st_mode & S_IWUSR) == 0)
410 #elif defined(_WIN32)
411  if ((stbuf.st_mode & S_IWRITE) == 0)
412 #endif
413  {
414  return false;
415  }
416  return true;
417 }
418 
432 bool vpIoTools::checkDirectory(const std::string &dirname) { return vpIoTools::checkDirectory(dirname.c_str()); }
433 
434 // See:
435 // https://gist.github.com/JonathonReinhart/8c0d90191c38af2dcadb102c4e202950
436 int vpIoTools::mkdir_p(const char *path, const int mode)
437 {
438  /* Adapted from http://stackoverflow.com/a/2336245/119527 */
439  const size_t len = strlen(path);
440  char _path[PATH_MAX];
441  char *p = NULL;
442  const char sep = vpIoTools::separator;
443 
444  errno = 0;
445  if (len > sizeof(_path) - 1) {
446  errno = ENAMETOOLONG;
447  return -1;
448  }
449  /* Copy string so its mutable */
450  strcpy(_path, path);
451 
452  /* Iterate over the string */
453  for (p = _path + 1; *p; p++) { // path cannot be empty
454  if (*p == sep) {
455  /* Temporarily truncate */
456  *p = '\0';
457 
458 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
459  if (mkdir(_path, (mode_t)mode) != 0)
460 #elif defined(_WIN32)
461  (void)mode; // var not used
462  if (!checkDirectory(_path) && _mkdir(_path) != 0)
463 #endif
464  {
465  if (errno != EEXIST)
466  return -1;
467  }
468  *p = sep;
469  }
470  }
471 
472 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
473  if (mkdir(_path, (mode_t)mode) != 0)
474 #elif defined(_WIN32)
475  if (_mkdir(_path) != 0)
476 #endif
477  {
478  if (errno != EEXIST)
479  return -1;
480  }
481 
482  return 0;
483 }
484 
499 void vpIoTools::makeDirectory(const char *dirname)
500 {
501 #if ((!defined(__unix__) && !defined(__unix) && (!defined(__APPLE__) || !defined(__MACH__)))) && !defined(_WIN32)
502  std::cerr << "Unsupported platform for vpIoTools::makeDirectory()!" << std::endl;
503  return;
504 #endif
505 
506 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
507  struct stat stbuf;
508 #elif defined(_WIN32) && defined(__MINGW32__)
509  struct stat stbuf;
510 #elif defined(_WIN32)
511  struct _stat stbuf;
512 #endif
513 
514  if (dirname == NULL || dirname[0] == '\0') {
515  vpERROR_TRACE("invalid directory name\n");
516  throw(vpIoException(vpIoException::invalidDirectoryName, "invalid directory name"));
517  }
518 
519  std::string _dirname = path(dirname);
520 
521 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
522  if (stat(_dirname.c_str(), &stbuf) != 0)
523 #elif defined(_WIN32) && defined(__MINGW32__)
524  if (stat(_dirname.c_str(), &stbuf) != 0)
525 #elif defined(_WIN32)
526  if (_stat(_dirname.c_str(), &stbuf) != 0)
527 #endif
528  {
529  if (vpIoTools::mkdir_p(_dirname.c_str(), 0755) != 0) {
530  vpERROR_TRACE("unable to create directory '%s'\n", dirname);
531  throw(vpIoException(vpIoException::cantCreateDirectory, "unable to create directory"));
532  }
533 
534  vpDEBUG_TRACE(2, "has created directory '%s'\n", dirname);
535  }
536 
537  if (checkDirectory(dirname) == false) {
538  vpERROR_TRACE("unable to create directory '%s'\n", dirname);
539  throw(vpIoException(vpIoException::cantCreateDirectory, "unable to create directory"));
540  }
541 }
542 
555 void vpIoTools::makeDirectory(const std::string &dirname)
556 {
557  try {
558  vpIoTools::makeDirectory(dirname.c_str());
559  } catch (...) {
560  vpERROR_TRACE("unable to create directory '%s'\n", dirname.c_str());
561  throw(vpIoException(vpIoException::cantCreateDirectory, "unable to create directory"));
562  }
563 }
564 
577 bool vpIoTools::checkFilename(const char *filename)
578 {
579 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
580  struct stat stbuf;
581 #elif defined(_WIN32)
582  struct _stat stbuf;
583 #endif
584 
585  if (filename == NULL || filename[0] == '\0') {
586  return false;
587  }
588 
589  std::string _filename = path(filename);
590 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
591  if (stat(_filename.c_str(), &stbuf) != 0)
592 #elif defined(_WIN32)
593  if (_stat(_filename.c_str(), &stbuf) != 0)
594 #endif
595  {
596  return false;
597  }
598  if ((stbuf.st_mode & S_IFREG) == 0) {
599  return false;
600  }
601 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
602  if ((stbuf.st_mode & S_IRUSR) == 0)
603 #elif defined(_WIN32)
604  if ((stbuf.st_mode & S_IREAD) == 0)
605 #endif
606  {
607  return false;
608  }
609  return true;
610 }
611 
624 bool vpIoTools::checkFilename(const std::string &filename) { return vpIoTools::checkFilename(filename.c_str()); }
625 
638 bool vpIoTools::copy(const char *src, const char *dst)
639 {
640  // Check if we have to consider a file or a directory
641  if (vpIoTools::checkFilename(src)) {
642 // std::cout << "copy file: " << src << " in " << dst << std::endl;
643 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
644 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
645  // wordexp() is not available
646  char cmd[FILENAME_MAX];
647  int ret;
648  sprintf(cmd, "cp -p %s %s", src, dst);
649  ret = system(cmd);
650  if (ret) {
651  }; // to avoid a warning
652  // std::cout << cmd << " return value: " << ret << std::endl;
653  return true;
654 #else
655  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src, dst));
656 #endif
657 #elif defined(_WIN32)
658 #if (!defined(WINRT))
659  char cmd[FILENAME_MAX];
660  int ret;
661  std::string src_ = vpIoTools::path(src);
662  std::string dst_ = vpIoTools::path(dst);
663  sprintf(cmd, "copy %s %s", src_.c_str(), dst_.c_str());
664  ret = system(cmd);
665  if (ret) {
666  }; // to avoid a warning
667  // std::cout << cmd << " return value: " << ret << std::endl;
668  return true;
669 #else
670  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
671  src, dst));
672 #endif
673 #endif
674  } else if (vpIoTools::checkDirectory(src)) {
675 // std::cout << "copy directory: " << src << " in " << dst << std::endl;
676 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
677 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
678  // wordexp() is not available
679  char cmd[FILENAME_MAX];
680  int ret;
681  sprintf(cmd, "cp -p -r %s %s", src, dst);
682  ret = system(cmd);
683  if (ret) {
684  }; // to avoid a warning
685  // std::cout << cmd << " return value: " << ret << std::endl;
686  return true;
687 #else
688  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on iOS Platform", src, dst));
689 #endif
690 #elif defined(_WIN32)
691 #if (!defined(WINRT))
692  char cmd[FILENAME_MAX];
693  int ret;
694  std::string src_ = vpIoTools::path(src);
695  std::string dst_ = vpIoTools::path(dst);
696  sprintf(cmd, "copy %s %s", src_.c_str(), dst_.c_str());
697  ret = system(cmd);
698  if (ret) {
699  }; // to avoid a warning
700  // std::cout << cmd << " return value: " << ret << std::endl;
701  return true;
702 #else
703  throw(vpIoException(vpException::fatalError, "Cannot copy %s in %s: not implemented on Universal Windows Platform",
704  src, dst));
705 #endif
706 #endif
707  } else {
708  std::cout << "Cannot copy: " << src << " in " << dst << std::endl;
709  return false;
710  }
711 }
724 bool vpIoTools::copy(const std::string &src, const std::string &dst)
725 {
726  return vpIoTools::copy(src.c_str(), dst.c_str());
727 }
728 
739 bool vpIoTools::remove(const char *file_or_dir)
740 {
741  // Check if we have to consider a file or a directory
742  if (vpIoTools::checkFilename(file_or_dir)) {
743  // std::cout << "remove file: " << file_or_dir << std::endl;
744  if (::remove(file_or_dir) != 0)
745  return false;
746  else
747  return true;
748  } else if (vpIoTools::checkDirectory(file_or_dir)) {
749 // std::cout << "remove directory: " << file_or_dir << std::endl;
750 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
751 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
752  // wordexp() is not available
753  char cmd[FILENAME_MAX];
754  sprintf(cmd, "rm -rf %s", file_or_dir);
755  int ret = system(cmd);
756  if (ret) {
757  }; // to avoid a warning
758  // std::cout << cmd << " return value: " << ret << std::endl;
759  return true;
760 #else
761  throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on iOS Platform", file_or_dir));
762 #endif
763 #elif defined(_WIN32)
764 #if (!defined(WINRT))
765  char cmd[FILENAME_MAX];
766  std::string file_or_dir_ = vpIoTools::path(file_or_dir);
767  sprintf(cmd, "rmdir /S /Q %s", file_or_dir_.c_str());
768  int ret = system(cmd);
769  if (ret) {
770  }; // to avoid a warning
771  // std::cout << cmd << " return value: " << ret << std::endl;
772  return true;
773 #else
774  throw(vpIoException(vpException::fatalError, "Cannot remove %s: not implemented on Universal Windows Platform",
775  file_or_dir));
776 #endif
777 #endif
778  } else {
779  std::cout << "Cannot remove: " << file_or_dir << std::endl;
780  return false;
781  }
782 }
794 bool vpIoTools::remove(const std::string &file_or_dir) { return vpIoTools::remove(file_or_dir.c_str()); }
795 
807 bool vpIoTools::rename(const char *oldfilename, const char *newfilename)
808 {
809  if (::rename(oldfilename, newfilename) != 0)
810  return false;
811  else
812  return true;
813 }
814 
826 bool vpIoTools::rename(const std::string &oldfilename, const std::string &newfilename)
827 {
828  return vpIoTools::rename(oldfilename.c_str(), newfilename.c_str());
829 }
830 
843 std::string vpIoTools::path(const char *pathname)
844 {
845  std::string path(pathname);
846 
847 #if defined(_WIN32)
848  for (unsigned int i = 0; i < path.length(); i++)
849  if (path[i] == '/')
850  path[i] = '\\';
851 #elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
852  for (unsigned int i = 0; i < path.length(); i++)
853  if (path[i] == '\\')
854  path[i] = '/';
855 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
856  // wordexp() is not available
857  wordexp_t exp_result;
858 
859  // escape quote character
860  replaceAll(path, "'", "'\\''");
861  // add quotes to handle special characters like parentheses and spaces
862  wordexp(std::string("'" + path + "'").c_str(), &exp_result, 0);
863  path = exp_result.we_wordc == 1 ? exp_result.we_wordv[0] : "";
864  wordfree(&exp_result);
865 #endif
866 #endif
867 
868  return path;
869 }
870 
883 std::string vpIoTools::path(const std::string &pathname) { return path(pathname.c_str()); }
884 
893 bool vpIoTools::loadConfigFile(const std::string &confFile)
894 {
895  configFile = path(confFile);
896  configVars.clear();
897  configValues.clear();
898  std::ifstream confContent(configFile.c_str(), std::ios::in);
899 
900  if (confContent.is_open()) {
901  std::string line, var, val;
902  long unsigned int k;
903  int c;
904  std::string stop[3] = {" ", "\t", "#"};
905  while (std::getline(confContent, line)) {
906  if ((line.compare(0, 1, "#") != 0) && (line.size() > 2)) {
907  try {
908  // name of the variable
909  k = (unsigned long)line.find(" ");
910  var = line.substr(0, k);
911  // look for the end of the actual value
912  c = 200;
913  for (unsigned i = 0; i < 3; ++i)
914  c = vpMath::minimum(c, (int)line.find(stop[i], k + 1));
915  if (c == -1)
916  c = (int)line.size();
917  long unsigned int c_ = (long unsigned int)c;
918  val = line.substr(k + 1, c_ - k - 1);
919  configVars.push_back(var);
920  configValues.push_back(val);
921  } catch (...) {
922  }
923  }
924  }
925  confContent.close();
926  } else {
927  return false;
928  }
929  return true;
930 }
931 
940 bool vpIoTools::readConfigVar(const std::string &var, float &value)
941 {
942  bool found = false;
943  for (unsigned int k = 0; k < configVars.size() && found == false; ++k) {
944  if (configVars[k] == var) {
945  if (configValues[k].compare("PI") == 0)
946  value = (float)M_PI;
947  else if (configValues[k].compare("PI/2") == 0)
948  value = (float)(M_PI / 2.0);
949  else if (configValues[k].compare("-PI/2") == 0)
950  value = (float)(-M_PI / 2.0);
951  else
952  value = (float)atof(configValues[k].c_str());
953  found = true;
954  }
955  }
956  if (found == false)
957  std::cout << var << " not found in config file" << std::endl;
958  return found;
959 }
968 bool vpIoTools::readConfigVar(const std::string &var, double &value)
969 {
970  bool found = false;
971  for (unsigned int k = 0; k < configVars.size() && found == false; ++k) {
972  if (configVars[k] == var) {
973  if (configValues[k].compare("PI") == 0)
974  value = M_PI;
975  else if (configValues[k].compare("PI/2") == 0)
976  value = M_PI / 2;
977  else if (configValues[k].compare("-PI/2") == 0)
978  value = -M_PI / 2;
979  else
980  value = atof(configValues[k].c_str());
981  found = true;
982  }
983  }
984  if (found == false)
985  std::cout << var << " not found in config file" << std::endl;
986  return found;
987 }
988 
997 bool vpIoTools::readConfigVar(const std::string &var, int &value)
998 {
999  bool found = false;
1000  for (unsigned int k = 0; k < configVars.size() && found == false; ++k) {
1001  if (configVars[k] == var) {
1002  value = atoi(configValues[k].c_str());
1003  found = true;
1004  }
1005  }
1006  if (found == false)
1007  std::cout << var << " not found in config file" << std::endl;
1008  return found;
1009 }
1010 
1019 bool vpIoTools::readConfigVar(const std::string &var, unsigned int &value)
1020 {
1021  int v = 0;
1022  bool found = readConfigVar(var, v);
1023  value = (unsigned int)v;
1024  return found;
1025 }
1026 
1035 bool vpIoTools::readConfigVar(const std::string &var, bool &value)
1036 {
1037  int v = 0;
1038  bool found = readConfigVar(var, v);
1039  value = (v != 0);
1040  return found;
1041 }
1042 
1051 bool vpIoTools::readConfigVar(const std::string &var, vpColor &value)
1052 {
1053  unsigned int v = 0;
1054  bool found = readConfigVar(var, v);
1055  value = vpColor::getColor(v);
1056  return found;
1057 }
1058 
1067 bool vpIoTools::readConfigVar(const std::string &var, std::string &value)
1068 {
1069  bool found = false;
1070  for (unsigned int k = 0; k < configVars.size() && found == false; ++k) {
1071  if (configVars[k] == var) {
1072  value = configValues[k];
1073  found = true;
1074  }
1075  }
1076  if (found == false)
1077  std::cout << var << " not found in config file" << std::endl;
1078  return found;
1079 }
1080 
1094 bool vpIoTools::readConfigVar(const std::string &var, vpArray2D<double> &value, const unsigned int &nCols,
1095  const unsigned int &nRows)
1096 {
1097  bool found = false;
1098  std::string nb;
1099  for (unsigned int k = 0; k < configVars.size() && found == false; ++k) {
1100  if (configVars[k] == var) {
1101  found = true;
1102  // resize or not
1103  if (nCols != 0 && nRows != 0)
1104  value.resize(nRows, nCols);
1105  size_t ind = 0, ind2;
1106  for (unsigned int i = 0; i < value.getRows(); ++i)
1107  for (unsigned int j = 0; j < value.getCols(); ++j) {
1108  ind2 = configValues[k].find(",", ind);
1109  nb = configValues[k].substr(ind, ind2 - ind);
1110  if (nb.compare("PI") == 0)
1111  value[i][j] = M_PI;
1112  else if (nb.compare("PI/2") == 0)
1113  value[i][j] = M_PI / 2;
1114  else if (nb.compare("-PI/2") == 0)
1115  value[i][j] = -M_PI / 2;
1116  else
1117  value[i][j] = atof(nb.c_str());
1118  ind = ind2 + 1;
1119  }
1120  }
1121  }
1122  if (found == false)
1123  std::cout << var << " not found in config file" << std::endl;
1124  return found;
1125 }
1126 
1127 // construct experiment filename & path
1128 
1137 void vpIoTools::addNameElement(const std::string &strTrue, const bool &cond, const std::string &strFalse)
1138 {
1139  if (cond)
1140  baseName += "_" + strTrue;
1141  else if (strFalse != "")
1142  baseName += "_" + strFalse;
1143 }
1144 
1153 void vpIoTools::addNameElement(const std::string &strTrue, const double &val)
1154 {
1155  // if(val != 0.)
1156  if (std::fabs(val) < std::numeric_limits<double>::epsilon()) {
1157  char valC[256];
1158  sprintf(valC, "%.3f", val);
1159  std::string valS(valC);
1160  baseName += "_" + strTrue + valS;
1161  }
1162 }
1163 
1172 void vpIoTools::createBaseNamePath(const bool &empty)
1173 {
1174  if (vpIoTools::checkDirectory(baseDir + baseName) == false) {
1176  std::cout << "creating directory " + baseDir + baseName << std::endl;
1177  } else {
1178  if (empty) {
1179  std::cout << "emptying directory " + baseDir + baseName << std::endl;
1181  }
1182  }
1183 }
1184 
1191 void vpIoTools::saveConfigFile(const bool &actuallySave)
1192 {
1193  if (actuallySave) {
1194  std::string dest = baseDir + "/" + baseName + "_config.txt";
1195  // file copy
1196  vpIoTools::copy(configFile, dest);
1197  }
1198 }
1199 
1215 {
1216  std::string data_path;
1217  std::string file_to_test("mbt/cube.cao");
1218  std::string filename;
1219 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1220  // Test if visp-images-data package is u-installed (Ubuntu and Debian)
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  data_path = "/usr/share/visp-images-data/visp-images";
1226  filename = data_path + "/" + file_to_test;
1227  if (vpIoTools::checkFilename(filename))
1228  return data_path;
1229 #endif
1230  // Test if VISP_INPUT_IMAGE_PATH env var is set
1231  try {
1232  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH");
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  data_path = vpIoTools::getenv("VISP_INPUT_IMAGE_PATH") + "/visp-images";
1241  filename = data_path + "/" + file_to_test;
1242  if (vpIoTools::checkFilename(filename))
1243  return data_path;
1244  } catch (...) {
1245  }
1246  data_path = "";
1247  return data_path;
1248 }
1249 
1261 std::string vpIoTools::getFileExtension(const std::string &pathname, const bool checkFile)
1262 {
1263  if (checkFile && (vpIoTools::checkDirectory(pathname) || !vpIoTools::checkFilename(pathname))) {
1264  return "";
1265  }
1266 
1267 #if defined(_WIN32)
1268  std::string sep = "\\";
1269  std::string altsep = "/";
1270  std::string extsep = ".";
1271 #else
1272  // On Unix, or on the Mac
1273  std::string sep = "/";
1274  std::string altsep = "";
1275  std::string extsep = ".";
1276 #endif
1277 
1278  // Python 2.7.8 module.
1279  //# Split a path in root and extension.
1280  //# The extension is everything starting at the last dot in the last
1281  //# pathname component; the root is everything before that.
1282  //# It is always true that root + ext == p.
1283  //
1284  //# Generic implementation of splitext, to be parametrized with
1285  //# the separators
1286  // def _splitext(p, sep, altsep, extsep):
1287  // """Split the extension from a pathname.
1288  //
1289  // Extension is everything from the last dot to the end, ignoring
1290  // leading dots. Returns "(root, ext)"; ext may be empty."""
1291  //
1292  // sepIndex = p.rfind(sep)
1293  // if altsep:
1294  // altsepIndex = p.rfind(altsep)
1295  // sepIndex = max(sepIndex, altsepIndex)
1296  //
1297  // dotIndex = p.rfind(extsep)
1298  // if dotIndex > sepIndex:
1299  // # skip all leading dots
1300  // filenameIndex = sepIndex + 1
1301  // while filenameIndex < dotIndex:
1302  // if p[filenameIndex] != extsep:
1303  // return p[:dotIndex], p[dotIndex:]
1304  // filenameIndex += 1
1305  //
1306  // return p, ''
1307 
1308  int sepIndex = (int)pathname.rfind(sep);
1309  if (!altsep.empty()) {
1310  int altsepIndex = (int)pathname.rfind(altsep);
1311  sepIndex = ((std::max))(sepIndex, altsepIndex);
1312  }
1313 
1314  size_t dotIndex = pathname.rfind(extsep);
1315  if (dotIndex != std::string::npos) {
1316  // The extsep character exists
1317  if ((sepIndex != (int)std::string::npos && (int)dotIndex > sepIndex) || sepIndex == (int)std::string::npos) {
1318  if (sepIndex == (int)std::string::npos) {
1319  sepIndex = -1;
1320  }
1321  size_t filenameIndex = (size_t)(sepIndex + 1);
1322 
1323  while (filenameIndex < dotIndex) {
1324  if (pathname.compare(filenameIndex, 1, extsep) != 0) {
1325  return pathname.substr(dotIndex);
1326  }
1327  filenameIndex++;
1328  }
1329  }
1330  }
1331 
1332  return "";
1333 }
1334 
1340 std::string vpIoTools::getName(const std::string &pathname)
1341 {
1342  if (pathname.size() > 0) {
1343  std::string convertedPathname = vpIoTools::path(pathname);
1344 
1345  size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1346  if (index != std::string::npos) {
1347  return convertedPathname.substr(index + 1);
1348  }
1349 
1350  return convertedPathname;
1351  }
1352 
1353  return "";
1354 }
1355 
1362 std::string vpIoTools::getNameWE(const std::string &pathname)
1363 {
1364  std::string name = vpIoTools::getName(pathname);
1365  size_t found = name.find_last_of(".");
1366  std::string name_we = name.substr(0, found);
1367  return name_we;
1368 }
1369 
1375 std::string vpIoTools::getParent(const std::string &pathname)
1376 {
1377  if (pathname.size() > 0) {
1378  std::string convertedPathname = vpIoTools::path(pathname);
1379 
1380  size_t index = convertedPathname.find_last_of(vpIoTools::separator);
1381  if (index != std::string::npos) {
1382  return convertedPathname.substr(0, index);
1383  }
1384  }
1385 
1386  return "";
1387 }
1388 
1397 std::string vpIoTools::getAbsolutePathname(const std::string &pathname)
1398 {
1399 
1400 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1401  std::string real_path_str = pathname;
1402  char *real_path = realpath(pathname.c_str(), NULL);
1403 
1404  if (real_path != NULL) {
1405  real_path_str = real_path;
1406  free(real_path);
1407  }
1408  return real_path_str;
1409 #elif defined(_WIN32)
1410 #if (!defined(WINRT))
1411  std::string real_path_str = pathname;
1412  DWORD retval = 0;
1413  TCHAR buffer[4096] = TEXT("");
1414 
1415  retval = GetFullPathName(pathname.c_str(), 4096, buffer, 0);
1416  if (retval != 0) {
1417  real_path_str = buffer;
1418  }
1419  return real_path_str;
1420 #else
1422  "Cannot get absolute path of %s: not implemented on "
1423  "Universal Windows Platform",
1424  pathname.c_str()));
1425 #endif
1426 #endif
1427 }
1428 
1439 std::string vpIoTools::createFilePath(const std::string &parent, const std::string &child)
1440 {
1441  if (child.size() == 0 && parent.size() == 0) {
1442  return "";
1443  }
1444 
1445  if (child.size() == 0) {
1446  return vpIoTools::path(parent);
1447  }
1448 
1449  if (parent.size() == 0) {
1450  return vpIoTools::path(child);
1451  }
1452 
1453  std::string convertedParent = vpIoTools::path(parent);
1454  std::string convertedChild = vpIoTools::path(child);
1455 
1456  std::stringstream ss;
1457  ss << vpIoTools::separator;
1458  std::string stringSeparator;
1459  ss >> stringSeparator;
1460 
1461  std::string lastConvertedParentChar = convertedParent.substr(convertedParent.size() - 1);
1462  std::string firstConvertedChildChar = convertedChild.substr(0, 1);
1463 
1464  if (lastConvertedParentChar == stringSeparator) {
1465  convertedParent = convertedParent.substr(0, convertedParent.size() - 1);
1466  }
1467 
1468  if (firstConvertedChildChar == stringSeparator) {
1469  convertedChild = convertedChild.substr(1);
1470  }
1471 
1472  return std::string(convertedParent + vpIoTools::separator + convertedChild);
1473 }
1474 
1480 bool vpIoTools::isAbsolutePathname(const std::string &pathname)
1481 {
1482  //# Inspired by the Python 2.7.8 module.
1483  //# Return whether a path is absolute.
1484  //# Trivial in Posix, harder on the Mac or MS-DOS.
1485  //# For DOS it is absolute if it starts with a slash or backslash (current
1486  //# volume), or if a pathname after the volume letter and colon / UNC
1487  // resource # starts with a slash or backslash.
1488  //
1489  // def isabs(s):
1490  // """Test whether a path is absolute"""
1491  // s = splitdrive(s)[1]
1492  // return s != '' and s[:1] in '/\\'
1493  std::string path = splitDrive(pathname).second;
1494  return path.size() > 0 && (path.substr(0, 1) == "/" || path.substr(0, 1) == "\\");
1495 }
1496 
1504 bool vpIoTools::isSamePathname(const std::string &pathname1, const std::string &pathname2)
1505 {
1506  // Normalize path
1507  std::string path1_normalize = vpIoTools::path(pathname1);
1508  std::string path2_normalize = vpIoTools::path(pathname2);
1509 
1510  // Get absolute path
1511  path1_normalize = vpIoTools::getAbsolutePathname(path1_normalize);
1512  path2_normalize = vpIoTools::getAbsolutePathname(path2_normalize);
1513 
1514  return (path1_normalize == path2_normalize);
1515 }
1516 
1524 std::pair<std::string, std::string> vpIoTools::splitDrive(const std::string &pathname)
1525 {
1526 //# Split a path in a drive specification (a drive letter followed by a
1527 //# colon) and the path specification.
1528 //# It is always true that drivespec + pathspec == p
1529 // def splitdrive(p):
1530 // """Split a pathname into drive/UNC sharepoint and relative path
1531 // specifiers. Returns a 2-tuple (drive_or_unc, path); either part may be
1532 // empty.
1533 //
1534 // If you assign
1535 // result = splitdrive(p)
1536 // It is always true that:
1537 // result[0] + result[1] == p
1538 //
1539 // If the path contained a drive letter, drive_or_unc will contain
1540 // everything up to and including the colon. e.g. splitdrive("c:/dir")
1541 // returns ("c:", "/dir")
1542 //
1543 // If the path contained a UNC path, the drive_or_unc will contain the host
1544 // name and share up to but not including the fourth directory separator
1545 // character. e.g. splitdrive("//host/computer/dir") returns
1546 // ("//host/computer", "/dir")
1547 //
1548 // Paths cannot contain both a drive letter and a UNC path.
1549 //
1550 // """
1551 // if len(p) > 1:
1552 // normp = p.replace(altsep, sep)
1553 // if (normp[0:2] == sep*2) and (normp[2] != sep):
1554 // # is a UNC path:
1555 // # vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1556 // # \\machine\mountpoint\directory\etc\...
1557 // # directory ^^^^^^^^^^^^^^^
1558 // index = normp.find(sep, 2)
1559 // if index == -1:
1560 // return '', p
1561 // index2 = normp.find(sep, index + 1)
1562 // # a UNC path can't have two slashes in a row
1563 // # (after the initial two)
1564 // if index2 == index + 1:
1565 // return '', p
1566 // if index2 == -1:
1567 // index2 = len(p)
1568 // return p[:index2], p[index2:]
1569 // if normp[1] == ':':
1570 // return p[:2], p[2:]
1571 // return '', p
1572 
1573 // On Unix, the drive is always empty.
1574 // On the Mac, the drive is always empty (don't use the volume name -- it
1575 // doesn't have the same syntactic and semantic oddities as DOS drive
1576 // letters, such as there being a separate current directory per drive).
1577 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
1578  return std::pair<std::string, std::string>("", pathname);
1579 #else
1580  const std::string sep = "\\";
1581  const std::string sepsep = "\\\\";
1582  const std::string altsep = "/";
1583 
1584  if (pathname.size() > 1) {
1585  std::string normPathname = pathname;
1586  std::replace(normPathname.begin(), normPathname.end(), *altsep.c_str(), *sep.c_str());
1587 
1588  if (normPathname.substr(0, 2) == sepsep && normPathname.substr(2, 1) != sep) {
1589  // is a UNC path:
1590  // vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
1591  // \\machine\mountpoint\directory\etc\...
1592  // directory ^^^^^^^^^^^^^^^
1593  size_t index = normPathname.find(sep, 2);
1594  if (index == std::string::npos) {
1595  return std::pair<std::string, std::string>("", pathname);
1596  }
1597 
1598  size_t index2 = normPathname.find(sep, index + 1);
1599  //# a UNC path can't have two slashes in a row
1600  //# (after the initial two)
1601  if (index2 == index + 1) {
1602  return std::pair<std::string, std::string>("", pathname);
1603  }
1604 
1605  if (index2 == std::string::npos) {
1606  index2 = pathname.size();
1607  }
1608 
1609  return std::pair<std::string, std::string>(pathname.substr(0, index2), pathname.substr(index2));
1610  }
1611 
1612  if (normPathname[1] == ':') {
1613  return std::pair<std::string, std::string>(pathname.substr(0, 2), pathname.substr(2));
1614  }
1615  }
1616 
1617  return std::pair<std::string, std::string>("", pathname);
1618 #endif
1619 }
1620 
1669 std::vector<std::string> vpIoTools::splitChain(const std::string &chain, const std::string &sep)
1670 {
1671  size_t startIndex = 0;
1672 
1673  std::string chainToSplit = chain;
1674  std::vector<std::string> subChain;
1675  size_t sepIndex = chainToSplit.find(sep);
1676 
1677  while (sepIndex != std::string::npos) {
1678  std::string sub = chainToSplit.substr(startIndex, sepIndex);
1679  if (!sub.empty())
1680  subChain.push_back(sub);
1681  chainToSplit = chainToSplit.substr(sepIndex + 1, chain.size() - 1);
1682 
1683  sepIndex = chainToSplit.find(sep);
1684  }
1685  if (!chainToSplit.empty())
1686  subChain.push_back(chainToSplit);
1687 
1688  return subChain;
1689 }
1690 
1698 std::vector<std::string> vpIoTools::getDirFiles(const std::string &pathname)
1699 {
1700 
1701  if (!checkDirectory(pathname)) {
1702  throw(vpIoException(vpException::fatalError, "Directory %s doesn't exist'", pathname.c_str()));
1703  }
1704  std::string dirName = path(pathname);
1705 
1706 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1707 
1708  std::vector<std::string> files;
1709  struct dirent **list = NULL;
1710  int filesCount = scandir(dirName.c_str(), &list, NULL, NULL);
1711  if (filesCount == -1) {
1712  throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1713  }
1714  for (int i = 0; i < filesCount; i++) {
1715  std::string fileName = list[i]->d_name;
1716  if (fileName != "." && fileName != "..") {
1717  files.push_back(fileName);
1718  }
1719  free(list[i]);
1720  }
1721  free(list);
1722  std::sort(files.begin(), files.end());
1723  return files;
1724 
1725 #elif defined(_WIN32)
1726 #if (!defined(WINRT))
1727 
1728  std::vector<std::string> files;
1729  std::string fileMask = dirName;
1730  fileMask.append("\\*");
1731  WIN32_FIND_DATA FindFileData;
1732  HANDLE hFind = FindFirstFile(fileMask.c_str(), &FindFileData);
1733  // Directory is empty
1734  if (HandleToLong(&hFind) == ERROR_FILE_NOT_FOUND) {
1735  return files;
1736  }
1737  if (hFind == INVALID_HANDLE_VALUE) {
1738  throw(vpIoException(vpException::fatalError, "Cannot read files of directory %s", dirName.c_str()));
1739  }
1740  do {
1741  std::string fileName = FindFileData.cFileName;
1742  if (fileName != "." && fileName != "..") {
1743  files.push_back(fileName);
1744  }
1745  } while (FindNextFile(hFind, &FindFileData));
1746  FindClose(hFind);
1747  std::sort(files.begin(), files.end());
1748  return files;
1749 
1750 #else
1752  "Cannot read files of directory %s: not implemented on "
1753  "Universal Windows Platform",
1754  dirName.c_str()));
1755 #endif
1756 #endif
1757 }
static bool remove(const char *filename)
Definition: vpIoTools.cpp:739
static bool checkDirectory(const char *dirname)
Definition: vpIoTools.cpp:371
static std::string getViSPImagesDataPath()
Definition: vpIoTools.cpp:1214
static bool isAbsolutePathname(const std::string &pathname)
Definition: vpIoTools.cpp:1480
static void getVersion(const std::string &version, unsigned int &major, unsigned int &minor, unsigned int &patch)
Definition: vpIoTools.cpp:328
static std::string getFileExtension(const std::string &pathname, const bool checkFile=false)
Definition: vpIoTools.cpp:1261
#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:266
static bool rename(const char *oldfilename, const char *newfilename)
Definition: vpIoTools.cpp:807
static std::string path(const char *pathname)
Definition: vpIoTools.cpp:843
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:1698
static std::string getParent(const std::string &pathname)
Definition: vpIoTools.cpp:1375
static void createBaseNamePath(const bool &empty=false)
Definition: vpIoTools.cpp:1172
static const std::string & getBuildInformation()
Definition: vpIoTools.cpp:105
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:499
static bool checkFilename(const char *filename)
Definition: vpIoTools.cpp:577
static void setBaseName(const std::string &s)
Definition: vpIoTools.cpp:118
static std::string createFilePath(const std::string &parent, const std::string &child)
Definition: vpIoTools.cpp:1439
static int mkdir_p(const char *path, const int mode)
Definition: vpIoTools.cpp:436
static bool copy(const char *src, const char *dst)
Definition: vpIoTools.cpp:638
static std::pair< std::string, std::string > splitDrive(const std::string &pathname)
Definition: vpIoTools.cpp:1524
static bool isSamePathname(const std::string &pathname1, const std::string &pathname2)
Definition: vpIoTools.cpp:1504
static std::string getUserName()
Definition: vpIoTools.cpp:202
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
Definition: vpIoTools.cpp:1669
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:145
static void saveConfigFile(const bool &actuallySave=true)
Definition: vpIoTools.cpp:1191
static std::vector< std::string > configVars
Definition: vpIoTools.h:238
static std::string getName(const std::string &pathname)
Definition: vpIoTools.cpp:1340
static std::string baseName
Definition: vpIoTools.h:235
static std::string getFullName()
Definition: vpIoTools.cpp:136
static std::string configFile
Definition: vpIoTools.h:237
static void setBaseDir(const std::string &dir)
Definition: vpIoTools.cpp:124
static std::string getNameWE(const std::string &pathname)
Definition: vpIoTools.cpp:1362
static std::string getBaseName()
Definition: vpIoTools.cpp:130
#define vpDEBUG_TRACE
Definition: vpDebug.h:487
static std::string getAbsolutePathname(const std::string &pathname)
Definition: vpIoTools.cpp:1397
static vpColor getColor(const unsigned int &i)
Definition: vpColor.h:249
static bool readConfigVar(const std::string &var, float &value)
Definition: vpIoTools.cpp:940
static std::vector< std::string > configValues
Definition: vpIoTools.h:239
static bool loadConfigFile(const std::string &confFile)
Definition: vpIoTools.cpp:893
static void addNameElement(const std::string &strTrue, const bool &cond=true, const std::string &strFalse="")
Definition: vpIoTools.cpp:1137