65 #include <sys/types.h>
66 #include <visp3/core/vpDebug.h>
67 #include <visp3/core/vpEndian.h>
68 #include <visp3/core/vpIoException.h>
69 #include <visp3/core/vpIoTools.h>
70 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
85 #if defined(__APPLE__) && defined(__MACH__)
86 #include <TargetConditionals.h>
91 #define PATH_MAX _MAX_PATH
97 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
99 #elif defined(_WIN32) && defined(__MINGW32__)
101 #elif defined(_WIN32)
102 #define VP_STAT _stat
117 #if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
118 #if (TARGET_OS_IOS == 0) && !defined(__ANDROID__)
119 void replaceAll(std::string &str,
const std::string &search,
const std::string &replace)
121 size_t start_pos = 0;
122 while ((start_pos = str.find(search, start_pos)) != std::string::npos) {
123 str.replace(start_pos, search.length(), replace);
124 start_pos += replace.length();
131 std::string <rim(std::string &s)
133 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
134 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](
int c) {
135 return !std::isspace(c);
138 s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
143 std::string &rtrim(std::string &s)
145 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
146 s.erase(std::find_if(s.rbegin(), s.rend(), [](
int c) {
147 return !std::isspace(c);
150 s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
161 static std::string build_info =
162 #include "version_string.inc"
220 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
221 std::string username;
223 return "/tmp/" + username;
224 #elif defined(_WIN32) && !defined(WINRT)
227 TCHAR lpTempPathBuffer[MAX_PATH];
228 DWORD dwRetVal = GetTempPath(MAX_PATH , lpTempPathBuffer );
229 if (dwRetVal > MAX_PATH || (dwRetVal == 0)) {
232 std::string temp_path(lpTempPathBuffer);
233 if (!temp_path.empty()) {
234 if (temp_path.back() ==
'\\') {
235 temp_path.resize(temp_path.size() - 1);
239 temp_path =
"C:\temp";
297 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
299 char *_username =
::getenv(
"LOGNAME");
301 username =
"unknown";
304 username = _username;
306 #elif defined(_WIN32)
307 #if (!defined(WINRT))
308 unsigned int info_buffer_size = 1024;
309 TCHAR *infoBuf =
new TCHAR[info_buffer_size];
310 DWORD bufCharCount = (DWORD)info_buffer_size;
312 if (!GetUserName(infoBuf, &bufCharCount)) {
313 username =
"unknown";
321 username =
"unknown";
324 username =
"unknown";
344 std::string username;
381 #if defined(_WIN32) && defined(WINRT)
383 "implemented on Universal Windows Platform"));
387 char *_value =
::getenv(env.c_str());
406 void vpIoTools::getVersion(
const std::string &version,
unsigned int &major,
unsigned int &minor,
unsigned int &patch)
408 if (version.size() == 0) {
414 size_t major_pos = version.find(
'.');
415 std::string major_str = version.substr(0, major_pos);
416 major =
static_cast<unsigned>(atoi(major_str.c_str()));
418 if (major_pos != std::string::npos) {
419 size_t minor_pos = version.find(
'.', major_pos + 1);
420 std::string minor_str = version.substr(major_pos + 1, (minor_pos - (major_pos + 1)));
421 minor =
static_cast<unsigned>(atoi(minor_str.c_str()));
423 if (minor_pos != std::string::npos) {
424 std::string patch_str = version.substr(minor_pos + 1);
425 patch =
static_cast<unsigned>(atoi(patch_str.c_str()));
451 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
453 #elif defined(_WIN32) && defined(__MINGW32__)
455 #elif defined(_WIN32)
459 if (dirname.empty()) {
463 std::string _dirname =
path(dirname);
465 if (VP_STAT(_dirname.c_str(), &stbuf) != 0) {
466 std::cout <<
"DEBUG 1 _dirname: " << _dirname <<
" is not a dir" << std::endl;
468 if (_dirname.at(_dirname.size() - 1) !=
separator) {
469 std::cout <<
"DEBUG 2 test if _dirname + separator: " << _dirname +
separator <<
" is a dir ?" << std::endl;
470 if (VP_STAT((_dirname +
separator).c_str(), &stbuf) != 0) {
471 std::cout <<
"DEBUG 2 _dirname + separator: " << _dirname +
separator <<
" is not a dir" << std::endl;
476 if (_dirname.at(_dirname.size() - 1) ==
separator) {
477 std::cout <<
"DEBUG 2 test if _dirname - separator: " << _dirname.substr(0, _dirname.size() - 1) <<
" is a dir ?" << std::endl;
478 if (VP_STAT((_dirname.substr(0, _dirname.size() - 1)).c_str(), &stbuf) != 0) {
479 std::cout <<
"DEBUG 3 _dirname - separator: " << _dirname.substr(0, _dirname.size() - 1) <<
" is not a dir" << std::endl;
485 #if defined(_WIN32) || (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
486 if ((stbuf.st_mode & S_IFDIR) == 0)
491 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
492 if ((stbuf.st_mode & S_IWUSR) == 0)
493 #elif defined(_WIN32)
494 if ((stbuf.st_mode & S_IWRITE) == 0)
516 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
519 std::string _filename =
path(fifofilename);
520 if (stat(_filename.c_str(), &stbuf) != 0) {
523 if ((stbuf.st_mode & S_IFIFO) == 0) {
526 if ((stbuf.st_mode & S_IRUSR) == 0)
532 #elif defined(_WIN32)
538 #ifndef DOXYGEN_SHOULD_SKIP_THIS
539 int vpIoTools::mkdir_p(
const std::string &path,
int mode)
542 if (
path.size() > PATH_MAX) {
543 errno = ENAMETOOLONG;
548 std::string _path =
path;
549 std::string _sub_path;
551 _sub_path += _path.substr(0, pos + 1);
554 _path.erase(0, pos + 1);
557 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
558 if (mkdir(_sub_path.c_str(),
static_cast<mode_t
>(mode)) != 0)
559 #elif defined(_WIN32)
564 if (errno != EEXIST) {
568 _path.erase(0, pos + 1);
571 if (!_path.empty()) {
573 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
574 if (mkdir(_sub_path.c_str(),
static_cast<mode_t
>(mode)) != 0)
575 #elif defined(_WIN32)
577 if (_mkdir(_sub_path.c_str()) != 0)
580 if (errno != EEXIST) {
605 #if ((!defined(__unix__) && !defined(__unix) && (!defined(__APPLE__) || !defined(__MACH__)))) && !defined(_WIN32)
606 std::cerr <<
"Unsupported platform for vpIoTools::makeDirectory()!" << std::endl;
610 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
612 #elif defined(_WIN32) && defined(__MINGW32__)
614 #elif defined(_WIN32)
618 if (dirname.empty()) {
622 std::string _dirname =
path(dirname);
624 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
625 if (stat(_dirname.c_str(), &stbuf) != 0)
626 #elif defined(_WIN32) && defined(__MINGW32__)
627 if (stat(_dirname.c_str(), &stbuf) != 0)
628 #elif defined(_WIN32)
629 if (_stat(_dirname.c_str(), &stbuf) != 0)
632 if (vpIoTools::mkdir_p(_dirname, 0755) != 0) {
656 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
661 "Unable to create fifo file. '%s' is an existing directory.", fifoname.c_str()));
675 else if (mkfifo(fifoname.c_str(), 0666) < 0) {
678 #elif defined(_WIN32)
684 #if defined(_WIN32) && !defined(WINRT)
685 std::string getUuid()
688 if (UuidCreate(&uuid) != RPC_S_OK) {
693 if (UuidToString(&uuid, &stringUuid) != RPC_S_OK) {
697 return reinterpret_cast<char *
>(stringUuid);
759 #if defined(WINRT) || !defined(_WIN32) && !(defined(__unix__) || defined(__unix) || \
760 (defined(__APPLE__) && defined(__MACH__)))
764 std::string dirname_cpy = std::string(dirname);
765 std::string correctEnding =
"XXXXXX";
769 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
771 if (dirname_cpy.rfind(correctEnding) == std::string::npos) {
772 if (dirname_cpy.at(dirname_cpy.length() - 1) !=
'/') {
773 dirname_cpy = dirname_cpy +
"/";
782 dirname_cpy = dirname_cpy +
"XXXXXX";
785 #elif defined(_WIN32) && !defined(WINRT)
787 dirname_cpy = dirname_cpy.substr(0, dirname_cpy.rfind(correctEnding));
789 dirname_cpy = dirname_cpy + getUuid();
795 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
796 if (dirname_cpy.at(dirname_cpy.length() - 1) !=
'/') {
797 dirname_cpy = dirname_cpy +
"/";
799 dirname_cpy = dirname_cpy +
"XXXXXX";
800 #elif defined(_WIN32) && !defined(WINRT)
805 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
806 char *dirname_char =
new char[dirname_cpy.length() + 1];
807 strcpy(dirname_char, dirname_cpy.c_str());
809 char *computedDirname = mkdtemp(dirname_char);
811 if (!computedDirname) {
812 delete[] dirname_char;
816 std::string res(computedDirname);
817 delete[] dirname_char;
819 #elif defined(_WIN32) && !defined(WINRT)
837 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
839 #elif defined(_WIN32)
843 if (filename.empty()) {
847 std::string _filename =
path(filename);
848 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
849 if (stat(_filename.c_str(), &stbuf) != 0)
850 #elif defined(_WIN32)
851 if (_stat(_filename.c_str(), &stbuf) != 0)
856 if ((stbuf.st_mode & S_IFREG) == 0) {
859 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
860 if ((stbuf.st_mode & S_IRUSR) == 0)
861 #elif defined(_WIN32)
862 if ((stbuf.st_mode & S_IREAD) == 0)
882 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
883 #if TARGET_OS_IOS == 0
885 std::stringstream cmd;
890 int ret = system(cmd.str().c_str());
899 #elif defined(_WIN32)
900 #if (!defined(WINRT))
901 std::stringstream cmd;
906 int ret = system(cmd.str().c_str());
913 src.c_str(), dst.c_str()));
919 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
920 #if TARGET_OS_IOS == 0
922 std::stringstream cmd;
927 int ret = system(cmd.str().c_str());
936 #elif defined(_WIN32)
937 #if (!defined(WINRT))
938 std::stringstream cmd;
943 int ret = system(cmd.str().c_str());
950 src.c_str(), dst.c_str()));
955 std::cout <<
"Cannot copy: " << src <<
" in " << dst << std::endl;
974 #
if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
979 if (::
remove(file_or_dir.c_str()) != 0)
986 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
987 #if TARGET_OS_IOS == 0
989 std::stringstream cmd;
993 int ret = system(cmd.str().c_str());
1000 file_or_dir.c_str()));
1002 #elif defined(_WIN32)
1003 #if (!defined(WINRT))
1004 std::stringstream cmd;
1005 cmd <<
"rmdir /S /Q ";
1008 int ret = system(cmd.str().c_str());
1015 file_or_dir.c_str()));
1020 std::cout <<
"Cannot remove: " << file_or_dir << std::endl;
1036 if (::
rename(oldfilename.c_str(), newfilename.c_str()) != 0)
1054 std::string
path(pathname);
1057 for (
unsigned int i = 0; i <
path.length(); i++)
1060 #elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
1061 for (
unsigned int i = 0; i <
path.length(); i++)
1062 if (
path[i] ==
'\\')
1064 #if TARGET_OS_IOS == 0
1069 wordexp_t exp_result;
1072 replaceAll(
path,
"'",
"'\\''");
1074 wordexp(std::string(
"'" +
path +
"'").c_str(), &exp_result, 0);
1075 path = exp_result.we_wordc == 1 ? exp_result.we_wordv[0] :
"";
1076 wordfree(&exp_result);
1097 std::ifstream confContent(
configFile.c_str(), std::ios::in);
1099 if (confContent.is_open()) {
1100 std::string line, var, val;
1101 long unsigned int k;
1103 std::string stop[3] = {
" ",
"\t",
"#" };
1104 while (std::getline(confContent, line)) {
1105 if ((line.compare(0, 1,
"#") != 0) && (line.size() > 2)) {
1108 k =
static_cast<unsigned long>(line.find(
" "));
1109 var = line.substr(0, k);
1112 for (
unsigned i = 0; i < 3; ++i)
1114 static_cast<int>(line.find(stop[i],
static_cast<size_t>(k) +
static_cast<size_t>(1))));
1116 c =
static_cast<int>(line.size());
1117 long unsigned int c_ =
static_cast<long unsigned int>(c);
1118 val = line.substr(
static_cast<size_t>(k) +
static_cast<size_t>(1),
1119 static_cast<size_t>(c_) -
static_cast<size_t>(k) -
static_cast<size_t>(1));
1127 confContent.close();
1146 for (
unsigned int k = 0; k <
configVars.size() && found ==
false; ++k) {
1149 value =
static_cast<float>(M_PI);
1151 value =
static_cast<float>(M_PI / 2.0);
1153 value =
static_cast<float>(-M_PI / 2.0);
1155 value =
static_cast<float>(atof(
configValues[k].c_str()));
1160 std::cout << var <<
" not found in config file" << std::endl;
1174 for (
unsigned int k = 0; k <
configVars.size() && found ==
false; ++k) {
1188 std::cout << var <<
" not found in config file" << std::endl;
1203 for (
unsigned int k = 0; k <
configVars.size() && found ==
false; ++k) {
1210 std::cout << var <<
" not found in config file" << std::endl;
1226 value =
static_cast<unsigned int>(v);
1273 for (
unsigned int k = 0; k <
configVars.size() && found ==
false; ++k) {
1280 std::cout << var <<
" not found in config file" << std::endl;
1298 const unsigned int &nRows)
1302 for (
unsigned int k = 0; k <
configVars.size() && found ==
false; ++k) {
1306 if (nCols != 0 && nRows != 0)
1307 value.
resize(nRows, nCols);
1308 size_t ind = 0, ind2;
1309 for (
unsigned int i = 0; i < value.
getRows(); ++i)
1310 for (
unsigned int j = 0; j < value.
getCols(); ++j) {
1313 if (nb.compare(
"PI") == 0)
1315 else if (nb.compare(
"PI/2") == 0)
1316 value[i][j] = M_PI / 2;
1317 else if (nb.compare(
"-PI/2") == 0)
1318 value[i][j] = -M_PI / 2;
1320 value[i][j] = atof(nb.c_str());
1326 std::cout << var <<
" not found in config file" << std::endl;
1344 else if (strFalse !=
"")
1359 if (std::fabs(val) < std::numeric_limits<double>::epsilon()) {
1360 std::stringstream valS;
1363 baseName +=
"_" + strTrue + valS.str();
1419 std::string data_path;
1420 std::string file_to_test(
"mbt/cube.cao");
1421 std::string filename;
1425 filename = data_path +
"/" + file_to_test;
1429 filename = data_path +
"/" + file_to_test;
1433 filename = data_path +
"/" + file_to_test;
1439 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
1441 data_path =
"/usr/share/visp-images-data/ViSP-images";
1442 filename = data_path +
"/" + file_to_test;
1445 data_path =
"/usr/share/visp-images-data/visp-images";
1446 filename = data_path +
"/" + file_to_test;
1490 std::string sep =
"\\";
1491 std::string altsep =
"/";
1492 std::string extsep =
".";
1495 std::string sep =
"/";
1496 std::string altsep =
"";
1497 std::string extsep =
".";
1530 int sepIndex =
static_cast<int>(pathname.rfind(sep));
1531 if (!altsep.empty()) {
1532 int altsepIndex =
static_cast<int>(pathname.rfind(altsep));
1533 sepIndex = ((std::max))(sepIndex, altsepIndex);
1536 size_t dotIndex = pathname.rfind(extsep);
1537 if (dotIndex != std::string::npos) {
1539 size_t npos = std::string::npos;
1540 if ((sepIndex !=
static_cast<int>(npos) &&
static_cast<int>(dotIndex) > sepIndex) ||
1541 sepIndex ==
static_cast<int>(npos)) {
1542 if (sepIndex ==
static_cast<int>(npos)) {
1545 size_t filenameIndex =
static_cast<size_t>(sepIndex) +
static_cast<size_t>(1);
1547 while (filenameIndex < dotIndex) {
1548 if (pathname.compare(filenameIndex, 1, extsep) != 0) {
1549 return pathname.substr(dotIndex);
1566 if (pathname.size() > 0) {
1570 if (index != std::string::npos) {
1571 return convertedPathname.substr(index + 1);
1574 return convertedPathname;
1589 size_t found = name.find_last_of(
".");
1590 std::string name_we = name.substr(0, found);
1629 size_t indexBegin = format.find_last_of(
'%');
1630 size_t indexEnd = format.find_first_of(
'd', indexBegin);
1631 size_t suffixLength = format.length() - indexEnd - 1;
1633 if (filename.length() <= suffixLength + indexBegin) {
1636 size_t indexLength = filename.length() - suffixLength - indexBegin;
1637 std::string indexSubstr = filename.substr(indexBegin, indexLength);
1638 std::istringstream ss(indexSubstr);
1641 if (ss.fail() || index < 0 || !ss.eof()) {
1646 char nameByFormat[FILENAME_MAX];
1647 snprintf(nameByFormat, FILENAME_MAX, format.c_str(), index);
1648 if (std::string(nameByFormat) != filename) {
1671 if (pathname.size() > 0) {
1675 if (index != std::string::npos) {
1676 return convertedPathname.substr(0, index);
1697 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
1698 for (
size_t i = 0; i < input.size(); i++) {
1699 out += std::tolower(input[i]);
1702 for (std::string::const_iterator it = input.cbegin(); it != input.cend(); it++) {
1703 out += std::tolower(*it);
1720 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
1721 for (
size_t i = 0; i < input.size(); i++) {
1722 out += std::toupper(input[i]);
1725 for (std::string::const_iterator it = input.cbegin(); it != input.cend(); it++) {
1726 out += std::toupper(*it);
1743 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
1744 std::string real_path_str = pathname;
1745 char *real_path = realpath(pathname.c_str(), NULL);
1748 real_path_str = real_path;
1751 return real_path_str;
1752 #elif defined(_WIN32)
1753 #if (!defined(WINRT))
1754 std::string real_path_str = pathname;
1756 TCHAR buffer[4096] = TEXT(
"");
1758 retval = GetFullPathName(pathname.c_str(), 4096, buffer, 0);
1760 real_path_str = buffer;
1762 return real_path_str;
1765 "Cannot get absolute path of %s: not implemented on "
1766 "Universal Windows Platform",
1784 if (child.size() == 0 && parent.size() == 0) {
1788 if (child.size() == 0) {
1792 if (parent.size() == 0) {
1799 std::stringstream ss;
1801 std::string stringSeparator;
1802 ss >> stringSeparator;
1804 std::string lastConvertedParentChar = convertedParent.substr(convertedParent.size() - 1);
1805 std::string firstConvertedChildChar = convertedChild.substr(0, 1);
1807 if (lastConvertedParentChar == stringSeparator) {
1808 convertedParent = convertedParent.substr(0, convertedParent.size() - 1);
1811 if (firstConvertedChildChar == stringSeparator) {
1812 convertedChild = convertedChild.substr(1);
1837 return path.size() > 0 && (
path.substr(0, 1) ==
"/" ||
path.substr(0, 1) ==
"\\");
1857 return (path1_normalize == path2_normalize);
1920 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
1921 return std::pair<std::string, std::string>(
"", pathname);
1923 const std::string sep =
"\\";
1924 const std::string sepsep =
"\\\\";
1925 const std::string altsep =
"/";
1927 if (pathname.size() > 1) {
1928 std::string normPathname = pathname;
1929 std::replace(normPathname.begin(), normPathname.end(), *altsep.c_str(), *sep.c_str());
1931 if (normPathname.substr(0, 2) == sepsep && normPathname.substr(2, 1) != sep) {
1936 size_t index = normPathname.find(sep, 2);
1937 if (index == std::string::npos) {
1938 return std::pair<std::string, std::string>(
"", pathname);
1941 size_t index2 = normPathname.find(sep, index + 1);
1944 if (index2 == index + 1) {
1945 return std::pair<std::string, std::string>(
"", pathname);
1948 if (index2 == std::string::npos) {
1949 index2 = pathname.size();
1952 return std::pair<std::string, std::string>(pathname.substr(0, index2), pathname.substr(index2));
1955 if (normPathname[1] ==
':') {
1956 return std::pair<std::string, std::string>(pathname.substr(0, 2), pathname.substr(2));
1960 return std::pair<std::string, std::string>(
"", pathname);
2014 size_t startIndex = 0;
2016 std::string chainToSplit = chain;
2017 std::vector<std::string> subChain;
2018 size_t sepIndex = chainToSplit.find(sep);
2020 while (sepIndex != std::string::npos) {
2021 std::string sub = chainToSplit.substr(startIndex, sepIndex);
2023 subChain.push_back(sub);
2024 chainToSplit = chainToSplit.substr(sepIndex + 1, chain.size() - 1);
2026 sepIndex = chainToSplit.find(sep);
2028 if (!chainToSplit.empty())
2029 subChain.push_back(chainToSplit);
2047 std::string dirName =
path(pathname);
2049 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
2051 std::vector<std::string> files;
2052 struct dirent **list = NULL;
2053 int filesCount = scandir(dirName.c_str(), &list, NULL, NULL);
2054 if (filesCount == -1) {
2057 for (
int i = 0; i < filesCount; i++) {
2058 std::string fileName = list[i]->d_name;
2059 if (fileName !=
"." && fileName !=
"..") {
2060 files.push_back(fileName);
2065 std::sort(files.begin(), files.end());
2068 #elif defined(_WIN32)
2069 #if (!defined(WINRT))
2071 std::vector<std::string> files;
2072 std::string fileMask = dirName;
2073 fileMask.append(
"\\*");
2074 WIN32_FIND_DATA FindFileData;
2075 HANDLE hFind = FindFirstFile(fileMask.c_str(), &FindFileData);
2077 if (HandleToLong(&hFind) == ERROR_FILE_NOT_FOUND) {
2080 if (hFind == INVALID_HANDLE_VALUE) {
2084 std::string fileName = FindFileData.cFileName;
2085 if (fileName !=
"." && fileName !=
"..") {
2086 files.push_back(fileName);
2088 }
while (FindNextFile(hFind, &FindFileData));
2090 std::sort(files.begin(), files.end());
2095 "Cannot read files of directory %s: not implemented on "
2096 "Universal Windows Platform",
2107 file.read((
char *)(&short_value),
sizeof(short_value));
2109 #ifdef VISP_BIG_ENDIAN
2120 file.read((
char *)(&ushort_value),
sizeof(ushort_value));
2122 #ifdef VISP_BIG_ENDIAN
2133 file.read((
char *)(&int_value),
sizeof(int_value));
2135 #ifdef VISP_BIG_ENDIAN
2146 file.read((
char *)(&uint_value),
sizeof(uint_value));
2148 #ifdef VISP_BIG_ENDIAN
2159 file.read((
char *)(&float_value),
sizeof(float_value));
2161 #ifdef VISP_BIG_ENDIAN
2172 file.read((
char *)(&double_value),
sizeof(double_value));
2174 #ifdef VISP_BIG_ENDIAN
2185 #ifdef VISP_BIG_ENDIAN
2188 file.write((
char *)(&swap_short),
sizeof(swap_short));
2190 file.write((
char *)(&short_value),
sizeof(short_value));
2199 #ifdef VISP_BIG_ENDIAN
2202 file.write((
char *)(&swap_ushort),
sizeof(swap_ushort));
2204 file.write((
char *)(&ushort_value),
sizeof(ushort_value));
2213 #ifdef VISP_BIG_ENDIAN
2216 file.write((
char *)(&swap_int),
sizeof(swap_int));
2218 file.write((
char *)(&int_value),
sizeof(int_value));
2227 #ifdef VISP_BIG_ENDIAN
2230 file.write((
char *)(&swap_int),
sizeof(swap_int));
2232 file.write((
char *)(&uint_value),
sizeof(uint_value));
2241 #ifdef VISP_BIG_ENDIAN
2244 file.write((
char *)(&swap_float),
sizeof(swap_float));
2246 file.write((
char *)(&float_value),
sizeof(float_value));
2255 #ifdef VISP_BIG_ENDIAN
2258 file.write((
char *)(&swap_double),
sizeof(swap_double));
2260 file.write((
char *)(&double_value),
sizeof(double_value));
2266 std::transform(input.begin(), input.end(), input.begin(), ::tolower);
2267 std::istringstream is(input);
2271 is >> (input.size() > 1 ? std::boolalpha : std::noboolalpha) >> b;
unsigned int getCols() const
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int getRows() const
Class to define RGB colors available for display functionalities.
static vpColor getColor(const unsigned int &i)
error that can be emitted by ViSP classes.
@ notImplementedError
Not implemented.
Error that can be emitted by the vpIoTools class and its derivatives.
@ invalidDirectoryName
Directory name is invalid.
@ cantCreateDirectory
Unable to create a directory.
@ cantGetenv
Cannot get environment variable value.
static Type minimum(const Type &a, const Type &b)
VISP_EXPORT float swapFloat(float f)
VISP_EXPORT uint32_t swap32bits(uint32_t val)
VISP_EXPORT double swapDouble(double d)
VISP_EXPORT uint16_t swap16bits(uint16_t val)