2 //-----------------------------------------------------------------------------
6 #include <ctype.h> // For isspace
9 //-----------------------------------------------------------------------------
13 //-----------------------------------------------------------------------------
17 * @param level debug level
20 gdcmDebug::gdcmDebug(int level) {
28 * @param Msg1 first message part
29 * @param Msg2 second message part
31 void gdcmDebug::Verbose(int Level, const char * Msg1, const char * Msg2) {
32 if (Level > DebugLevel)
34 std::cerr << Msg1 << ' ' << Msg2 << std::endl;
41 * @param Msg1 first message part
42 * @param Msg2 second message part
44 void gdcmDebug::Error( bool Test, const char * Msg1, const char * Msg2) {
47 std::cerr << Msg1 << ' ' << Msg2 << std::endl;
54 * @param Msg1 first message part
55 * @param Msg2 second message part
56 * @param Msg3 Third message part
58 void gdcmDebug::Error(const char* Msg1, const char* Msg2,
60 std::cerr << Msg1 << ' ' << Msg2 << ' ' << Msg3 << std::endl;
69 * @param Msg1 first message part
70 * @param Msg2 second message part
72 void gdcmDebug::Assert(int Level, bool Test,
73 const char * Msg1, const char * Msg2) {
74 if (Level > DebugLevel)
77 std::cerr << Msg1 << ' ' << Msg2 << std::endl;
83 * @param a return code
85 void gdcmDebug::Exit(int a) {
90 exit(a); // Found in #include <stdlib.h>
94 //-----------------------------------------------------------------------------
95 /// Pointer to a container, holding *all* the Dicom Dictionaries
96 gdcmDictSet *gdcmGlobal::Dicts = (gdcmDictSet *)0;
97 /// Pointer to a H table containing the 'Value Representations'
98 gdcmVR *gdcmGlobal::VR = (gdcmVR *)0;
99 /// Pointer to a H table containing the Transfer Syntax codes and their english description
100 gdcmTS *gdcmGlobal::TS = (gdcmTS *)0;
101 /// Pointer to a H table containing the Dicom Elements necessary to describe each part of a DICOMDIR
102 gdcmDicomDirElement *gdcmGlobal::ddElem = (gdcmDicomDirElement *)0;
108 * \ingroup gdcmGlobal
109 * \brief constructor : populates the
111 gdcmGlobal::gdcmGlobal(void) {
112 if (VR || TS || Dicts || ddElem)
113 dbg.Verbose(0, "gdcmGlobal::gdcmGlobal : VR or TS or Dicts already allocated");
114 Dicts = new gdcmDictSet();
117 ddElem = new gdcmDicomDirElement();
121 * \ingroup gdcmGlobal
122 * \brief canonical destructor
124 gdcmGlobal::~gdcmGlobal() {
131 gdcmVR *gdcmGlobal::GetVR(void) {
135 gdcmTS *gdcmGlobal::GetTS(void) {
139 gdcmDictSet *gdcmGlobal::GetDicts(void) {
143 gdcmDicomDirElement *gdcmGlobal::GetDicomDirElements(void) {
147 //-----------------------------------------------------------------------------
148 // Here are some usefull functions, belonging to NO class,
149 // dealing with strings, file names, etc
150 // that can be called from anywhere
151 // by whomsoever they can help.
152 //-----------------------------------------------------------------------------
154 // Because is not yet available in g++2.96
155 std::istream& eatwhite(std::istream& is) {
166 ///////////////////////////////////////////////////////////////////////////
167 // Because is not available in C++ (?)
168 void Tokenize (const std::string& str,
169 std::vector<std::string>& tokens,
170 const std::string& delimiters) {
171 std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
172 std::string::size_type pos = str.find_first_of (delimiters,lastPos);
173 while (std::string::npos != pos || std::string::npos != lastPos) {
174 tokens.push_back(str.substr(lastPos, pos - lastPos));
175 lastPos = str.find_first_not_of(delimiters, pos);
176 pos = str.find_first_of (delimiters, lastPos);
181 ///////////////////////////////////////////////////////////////////////////
183 * \brief to prevent a flashing screen when non-printable character
186 char *_cleanString(char *v) {
199 ///////////////////////////////////////////////////////////////////////////
201 * \brief to prevent a flashing screen when non-printable character
204 std::string _CreateCleanString(std::string s) {
207 for(int i=0;i<str.size();i++)
215 if(!isprint(s[str.size()-1]))
216 if(s[str.size()-1]==0)
217 str[str.size()-1]=' ';
222 ///////////////////////////////////////////////////////////////////////////
224 * \brief Add a SEPARATOR to the end of the name is necessary
227 void NormalizePath(std::string &name)
229 const char SEPARATOR_X = '/';
230 const char SEPARATOR_WIN = '\\';
231 const std::string SEPARATOR = "/";
232 int size=name.size();
233 if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN))
239 ///////////////////////////////////////////////////////////////////////////
241 * \brief Get the (directory) path from a full path file name
244 std::string GetPath(std::string &fullName)
246 int pos1=fullName.rfind("/");
247 int pos2=fullName.rfind("\\");
249 fullName.resize(pos1);
251 fullName.resize(pos2);
255 ///////////////////////////////////////////////////////////////////////////
257 * \brief Get the (last) name of a full path file name
260 std::string GetName(std::string &fullName)
262 int fin=fullName.length()-1;
263 char a =fullName.c_str()[fin];
264 if (a == '/' || a == '\\') {
268 for (int i=fin;i!=0;i--) {
269 if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\')
274 std::string lastName;
275 for (int j=deb;j<fin+1;j++)
276 lastName=lastName+fullName.c_str()[j];