46 #include <visp/vpIoTools.h>
47 #include <visp/vpDebug.h>
48 #include <visp/vpIoException.h>
54 #include <sys/types.h>
58 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
96 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
98 char *_username = NULL;
100 if (_username == NULL) {
101 vpERROR_TRACE(
"Cannot get the username. Check your LOGNAME environment variable" );
103 "Cannot get the username")) ;
105 username = _username;
106 #elif defined(_WIN32)
107 unsigned int info_buffer_size = 1024;
108 TCHAR *infoBuf =
new TCHAR [info_buffer_size];
109 DWORD bufCharCount = (DWORD) info_buffer_size;
111 if( ! GetUserName( infoBuf, &bufCharCount ) ) {
115 "Cannot get the username")) ;
142 std::string username;
143 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
145 char *_username = NULL;
147 if (_username == NULL) {
148 vpERROR_TRACE(
"Cannot get the username. Check your LOGNAME environment variable" );
150 "Cannot get the username")) ;
152 username = _username;
153 #elif defined(_WIN32)
154 unsigned int info_buffer_size = 1024;
155 TCHAR *infoBuf =
new TCHAR [info_buffer_size];
156 DWORD bufCharCount = (DWORD) info_buffer_size;
158 if( ! GetUserName( infoBuf, &bufCharCount ) ) {
162 "Cannot get the username")) ;
209 #
if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
215 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
219 if (_value == NULL) {
220 vpERROR_TRACE(
"Cannot get the environment variable value" );
222 "Cannot get the environment variable value")) ;
227 #elif defined(_WIN32)
231 "Not implemented!")) ;
290 if(version.size() == 0){
296 size_t major_pos = version.find(
'.');
297 std::string major_str = version.substr(0, major_pos);
298 major = (unsigned)atoi(major_str.c_str());
300 if(major_pos != std::string::npos){
301 size_t minor_pos = version.find(
'.', major_pos+1);
302 std::string minor_str = version.substr(major_pos+1, (minor_pos - (major_pos+1)));
303 minor = (unsigned)atoi(minor_str.c_str());
305 if(minor_pos != std::string::npos){
306 std::string patch_str = version.substr(minor_pos+1);
307 patch = (unsigned)atoi(patch_str.c_str());
337 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
339 #elif defined(_WIN32)
343 if ( dirname == NULL || dirname[0] ==
'\0' ) {
347 std::string _dirname =
path(dirname);
349 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
350 if ( stat( _dirname.c_str(), &stbuf ) != 0 )
351 #elif defined(_WIN32)
352 if ( _stat( _dirname.c_str(), &stbuf ) != 0 )
357 if ( (stbuf.st_mode & S_IFDIR) == 0 ) {
360 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
361 if ( (stbuf.st_mode & S_IWUSR) == 0 )
362 #elif defined(_WIN32)
363 if ( (stbuf.st_mode & S_IWRITE) == 0 )
406 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
408 #elif defined(_WIN32)
412 if ( dirname == NULL || dirname[0] ==
'\0' ) {
415 "invalid directory name")) ;
418 std::string _dirname =
path(dirname);
420 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
421 if ( stat( _dirname.c_str(), &stbuf ) != 0 )
422 #elif defined(_WIN32)
423 if ( _stat( _dirname.c_str(), &stbuf ) != 0 )
426 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
427 if ( mkdir( _dirname.c_str(), (mode_t)0755 ) != 0 )
428 #elif defined(_WIN32)
429 if ( _mkdir( _dirname.c_str()) != 0 )
432 vpERROR_TRACE(
"unable to create directory '%s'\n", dirname );
434 "unable to create directory")) ;
440 vpERROR_TRACE(
"unable to create directory '%s'\n", dirname );
442 "unable to create directory")) ;
465 vpERROR_TRACE(
"unable to create directory '%s'\n",dirname.c_str());
467 "unable to create directory")) ;
487 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
489 #elif defined(_WIN32)
493 if ( filename == NULL || filename[0] ==
'\0' ) {
497 std::string _filename =
path(filename);
498 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
499 if ( stat( _filename.c_str(), &stbuf ) != 0 )
500 #elif defined(_WIN32)
501 if ( _stat( _filename.c_str(), &stbuf ) != 0 )
506 if ( (stbuf.st_mode & S_IFREG) == 0 ) {
509 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
510 if ( (stbuf.st_mode & S_IRUSR) == 0 )
511 #elif defined(_WIN32)
512 if ( (stbuf.st_mode & S_IREAD) == 0 )
553 char cmd[FILENAME_MAX];
558 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
559 sprintf(cmd,
"cp -p %s %s", src, dst);
560 #elif defined(_WIN32)
563 sprintf(cmd,
"copy %s %s", src_.c_str(), dst_.c_str());
571 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
572 sprintf(cmd,
"cp -p -r %s %s", src, dst);
573 #elif defined(_WIN32)
576 sprintf(cmd,
"copy %s %s", src_.c_str(), dst_.c_str());
584 std::cout <<
"Cannot copy: " << src <<
" in " << dst << std::endl;
622 if (::
remove(file_or_dir) != 0)
629 char cmd[FILENAME_MAX];
630 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
631 sprintf(cmd,
"rm -rf %s", file_or_dir);
632 #elif defined(_WIN32)
634 sprintf(cmd,
"rmdir /S /Q %s", file_or_dir_.c_str());
636 int ret = system( cmd );
642 std::cout <<
"Cannot remove: " << file_or_dir << std::endl;
677 if (::
rename(oldfilename, newfilename) != 0)
717 std::string
path(pathname);
720 for(
unsigned int i=0 ; i<path.length() ; i++)
721 if( path[i] ==
'/') path[i] =
'\\';
723 for(
unsigned int i=0 ; i<path.length() ; i++)
724 if( path[i] ==
'\\') path[i] =
'/';
725 wordexp_t exp_result;
726 wordexp(path.c_str(), &exp_result, 0);
727 path = std::string(exp_result.we_wordv[0]);
728 wordfree(&exp_result);
749 return path(pathname.c_str());
764 std::ifstream confContent(
configFile.c_str(), std::ios::in);
766 if(confContent.is_open())
768 std::string line,var,val;
771 std::string stop[3] = {
" ",
"\t",
"#"};
772 while(std::getline(confContent, line))
774 if((line.find(
"#",0,1) != 0) && (line.size() > 2))
779 k = (
unsigned long)line.find(
" ");
780 var = line.substr(0,k);
783 for(
unsigned i=0;i<3;++i)
786 c = (int)line.size();
787 long unsigned int c_ = (
long unsigned int) c;
788 val = line.substr(k+1,c_-k-1);
814 for(
unsigned int k=0;k<
configVars.size() && found==
false;++k)
830 std::cout << var <<
" not found in config file" << std::endl;
844 for(
unsigned int k=0;k<
configVars.size() && found==
false;++k)
860 std::cout << var <<
" not found in config file" << std::endl;
875 for(
unsigned int k=0;k<
configVars.size() && found==
false;++k)
884 std::cout << var <<
" not found in config file" << std::endl;
900 value = (
unsigned int) v;
947 for(
unsigned int k=0;k<
configVars.size() && found==
false;++k)
956 std::cout << var <<
" not found in config file" << std::endl;
976 for(
unsigned int k=0;k<
configVars.size() && found==
false;++k)
982 if(nCols != 0 && nRows != 0)
983 value.
resize(nRows, nCols);
985 for(
unsigned int i=0;i<value.
getRows();++i)
986 for(
unsigned int j=0;j<value.
getCols();++j)
990 if(nb.compare(
"PI") == 0)
992 else if(nb.compare(
"PI/2") == 0)
993 value[i][j] = M_PI/2;
994 else if(nb.compare(
"-PI/2") == 0)
995 value[i][j] = -M_PI/2;
997 value[i][j] = atof(nb.c_str());
1003 std::cout << var <<
" not found in config file" << std::endl;
1020 else if(strFalse !=
"")
1034 if(std::fabs(val) < std::numeric_limits<double>::epsilon())
1037 sprintf(valC,
"%.3f", val);
1038 std::string valS(valC);
Definition of the vpMatrix class.
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Class to define colors available for display functionnalities.
Error that can be emited by the vpIoTools class and its derivates.
static Type minimum(const Type &a, const Type &b)
unsigned int getCols() const
Return the number of columns of the matrix.
static vpColor getColor(const unsigned int &i)
unsigned int getRows() const
Return the number of rows of the matrix.