00001
00002
00003 #include "gdcmUtil.h"
00004
00005 #include <stdio.h>
00006 #include <ctype.h>
00007 #include <string.h>
00008
00009
00010
00011 gdcmDebug dbg;
00012
00013
00014 gdcmDebug::gdcmDebug(int level) {
00015 DebugLevel = level;
00016 }
00017
00018 void gdcmDebug::Verbose(int Level, const char * Msg1, const char * Msg2) {
00019 if (Level > DebugLevel)
00020 return ;
00021 std::cerr << Msg1 << ' ' << Msg2 << std::endl;
00022 }
00023
00024 void gdcmDebug::Error( bool Test, const char * Msg1, const char * Msg2) {
00025 if (!Test)
00026 return;
00027 std::cerr << Msg1 << ' ' << Msg2 << std::endl;
00028 Exit(1);
00029 }
00030
00031 void gdcmDebug::Error(const char* Msg1, const char* Msg2,
00032 const char* Msg3) {
00033 std::cerr << Msg1 << ' ' << Msg2 << ' ' << Msg3 << std::endl;
00034 Exit(1);
00035 }
00036
00037 void gdcmDebug::Assert(int Level, bool Test,
00038 const char * Msg1, const char * Msg2) {
00039 if (Level > DebugLevel)
00040 return ;
00041 if (!Test)
00042 std::cerr << Msg1 << ' ' << Msg2 << std::endl;
00043 }
00044
00045 void gdcmDebug::Exit(int a) {
00046 #ifdef __GNUC__
00047 std::exit(a);
00048 #endif
00049 #ifdef _MSC_VER
00050 exit(a);
00051 #endif
00052 }
00053
00054
00055 gdcmDictSet *gdcmGlobal::Dicts = (gdcmDictSet *)0;
00056 gdcmVR *gdcmGlobal::VR = (gdcmVR *)0;
00057 gdcmTS *gdcmGlobal::TS = (gdcmTS *)0;
00058 gdcmDicomDirElement *gdcmGlobal::ddElem = (gdcmDicomDirElement *)0;
00059 gdcmGlobal gdcmGlob;
00060
00061 gdcmGlobal::gdcmGlobal(void) {
00062 if (VR || TS || Dicts)
00063 dbg.Verbose(0, "gdcmGlobal::gdcmGlobal : VR or TS or Dicts already allocated");
00064 Dicts = new gdcmDictSet();
00065 VR = new gdcmVR();
00066 TS = new gdcmTS();
00067 ddElem = new gdcmDicomDirElement();
00068 }
00069
00070 gdcmGlobal::~gdcmGlobal() {
00071 delete Dicts;
00072 delete VR;
00073 delete TS;
00074 delete ddElem;
00075 }
00076
00077 gdcmVR *gdcmGlobal::GetVR(void) {
00078 return VR;
00079 }
00080
00081 gdcmTS *gdcmGlobal::GetTS(void) {
00082 return TS;
00083 }
00084
00085 gdcmDictSet *gdcmGlobal::GetDicts(void) {
00086 return Dicts;
00087 }
00088
00089 gdcmDicomDirElement *gdcmGlobal::GetDicomDirElements(void) {
00090 return ddElem;
00091 }
00092
00093
00094
00095 std::istream& eatwhite(std::istream& is) {
00096 char c;
00097 while (is.get(c)) {
00098 if (!isspace(c)) {
00099 is.putback(c);
00100 break;
00101 }
00102 }
00103 return is;
00104 }
00105
00107
00108 void Tokenize (const std::string& str,
00109 std::vector<std::string>& tokens,
00110 const std::string& delimiters) {
00111 std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
00112 std::string::size_type pos = str.find_first_of (delimiters,lastPos);
00113 while (std::string::npos != pos || std::string::npos != lastPos) {
00114 tokens.push_back(str.substr(lastPos, pos - lastPos));
00115 lastPos = str.find_first_not_of(delimiters, pos);
00116 pos = str.find_first_of (delimiters, lastPos);
00117 }
00118 }
00119
00120
00122
00123 char *_cleanString(char *v) {
00124 char *d;
00125 int i, l;
00126 l = strlen(v);
00127 for (i=0,d=v;
00128 i<l ;
00129 i++,d++) {
00130 if (!isprint(*d))
00131 *d = '.';
00132 }
00133 return v;
00134 }
00135
00136
00138
00139 std::string _CreateCleanString(std::string s) {
00140 std::string str=s;
00141
00142 for(int i=0;i<str.size();i++)
00143 {
00144 if(!isprint(str[i]))
00145 str[i]='.';
00146 }
00147
00148
00149 if(str.size()>0)
00150 if(!isprint(s[str.size()-1]))
00151 if(s[str.size()-1]==0)
00152 str[str.size()-1]=' ';
00153
00154 return(str);
00155 }