2 //-----------------------------------------------------------------------------
6 #include <ctype.h> // For isspace
9 //-----------------------------------------------------------------------------
13 //-----------------------------------------------------------------------------
14 gdcmDebug::gdcmDebug(int level) {
18 void gdcmDebug::Verbose(int Level, const char * Msg1, const char * Msg2) {
19 if (Level > DebugLevel)
21 std::cerr << Msg1 << ' ' << Msg2 << std::endl;
24 void gdcmDebug::Error( bool Test, const char * Msg1, const char * Msg2) {
27 std::cerr << Msg1 << ' ' << Msg2 << std::endl;
31 void gdcmDebug::Error(const char* Msg1, const char* Msg2,
33 std::cerr << Msg1 << ' ' << Msg2 << ' ' << Msg3 << std::endl;
37 void gdcmDebug::Assert(int Level, bool Test,
38 const char * Msg1, const char * Msg2) {
39 if (Level > DebugLevel)
42 std::cerr << Msg1 << ' ' << Msg2 << std::endl;
45 void gdcmDebug::Exit(int a) {
50 exit(a); // Found in #include <stdlib.h>
54 //-----------------------------------------------------------------------------
55 gdcmDictSet *gdcmGlobal::Dicts = (gdcmDictSet *)0;
56 gdcmVR *gdcmGlobal::VR = (gdcmVR *)0;
57 gdcmTS *gdcmGlobal::TS = (gdcmTS *)0;
58 gdcmDicomDirElement *gdcmGlobal::ddElem = (gdcmDicomDirElement *)0;
61 gdcmGlobal::gdcmGlobal(void) {
62 if (VR || TS || Dicts || ddElem)
63 dbg.Verbose(0, "gdcmGlobal::gdcmGlobal : VR or TS or Dicts already allocated");
64 Dicts = new gdcmDictSet();
67 ddElem = new gdcmDicomDirElement();
70 gdcmGlobal::~gdcmGlobal() {
77 gdcmVR *gdcmGlobal::GetVR(void) {
81 gdcmTS *gdcmGlobal::GetTS(void) {
85 gdcmDictSet *gdcmGlobal::GetDicts(void) {
89 gdcmDicomDirElement *gdcmGlobal::GetDicomDirElements(void) {
93 //-----------------------------------------------------------------------------
94 // Because is not yet available in g++2.96
95 std::istream& eatwhite(std::istream& is) {
106 ///////////////////////////////////////////////////////////////////////////
107 // Because is not available in C++ (?)
108 void Tokenize (const std::string& str,
109 std::vector<std::string>& tokens,
110 const std::string& delimiters) {
111 std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
112 std::string::size_type pos = str.find_first_of (delimiters,lastPos);
113 while (std::string::npos != pos || std::string::npos != lastPos) {
114 tokens.push_back(str.substr(lastPos, pos - lastPos));
115 lastPos = str.find_first_not_of(delimiters, pos);
116 pos = str.find_first_of (delimiters, lastPos);
121 ///////////////////////////////////////////////////////////////////////////
122 // to prevent a flashing screen when non-printable character
123 char *_cleanString(char *v) {
137 ///////////////////////////////////////////////////////////////////////////
138 // to prevent a flashing screen when non-printable character
139 std::string _CreateCleanString(std::string s) {
142 for(int i=0;i<str.size();i++)
150 if(!isprint(s[str.size()-1]))
151 if(s[str.size()-1]==0)
152 str[str.size()-1]=' ';
157 ///////////////////////////////////////////////////////////////////////////
159 * \brief Add a SEPARATOR to the end of the name is necessary
162 void NormalizePath(std::string &name)
164 const char SEPARATOR_X = '/';
165 const char SEPARATOR_WIN = '\\';
166 const std::string SEPARATOR = "/";
167 int size=name.size();
168 if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN))
174 ///////////////////////////////////////////////////////////////////////////
176 * \brief Get the (directory) path from a full path file name
178 std::string GetPath(std::string fullName)
180 int pos1=fullName.rfind("/");
181 int pos2=fullName.rfind("\\");
183 fullName.resize(pos1);
185 fullName.resize(pos2);
189 ///////////////////////////////////////////////////////////////////////////
191 * \brief Get the (last) name of a full path file name
193 std::string GetName(std::string fullName)
195 int fin=fullName.length()-1;
196 char a =fullName.c_str()[fin];
197 if (a == '/' || a == '\\') {
201 for (int i=fin;i!=0;i--) {
202 if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\')
206 std::string lastName;
207 for (int i=deb;i<fin+1;i++)
208 lastName=lastName+fullName.c_str()[i];