]> Creatis software - gdcm.git/blob - src/gdcmUtil.cxx
* Memory link hunt (by using valgrind --leak-check=yes PrintHeader).
[gdcm.git] / src / gdcmUtil.cxx
1 // gdcmUtil.cxx
2
3 #include <ctype.h>   // For isspace
4 #include "gdcmUtil.h"
5
6 // Library globals.
7 gdcmDebug dbg;
8 gdcmVR * gdcmGlobal::VR = new gdcmVR();
9
10 gdcmDebug::gdcmDebug(int level) {
11         DebugLevel = level;
12 }
13
14 void gdcmDebug::Verbose(int Level, const char * Msg1, const char * Msg2) {
15         if (Level > DebugLevel)
16                 return ;
17         cerr << Msg1 << ' ' << Msg2 << '\n';
18 }
19
20 void gdcmDebug::Assert(int Level, bool Test,
21                  const char * Msg1, const char * Msg2) {
22         if (Level > DebugLevel)
23                 return ;
24         if (!Test)
25                 cerr << Msg1 << ' ' << Msg2 << '\n';
26 }
27
28 void gdcmDebug::Error( bool Test, const char * Msg1, const char * Msg2) {
29         if (!Test)
30                 return;
31         std::cerr << Msg1 << ' ' << Msg2 << '\n';
32         Exit(1);
33 }
34
35 void gdcmDebug::Error(const char* Msg1, const char* Msg2,
36                       const char* Msg3) {
37         std::cerr << Msg1 << ' ' << Msg2 << ' ' << Msg3 << '\n';
38         Exit(1);
39 }
40
41 void gdcmDebug::Exit(int a) {
42 #ifdef __GNUC__
43         std::exit(a);
44 #endif
45 #ifdef _MSC_VER
46         exit(a);    // Found in #include <stdlib.h>
47 #endif
48 }
49
50 ///////////////////////////////////////////////////////////////////////////
51 gdcmGlobal::gdcmGlobal(void) {
52 }
53
54 gdcmGlobal::~gdcmGlobal(void) {
55    delete VR;
56 }
57
58 gdcmVR * gdcmGlobal::GetVR(void) {
59    return VR;
60 }
61
62 ///////////////////////////////////////////////////////////////////////////
63 // Because is not yet available in g++2.96
64 istream& eatwhite(istream& is) {
65         char c;
66         while (is.get(c)) {
67                 if (!isspace(c)) {
68                         is.putback(c);
69                         break;
70                 }
71         }
72         return is;
73 }
74
75 void Tokenize (const string& str,
76                vector<string>& tokens,
77                const string& delimiters) {
78    string::size_type lastPos = str.find_first_not_of(delimiters,0);
79    string::size_type pos     = str.find_first_of(delimiters,lastPos);
80    while (string::npos != pos || string::npos != lastPos) {
81       tokens.push_back(str.substr(lastPos, pos - lastPos));
82       lastPos = str.find_first_not_of(delimiters, pos);
83       pos = str.find_first_of(delimiters, lastPos);
84    }
85 }