46 #include <visp/vpIoTools.h>
47 #include <visp/vpDebug.h>
48 #include <visp/vpIoException.h>
54 #include <sys/types.h>
94 char *_username = NULL;
96 if (_username == NULL) {
97 vpERROR_TRACE(
"Cannot get the username. Check your LOGNAME environment variable" );
99 "Cannot get the username")) ;
101 username = _username;
103 unsigned int info_buffer_size = 1024;
104 TCHAR *infoBuf =
new TCHAR [info_buffer_size];
105 DWORD bufCharCount = (DWORD) info_buffer_size;
107 if( ! GetUserName( infoBuf, &bufCharCount ) ) {
111 "Cannot get the username")) ;
138 std::string username;
141 char *_username = NULL;
143 if (_username == NULL) {
144 vpERROR_TRACE(
"Cannot get the username. Check your LOGNAME environment variable" );
146 "Cannot get the username")) ;
148 username = _username;
150 unsigned int info_buffer_size = 1024;
151 TCHAR *infoBuf =
new TCHAR [info_buffer_size];
152 DWORD bufCharCount = (DWORD) info_buffer_size;
154 if( ! GetUserName( infoBuf, &bufCharCount ) ) {
158 "Cannot get the username")) ;
215 if (_value == NULL) {
216 vpERROR_TRACE(
"Cannot get the environment variable value" );
218 "Cannot get the environment variable value")) ;
227 "Not implemented!")) ;
297 if ( dirname == NULL || dirname[0] ==
'\0' ) {
301 std::string _dirname =
path(dirname);
304 if ( stat( _dirname.c_str(), &stbuf ) != 0 )
306 if ( _stat( _dirname.c_str(), &stbuf ) != 0 )
311 if ( (stbuf.st_mode & S_IFDIR) == 0 ) {
315 if ( (stbuf.st_mode & S_IWUSR) == 0 )
317 if ( (stbuf.st_mode & S_IWRITE) == 0 )
366 if ( dirname == NULL || dirname[0] ==
'\0' ) {
369 "invalid directory name")) ;
372 std::string _dirname =
path(dirname);
375 if ( stat( _dirname.c_str(), &stbuf ) != 0 )
377 if ( _stat( _dirname.c_str(), &stbuf ) != 0 )
381 if ( mkdir( _dirname.c_str(), (mode_t)0755 ) != 0 )
383 if ( _mkdir( _dirname.c_str()) != 0 )
386 vpERROR_TRACE(
"unable to create directory '%s'\n", dirname );
388 "unable to create directory")) ;
394 vpERROR_TRACE(
"unable to create directory '%s'\n", dirname );
396 "unable to create directory")) ;
419 vpERROR_TRACE(
"unable to create directory '%s'\n",dirname.c_str());
421 "unable to create directory")) ;
447 if ( filename == NULL || filename[0] ==
'\0' ) {
451 std::string _filename =
path(filename);
453 if ( stat( _filename.c_str(), &stbuf ) != 0 )
455 if ( _stat( _filename.c_str(), &stbuf ) != 0 )
460 if ( (stbuf.st_mode & S_IFREG) == 0 ) {
464 if ( (stbuf.st_mode & S_IRUSR) == 0 )
466 if ( (stbuf.st_mode & S_IREAD) == 0 )
507 char cmd[FILENAME_MAX];
513 sprintf(cmd,
"cp -p %s %s", src, dst);
517 sprintf(cmd,
"copy %s %s", src_.c_str(), dst_.c_str());
526 sprintf(cmd,
"cp -p -r %s %s", src, dst);
530 sprintf(cmd,
"copy %s %s", src_.c_str(), dst_.c_str());
538 std::cout <<
"Cannot copy: " << src <<
" in " << dst << std::endl;
576 if (::
remove(file_or_dir) != 0)
583 char cmd[FILENAME_MAX];
585 sprintf(cmd,
"rm -rf %s", file_or_dir);
588 sprintf(cmd,
"rmdir /S /Q %s", file_or_dir_.c_str());
590 int ret = system( cmd );
596 std::cout <<
"Cannot remove: " << file_or_dir << std::endl;
631 if (::
rename(oldfilename, newfilename) != 0)
671 std::string
path(pathname);
674 for(
unsigned int i=0 ; i<path.length() ; i++)
675 if( path[i] ==
'/') path[i] =
'\\';
677 for(
unsigned int i=0 ; i<path.length() ; i++)
678 if( path[i] ==
'\\') path[i] =
'/';
699 return path(pathname.c_str());
712 std::ifstream confContent(confFile.c_str(), std::ios::in);
716 std::string line,var,val;
719 std::string stop[3] = {
" ",
"\t",
"#"};
720 while(std::getline(confContent, line))
722 if((line.find(
"#",0,1) != 0) && (line.size() > 2))
728 var = line.substr(0,k);
731 for(
unsigned i=0;i<3;++i)
734 c = (int)line.size();
735 long unsigned int c_ = (
long unsigned int) c;
736 val = line.substr(k+1,c_-k-1);
758 for(
unsigned int k=0;k<
configVars.size() && found==
false;++k)
767 std::cout << var <<
" not found in config file" << std::endl;
782 for(
unsigned int k=0;k<
configVars.size() && found==
false;++k)
791 std::cout << var <<
" not found in config file" << std::endl;
807 value = (
unsigned int) v;
854 for(
unsigned int k=0;k<
configVars.size() && found==
false;++k)
863 std::cout << var <<
" not found in config file" << std::endl;
882 for(
unsigned int k=0;k<
configVars.size() && found==
false;++k)
888 if(nCols != 0 && nRows != 0)
889 value.
resize(nRows, nCols);
890 long unsigned int ind=0,ind2;
891 for(
unsigned int i=0;i<value.
getRows();++i)
892 for(
unsigned int j=0;j<value.
getCols();++j)
895 value[i][j] = atof(
configValues[k].substr(ind,ind2-ind).c_str());
901 std::cout << var <<
" not found in config file" << std::endl;
918 else if(strFalse !=
"")
932 if(std::fabs(val) < std::numeric_limits<double>::epsilon())
935 sprintf(valC,
"%.3f", val);
936 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.