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