]> 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.11 2003/05/21 16:26:28 regrain Exp $
2
3 #include <ctype.h>   // For isspace
4 #include "gdcmUtil.h"
5 using namespace std;
6
7 // Library globals.
8 gdcmDebug dbg;
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 gdcmVR      * gdcmGlobal::VR    = (gdcmVR*)0;
52 gdcmDictSet * gdcmGlobal::Dicts = (gdcmDictSet*)0;
53 gdcmGlobal gdcmGlob;
54
55 gdcmGlobal::gdcmGlobal(void) {
56    if (VR || Dicts)
57       dbg.Verbose(0, "gdcmGlobal::gdcmGlobal: VR or Dicts allready allocated");
58    VR = new gdcmVR();
59    Dicts = new gdcmDictSet();
60 }
61
62 gdcmGlobal::~gdcmGlobal() {
63    delete VR;
64    delete Dicts;
65 }
66
67 gdcmVR * gdcmGlobal::GetVR(void) {
68    return VR;
69 }
70
71 gdcmDictSet * gdcmGlobal::GetDicts(void) {
72    return Dicts;
73 }
74
75 ///////////////////////////////////////////////////////////////////////////
76 // Because is not yet available in g++2.96
77 istream& eatwhite(istream& is) {
78         char c;
79         while (is.get(c)) {
80                 if (!isspace(c)) {
81                         is.putback(c);
82                         break;
83                 }
84         }
85         return is;
86 }
87
88 void Tokenize (const string& str,
89                vector<string>& tokens,
90                const string& delimiters) {
91    string::size_type lastPos = str.find_first_not_of(delimiters,0);
92    string::size_type pos     = str.find_first_of(delimiters,lastPos);
93    while (string::npos != pos || string::npos != lastPos) {
94       tokens.push_back(str.substr(lastPos, pos - lastPos));
95       lastPos = str.find_first_not_of(delimiters, pos);
96       pos = str.find_first_of(delimiters, lastPos);
97    }
98 }