comparison Core/Toolbox.cpp @ 1397:704de8c30ff5

modularization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 01 Jun 2015 11:50:58 +0200
parents 60cc0ee61edb
children fe384a9d3b51
comparison
equal deleted inserted replaced
1396:ac4efabeb80c 1397:704de8c30ff5
33 #include "PrecompiledHeaders.h" 33 #include "PrecompiledHeaders.h"
34 #include "Toolbox.h" 34 #include "Toolbox.h"
35 35
36 #include "OrthancException.h" 36 #include "OrthancException.h"
37 37
38 #include <string>
38 #include <stdint.h> 39 #include <stdint.h>
39 #include <string.h> 40 #include <string.h>
40 #include <boost/filesystem.hpp> 41 #include <boost/filesystem.hpp>
41 #include <boost/filesystem/fstream.hpp> 42 #include <boost/filesystem/fstream.hpp>
42 #include <boost/date_time/posix_time/posix_time.hpp>
43 #include <boost/uuid/sha1.hpp> 43 #include <boost/uuid/sha1.hpp>
44 #include <boost/lexical_cast.hpp>
44 #include <algorithm> 45 #include <algorithm>
45 #include <ctype.h> 46 #include <ctype.h>
47
48 #if BOOST_HAS_DATE_TIME == 1
49 #include <boost/date_time/posix_time/posix_time.hpp>
50 #endif
51
52 #if BOOST_HAS_REGEX == 1
46 #include <boost/regex.hpp> 53 #include <boost/regex.hpp>
54 #endif
55
56 #if HAVE_GOOGLE_LOG == 1
47 #include <glog/logging.h> 57 #include <glog/logging.h>
58 #endif
48 59
49 #if defined(_WIN32) 60 #if defined(_WIN32)
50 #include <windows.h> 61 #include <windows.h>
51 #include <process.h> // For "_spawnvp()" 62 #include <process.h> // For "_spawnvp()"
52 #else 63 #else
697 } 708 }
698 709
699 return true; 710 return true;
700 } 711 }
701 712
713
714 #if BOOST_HAS_DATE_TIME == 1
702 std::string Toolbox::GetNowIsoString() 715 std::string Toolbox::GetNowIsoString()
703 { 716 {
704 boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); 717 boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
705 return boost::posix_time::to_iso_string(now); 718 return boost::posix_time::to_iso_string(now);
706 } 719 }
720 #endif
721
707 722
708 std::string Toolbox::StripSpaces(const std::string& source) 723 std::string Toolbox::StripSpaces(const std::string& source)
709 { 724 {
710 size_t first = 0; 725 size_t first = 0;
711 726
803 throw OrthancException(ErrorCode_NotImplemented); 818 throw OrthancException(ErrorCode_NotImplemented);
804 } 819 }
805 } 820 }
806 821
807 822
823 #if BOOST_HAS_REGEX == 1
808 std::string Toolbox::WildcardToRegularExpression(const std::string& source) 824 std::string Toolbox::WildcardToRegularExpression(const std::string& source)
809 { 825 {
810 // TODO - Speed up this with a regular expression 826 // TODO - Speed up this with a regular expression
811 827
812 std::string result = source; 828 std::string result = source;
830 boost::replace_all(result, "?", "."); 846 boost::replace_all(result, "?", ".");
831 boost::replace_all(result, "*", ".*"); 847 boost::replace_all(result, "*", ".*");
832 848
833 return result; 849 return result;
834 } 850 }
851 #endif
835 852
836 853
837 854
838 void Toolbox::TokenizeString(std::vector<std::string>& result, 855 void Toolbox::TokenizeString(std::vector<std::string>& result,
839 const std::string& value, 856 const std::string& value,
858 875
859 result.push_back(currentItem); 876 result.push_back(currentItem);
860 } 877 }
861 878
862 879
880 #if BOOST_HAS_REGEX == 1
863 void Toolbox::DecodeDataUriScheme(std::string& mime, 881 void Toolbox::DecodeDataUriScheme(std::string& mime,
864 std::string& content, 882 std::string& content,
865 const std::string& source) 883 const std::string& source)
866 { 884 {
867 boost::regex pattern("data:([^;]+);base64,([a-zA-Z0-9=+/]*)", 885 boost::regex pattern("data:([^;]+);base64,([a-zA-Z0-9=+/]*)",
876 else 894 else
877 { 895 {
878 throw OrthancException(ErrorCode_BadFileFormat); 896 throw OrthancException(ErrorCode_BadFileFormat);
879 } 897 }
880 } 898 }
881 899 #endif
882 900
883 void Toolbox::CreateDirectory(const std::string& path) 901
902 void Toolbox::MakeDirectory(const std::string& path)
884 { 903 {
885 if (boost::filesystem::exists(path)) 904 if (boost::filesystem::exists(path))
886 { 905 {
887 if (!boost::filesystem::is_directory(path)) 906 if (!boost::filesystem::is_directory(path))
888 { 907 {
1052 int pid = fork(); 1071 int pid = fork();
1053 1072
1054 if (pid == -1) 1073 if (pid == -1)
1055 { 1074 {
1056 // Error in fork() 1075 // Error in fork()
1076 #if HAVE_GOOGLE_LOG == 1
1057 LOG(ERROR) << "Cannot fork a child process"; 1077 LOG(ERROR) << "Cannot fork a child process";
1078 #endif
1079
1058 throw OrthancException(ErrorCode_SystemCommand); 1080 throw OrthancException(ErrorCode_SystemCommand);
1059 } 1081 }
1060 else if (pid == 0) 1082 else if (pid == 0)
1061 { 1083 {
1062 // Execute the system command in the child process 1084 // Execute the system command in the child process
1072 } 1094 }
1073 #endif 1095 #endif
1074 1096
1075 if (status != 0) 1097 if (status != 0)
1076 { 1098 {
1099 #if HAVE_GOOGLE_LOG == 1
1077 LOG(ERROR) << "System command failed with status code " << status; 1100 LOG(ERROR) << "System command failed with status code " << status;
1101 #endif
1102
1078 throw OrthancException(ErrorCode_SystemCommand); 1103 throw OrthancException(ErrorCode_SystemCommand);
1079 } 1104 }
1080 } 1105 }
1081 1106
1082 1107