55 #include <sys/types.h>
56 #include <visp3/core/vpDebug.h>
57 #include <visp3/core/vpIoException.h>
58 #include <visp3/core/vpIoTools.h>
59 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
74 #if defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin)
75 #include <TargetConditionals.h>
80 # define PATH_MAX _MAX_PATH
82 # define PATH_MAX 1024
88 #if defined(__GLIBC__) || (defined(__GNUC__) && !defined(__llvm__) && !defined(__MINGW32__) && defined(__BYTE_ORDER__))
90 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
91 #define VISP_LITTLE_ENDIAN
92 #elif (__BYTE_ORDER == __BIG_ENDIAN)
93 #define VISP_BIG_ENDIAN
94 #elif (__BYTE_ORDER == __PDP_ENDIAN)
96 #define VISP_PDP_ENDIAN
99 #error Unknown machine endianness detected.
101 #elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) || defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
102 #define VISP_BIG_ENDIAN
103 #elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) || defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
104 #define VISP_LITTLE_ENDIAN
105 #elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || \
106 defined(__hpux) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
108 #define VISP_BIG_ENDIAN
109 #elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || defined(_M_IX86) || \
110 defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || \
111 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(__ANDROID__)
114 #define VISP_LITTLE_ENDIAN
115 #elif defined(WINRT) // For UWP
117 #define VISP_LITTLE_ENDIAN
119 #error Cannot detect host machine endianness.
132 #if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
133 #if (TARGET_OS_IOS == 0) && !defined(__ANDROID__)
134 void replaceAll(std::string &str,
const std::string &search,
const std::string &replace)
136 size_t start_pos = 0;
137 while ((start_pos = str.find(search, start_pos)) != std::string::npos) {
138 str.replace(start_pos, search.length(), replace);
139 start_pos += replace.length();
146 #ifdef VISP_BIG_ENDIAN
149 uint16_t swap16bits(
const uint16_t val)
151 return (((val >> 8) & 0x00FF) | ((val << 8) & 0xFF00));
156 uint32_t swap32bits(
const uint32_t val)
158 return (((val >> 24) & 0x000000FF) | ((val >> 8) & 0x0000FF00) | ((val << 8) & 0x00FF0000) |
159 ((val << 24) & 0xFF000000));
164 float swapFloat(
float f)
172 dat2.b[0] = dat1.b[3];
173 dat2.b[1] = dat1.b[2];
174 dat2.b[2] = dat1.b[1];
175 dat2.b[3] = dat1.b[0];
181 double swapDouble(
double d)
189 dat2.b[0] = dat1.b[7];
190 dat2.b[1] = dat1.b[6];
191 dat2.b[2] = dat1.b[5];
192 dat2.b[3] = dat1.b[4];
193 dat2.b[4] = dat1.b[3];
194 dat2.b[5] = dat1.b[2];
195 dat2.b[6] = dat1.b[1];
196 dat2.b[7] = dat1.b[0];
201 std::string <rim(std::string &s)
203 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
204 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](
int c) { return !std::isspace(c); }));
206 s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
211 std::string &rtrim(std::string &s)
213 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98
214 s.erase(std::find_if(s.rbegin(), s.rend(), [](
int c) { return !std::isspace(c); }).base(), s.end());
216 s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
227 static std::string build_info =
228 #include "version_string.inc"
274 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
276 char *_username =
::getenv(
"LOGNAME");
278 username =
"unknown";
281 username = _username;
283 #elif defined(_WIN32)
284 #if (!defined(WINRT))
285 unsigned int info_buffer_size = 1024;
286 TCHAR *infoBuf =
new TCHAR[info_buffer_size];
287 DWORD bufCharCount = (DWORD)info_buffer_size;
289 if (!GetUserName(infoBuf, &bufCharCount)) {
290 username =
"unknown";
297 username =
"unknown";
300 username =
"unknown";
320 std::string username;
357 #if defined(_WIN32) && defined(WINRT)
359 "implemented on Universal Windows Platform"));
363 char *_value =
::getenv(env.c_str());
382 void vpIoTools::getVersion(
const std::string &version,
unsigned int &major,
unsigned int &minor,
unsigned int &patch)
384 if (version.size() == 0) {
389 size_t major_pos = version.find(
'.');
390 std::string major_str = version.substr(0, major_pos);
391 major =
static_cast<unsigned>(atoi(major_str.c_str()));
393 if (major_pos != std::string::npos) {
394 size_t minor_pos = version.find(
'.', major_pos + 1);
395 std::string minor_str = version.substr(major_pos + 1, (minor_pos - (major_pos + 1)));
396 minor =
static_cast<unsigned>(atoi(minor_str.c_str()));
398 if (minor_pos != std::string::npos) {
399 std::string patch_str = version.substr(minor_pos + 1);
400 patch =
static_cast<unsigned>(atoi(patch_str.c_str()));
424 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
426 #elif defined(_WIN32) && defined(__MINGW32__)
428 #elif defined(_WIN32)
432 if (dirname.empty()) {
436 std::string _dirname =
path(dirname);
438 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
439 if (stat(_dirname.c_str(), &stbuf) != 0)
440 #elif defined(_WIN32) && defined(__MINGW32__)
445 _dirname = _dirname.substr(0, _dirname.size() - 1);
446 if (stat(_dirname.c_str(), &stbuf) != 0)
447 #elif defined(_WIN32)
448 if (_stat(_dirname.c_str(), &stbuf) != 0)
453 #if defined(_WIN32) || (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
454 if ((stbuf.st_mode & S_IFDIR) == 0)
459 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
460 if ((stbuf.st_mode & S_IWUSR) == 0)
461 #elif defined(_WIN32)
462 if ((stbuf.st_mode & S_IWRITE) == 0)
484 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
487 std::string _filename =
path(fifofilename);
488 if (stat(_filename.c_str(), &stbuf) != 0) {
491 if ((stbuf.st_mode & S_IFIFO) == 0) {
494 if ((stbuf.st_mode & S_IRUSR) == 0)
500 #elif defined(_WIN32)
506 #ifndef DOXYGEN_SHOULD_SKIP_THIS
509 int vpIoTools::mkdir_p(
const char *path,
int mode)
512 const size_t len = strlen(
path);
513 char _path[PATH_MAX];
516 std::fill(_path, _path + PATH_MAX, 0);
519 if (len >
sizeof(_path) - 1) {
520 errno = ENAMETOOLONG;
527 for (
char *p = _path + 1; *p; p++) {
532 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
533 if (mkdir(_path,
static_cast<mode_t
>(mode)) != 0)
534 #elif defined(_WIN32)
546 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
547 if (mkdir(_path,
static_cast<mode_t
>(mode)) != 0)
548 #elif defined(_WIN32)
549 if (_mkdir(_path) != 0)
558 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
574 #if ((!defined(__unix__) && !defined(__unix) && (!defined(__APPLE__) || !defined(__MACH__)))) && !defined(_WIN32)
575 std::cerr <<
"Unsupported platform for vpIoTools::makeDirectory()!" << std::endl;
579 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
581 #elif defined(_WIN32) && defined(__MINGW32__)
583 #elif defined(_WIN32)
587 if (dirname.empty()) {
591 std::string _dirname =
path(dirname);
593 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
594 if (stat(_dirname.c_str(), &stbuf) != 0)
595 #elif defined(_WIN32) && defined(__MINGW32__)
596 if (stat(_dirname.c_str(), &stbuf) != 0)
597 #elif defined(_WIN32)
598 if (_stat(_dirname.c_str(), &stbuf) != 0)
601 if (vpIoTools::mkdir_p(_dirname.c_str(), 0755) != 0) {
625 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
630 "Unable to create fifo file. '%s' is an existing directory.", fifoname.c_str()));
643 else if (mkfifo(fifoname.c_str(), 0666) < 0) {
646 #elif defined(_WIN32)
673 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
675 std::string dirname_cpy = std::string(dirname);
677 std::string correctEnding =
"XXXXXX";
679 size_t endingLength = correctEnding.length();
680 size_t dirNameLength = dirname_cpy.length();
684 if (endingLength > dirNameLength) {
686 "Unable to create temp directory '%s'. It should end with XXXXXX.", dirname_cpy.c_str()));
689 if (dirname.compare(dirNameLength - endingLength, endingLength, correctEnding) != 0) {
691 "Unable to create temp directory '%s'. It should end with XXXXXX.", dirname_cpy.c_str()));
696 if (dirname_cpy.at(dirname_cpy.length() - 1) !=
'/') {
697 dirname_cpy = dirname_cpy +
"/";
699 dirname_cpy = dirname_cpy +
"XXXXXX";
701 char *dirname_char =
new char[dirname_cpy.length() + 1];
702 strcpy(dirname_char, dirname_cpy.c_str());
704 char *computedDirname = mkdtemp(dirname_char);
706 if (!computedDirname) {
707 delete[] dirname_char;
711 std::string res(computedDirname);
712 delete[] dirname_char;
714 #elif defined(_WIN32)
732 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
734 #elif defined(_WIN32)
738 if (filename.empty()) {
742 std::string _filename =
path(filename);
743 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
744 if (stat(_filename.c_str(), &stbuf) != 0)
745 #elif defined(_WIN32)
746 if (_stat(_filename.c_str(), &stbuf) != 0)
751 if ((stbuf.st_mode & S_IFREG) == 0) {
754 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
755 if ((stbuf.st_mode & S_IRUSR) == 0)
756 #elif defined(_WIN32)
757 if ((stbuf.st_mode & S_IREAD) == 0)
777 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
778 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
780 char cmd[FILENAME_MAX];
782 sprintf(cmd,
"cp -p %s %s", src.c_str(), dst.c_str());
791 #elif defined(_WIN32)
792 #if (!defined(WINRT))
793 char cmd[FILENAME_MAX];
797 sprintf(cmd,
"copy %s %s", src_.c_str(), dst_.c_str());
805 src.c_str(), dst.c_str()));
810 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
811 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
813 char cmd[FILENAME_MAX];
815 sprintf(cmd,
"cp -p -r %s %s", src.c_str(), dst.c_str());
824 #elif defined(_WIN32)
825 #if (!defined(WINRT))
826 char cmd[FILENAME_MAX];
830 sprintf(cmd,
"copy %s %s", src_.c_str(), dst_.c_str());
838 src.c_str(), dst.c_str()));
842 std::cout <<
"Cannot copy: " << src <<
" in " << dst << std::endl;
859 #
if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
864 if (::
remove(file_or_dir.c_str()) != 0)
870 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
871 #if TARGET_OS_IOS == 0 // The following code is not working on iOS since
873 char cmd[FILENAME_MAX];
874 sprintf(cmd,
"rm -rf \"%s\"", file_or_dir.c_str());
875 int ret = system(cmd);
883 #elif defined(_WIN32)
884 #if (!defined(WINRT))
885 char cmd[FILENAME_MAX];
887 sprintf(cmd,
"rmdir /S /Q %s", file_or_dir_.c_str());
888 int ret = system(cmd);
895 file_or_dir.c_str()));
899 std::cout <<
"Cannot remove: " << file_or_dir << std::endl;
915 if (::
rename(oldfilename.c_str(), newfilename.c_str()) != 0)
933 std::string
path(pathname);
936 for (
unsigned int i = 0; i <
path.length(); i++)
939 #elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
940 for (
unsigned int i = 0; i <
path.length(); i++)
943 #if TARGET_OS_IOS == 0 // The following code is not working on iOS and android since
948 wordexp_t exp_result;
951 replaceAll(
path,
"'",
"'\\''");
953 wordexp(std::string(
"'" +
path +
"'").c_str(), &exp_result, 0);
954 path = exp_result.we_wordc == 1 ? exp_result.we_wordv[0] :
"";
955 wordfree(&exp_result);
976 std::ifstream confContent(
configFile.c_str(), std::ios::in);
978 if (confContent.is_open()) {
979 std::string line, var, val;
982 std::string stop[3] = {
" ",
"\t",
"#"};
983 while (std::getline(confContent, line)) {
984 if ((line.compare(0, 1,
"#") != 0) && (line.size() > 2)) {
987 k =
static_cast<unsigned long>(line.find(
" "));
988 var = line.substr(0, k);
991 for (
unsigned i = 0; i < 3; ++i)
992 c =
vpMath::minimum(c,
static_cast<int>(line.find(stop[i],
static_cast<size_t>(k) +
static_cast<size_t>(1))));
994 c =
static_cast<int>(line.size());
995 long unsigned int c_ =
static_cast<long unsigned int>(c);
996 val = line.substr(
static_cast<size_t>(k) +
static_cast<size_t>(1),
static_cast<size_t>(c_) -
static_cast<size_t>(k) -
static_cast<size_t>(1));
1003 confContent.close();
1021 for (
unsigned int k = 0; k <
configVars.size() && found ==
false; ++k) {
1024 value =
static_cast<float>(M_PI);
1026 value =
static_cast<float>(M_PI / 2.0);
1028 value =
static_cast<float>(-M_PI / 2.0);
1030 value =
static_cast<float>(atof(
configValues[k].c_str()));
1035 std::cout << var <<
" not found in config file" << std::endl;
1049 for (
unsigned int k = 0; k <
configVars.size() && found ==
false; ++k) {
1063 std::cout << var <<
" not found in config file" << std::endl;
1078 for (
unsigned int k = 0; k <
configVars.size() && found ==
false; ++k) {
1085 std::cout << var <<
" not found in config file" << std::endl;
1101 value =
static_cast<unsigned int>(v);
1148 for (
unsigned int k = 0; k <
configVars.size() && found ==
false; ++k) {
1155 std::cout << var <<
" not found in config file" << std::endl;
1173 const unsigned int &nRows)
1177 for (
unsigned int k = 0; k <
configVars.size() && found ==
false; ++k) {
1181 if (nCols != 0 && nRows != 0)
1182 value.
resize(nRows, nCols);
1183 size_t ind = 0, ind2;
1184 for (
unsigned int i = 0; i < value.
getRows(); ++i)
1185 for (
unsigned int j = 0; j < value.
getCols(); ++j) {
1188 if (nb.compare(
"PI") == 0)
1190 else if (nb.compare(
"PI/2") == 0)
1191 value[i][j] = M_PI / 2;
1192 else if (nb.compare(
"-PI/2") == 0)
1193 value[i][j] = -M_PI / 2;
1195 value[i][j] = atof(nb.c_str());
1201 std::cout << var <<
" not found in config file" << std::endl;
1219 else if (strFalse !=
"")
1234 if (std::fabs(val) < std::numeric_limits<double>::epsilon()) {
1236 sprintf(valC,
"%.3f", val);
1237 std::string valS(valC);
1294 std::string data_path;
1295 std::string file_to_test(
"mbt/cube.cao");
1296 std::string filename;
1297 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1299 data_path =
"/usr/share/visp-images-data/ViSP-images";
1300 filename = data_path +
"/" + file_to_test;
1303 data_path =
"/usr/share/visp-images-data/visp-images";
1304 filename = data_path +
"/" + file_to_test;
1311 filename = data_path +
"/" + file_to_test;
1315 filename = data_path +
"/" + file_to_test;
1319 filename = data_path +
"/" + file_to_test;
1364 std::string sep =
"\\";
1365 std::string altsep =
"/";
1366 std::string extsep =
".";
1369 std::string sep =
"/";
1370 std::string altsep =
"";
1371 std::string extsep =
".";
1404 int sepIndex =
static_cast<int>(pathname.rfind(sep));
1405 if (!altsep.empty()) {
1406 int altsepIndex =
static_cast<int>(pathname.rfind(altsep));
1407 sepIndex = ((std::max))(sepIndex, altsepIndex);
1410 size_t dotIndex = pathname.rfind(extsep);
1411 if (dotIndex != std::string::npos) {
1413 size_t npos = std::string::npos;
1414 if ((sepIndex !=
static_cast<int>(npos) &&
static_cast<int>(dotIndex) > sepIndex) || sepIndex ==
static_cast<int>(npos)) {
1415 if (sepIndex ==
static_cast<int>(npos)) {
1417 std::cout <<
"Debug sepIndex: " << sepIndex << std::endl;
1419 size_t filenameIndex =
static_cast<size_t>(sepIndex) +
static_cast<size_t>(1);
1421 while (filenameIndex < dotIndex) {
1422 if (pathname.compare(filenameIndex, 1, extsep) != 0) {
1423 return pathname.substr(dotIndex);
1440 if (pathname.size() > 0) {
1444 if (index != std::string::npos) {
1445 return convertedPathname.substr(index + 1);
1448 return convertedPathname;
1463 size_t found = name.find_last_of(
".");
1464 std::string name_we = name.substr(0, found);
1475 if (pathname.size() > 0) {
1479 if (index != std::string::npos) {
1480 return convertedPathname.substr(0, index);
1498 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1499 std::string real_path_str = pathname;
1500 char *real_path = realpath(pathname.c_str(), NULL);
1503 real_path_str = real_path;
1506 return real_path_str;
1507 #elif defined(_WIN32)
1508 #if (!defined(WINRT))
1509 std::string real_path_str = pathname;
1511 TCHAR buffer[4096] = TEXT(
"");
1513 retval = GetFullPathName(pathname.c_str(), 4096, buffer, 0);
1515 real_path_str = buffer;
1517 return real_path_str;
1520 "Cannot get absolute path of %s: not implemented on "
1521 "Universal Windows Platform",
1539 if (child.size() == 0 && parent.size() == 0) {
1543 if (child.size() == 0) {
1547 if (parent.size() == 0) {
1554 std::stringstream ss;
1556 std::string stringSeparator;
1557 ss >> stringSeparator;
1559 std::string lastConvertedParentChar = convertedParent.substr(convertedParent.size() - 1);
1560 std::string firstConvertedChildChar = convertedChild.substr(0, 1);
1562 if (lastConvertedParentChar == stringSeparator) {
1563 convertedParent = convertedParent.substr(0, convertedParent.size() - 1);
1566 if (firstConvertedChildChar == stringSeparator) {
1567 convertedChild = convertedChild.substr(1);
1592 return path.size() > 0 && (
path.substr(0, 1) ==
"/" ||
path.substr(0, 1) ==
"\\");
1612 return (path1_normalize == path2_normalize);
1675 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
1676 return std::pair<std::string, std::string>(
"", pathname);
1678 const std::string sep =
"\\";
1679 const std::string sepsep =
"\\\\";
1680 const std::string altsep =
"/";
1682 if (pathname.size() > 1) {
1683 std::string normPathname = pathname;
1684 std::replace(normPathname.begin(), normPathname.end(), *altsep.c_str(), *sep.c_str());
1686 if (normPathname.substr(0, 2) == sepsep && normPathname.substr(2, 1) != sep) {
1691 size_t index = normPathname.find(sep, 2);
1692 if (index == std::string::npos) {
1693 return std::pair<std::string, std::string>(
"", pathname);
1696 size_t index2 = normPathname.find(sep, index + 1);
1699 if (index2 == index + 1) {
1700 return std::pair<std::string, std::string>(
"", pathname);
1703 if (index2 == std::string::npos) {
1704 index2 = pathname.size();
1707 return std::pair<std::string, std::string>(pathname.substr(0, index2), pathname.substr(index2));
1710 if (normPathname[1] ==
':') {
1711 return std::pair<std::string, std::string>(pathname.substr(0, 2), pathname.substr(2));
1715 return std::pair<std::string, std::string>(
"", pathname);
1769 size_t startIndex = 0;
1771 std::string chainToSplit = chain;
1772 std::vector<std::string> subChain;
1773 size_t sepIndex = chainToSplit.find(sep);
1775 while (sepIndex != std::string::npos) {
1776 std::string sub = chainToSplit.substr(startIndex, sepIndex);
1778 subChain.push_back(sub);
1779 chainToSplit = chainToSplit.substr(sepIndex + 1, chain.size() - 1);
1781 sepIndex = chainToSplit.find(sep);
1783 if (!chainToSplit.empty())
1784 subChain.push_back(chainToSplit);
1802 std::string dirName =
path(pathname);
1804 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
1806 std::vector<std::string> files;
1807 struct dirent **list = NULL;
1808 int filesCount = scandir(dirName.c_str(), &list, NULL, NULL);
1809 if (filesCount == -1) {
1812 for (
int i = 0; i < filesCount; i++) {
1813 std::string fileName = list[i]->d_name;
1814 if (fileName !=
"." && fileName !=
"..") {
1815 files.push_back(fileName);
1820 std::sort(files.begin(), files.end());
1823 #elif defined(_WIN32)
1824 #if (!defined(WINRT))
1826 std::vector<std::string> files;
1827 std::string fileMask = dirName;
1828 fileMask.append(
"\\*");
1829 WIN32_FIND_DATA FindFileData;
1830 HANDLE hFind = FindFirstFile(fileMask.c_str(), &FindFileData);
1832 if (HandleToLong(&hFind) == ERROR_FILE_NOT_FOUND) {
1835 if (hFind == INVALID_HANDLE_VALUE) {
1839 std::string fileName = FindFileData.cFileName;
1840 if (fileName !=
"." && fileName !=
"..") {
1841 files.push_back(fileName);
1843 }
while (FindNextFile(hFind, &FindFileData));
1845 std::sort(files.begin(), files.end());
1850 "Cannot read files of directory %s: not implemented on "
1851 "Universal Windows Platform",
1862 file.read((
char *)(&short_value),
sizeof(short_value));
1864 #ifdef VISP_BIG_ENDIAN
1866 short_value = swap16bits((uint16_t)short_value);
1875 file.read((
char *)(&ushort_value),
sizeof(ushort_value));
1877 #ifdef VISP_BIG_ENDIAN
1879 ushort_value = swap16bits(ushort_value);
1888 file.read((
char *)(&int_value),
sizeof(int_value));
1890 #ifdef VISP_BIG_ENDIAN
1892 int_value = swap32bits((uint32_t)int_value);
1901 file.read((
char *)(&uint_value),
sizeof(uint_value));
1903 #ifdef VISP_BIG_ENDIAN
1905 uint_value = swap32bits(uint_value);
1914 file.read((
char *)(&float_value),
sizeof(float_value));
1916 #ifdef VISP_BIG_ENDIAN
1918 float_value = swapFloat(float_value);
1927 file.read((
char *)(&double_value),
sizeof(double_value));
1929 #ifdef VISP_BIG_ENDIAN
1931 double_value = swapDouble(double_value);
1940 #ifdef VISP_BIG_ENDIAN
1942 uint16_t swap_short = swap16bits((uint16_t)short_value);
1943 file.write((
char *)(&swap_short),
sizeof(swap_short));
1945 file.write((
char *)(&short_value),
sizeof(short_value));
1954 #ifdef VISP_BIG_ENDIAN
1956 uint16_t swap_ushort = swap16bits(ushort_value);
1957 file.write((
char *)(&swap_ushort),
sizeof(swap_ushort));
1959 file.write((
char *)(&ushort_value),
sizeof(ushort_value));
1968 #ifdef VISP_BIG_ENDIAN
1970 uint32_t swap_int = swap32bits((uint32_t)int_value);
1971 file.write((
char *)(&swap_int),
sizeof(swap_int));
1973 file.write((
char *)(&int_value),
sizeof(int_value));
1982 #ifdef VISP_BIG_ENDIAN
1984 uint32_t swap_int = swap32bits(uint_value);
1985 file.write((
char *)(&swap_int),
sizeof(swap_int));
1987 file.write((
char *)(&uint_value),
sizeof(uint_value));
1996 #ifdef VISP_BIG_ENDIAN
1998 float swap_float = swapFloat(float_value);
1999 file.write((
char *)(&swap_float),
sizeof(swap_float));
2001 file.write((
char *)(&float_value),
sizeof(float_value));
2010 #ifdef VISP_BIG_ENDIAN
2012 double swap_double = swapDouble(double_value);
2013 file.write((
char *)(&swap_double),
sizeof(swap_double));
2015 file.write((
char *)(&double_value),
sizeof(double_value));
2021 std::transform(input.begin(), input.end(), input.begin(), ::tolower);
2022 std::istringstream is(input);
2026 is >> (input.size() > 1 ? std::boolalpha : std::noboolalpha) >> b;
2035 return ltrim(rtrim(s));