2 //-----------------------------------------------------------------------------
6 #include <ctype.h> // For isspace
7 #include <string.h> // CLEANME: could this be only string ? Related to Win32 ?
11 * \brief Pointer to a container, holding _all_ the Dicom Dictionaries.
13 gdcmDictSet *gdcmGlobal::Dicts = (gdcmDictSet *)0;
17 * \brief Pointer to a hash table containing the 'Value Representations'.
19 gdcmVR *gdcmGlobal::VR = (gdcmVR *)0;
23 * \brief Pointer to a hash table containing the Transfer Syntax codes
24 * and their english description
26 gdcmTS *gdcmGlobal::TS = (gdcmTS *)0;
30 * \brief Pointer to the hash table containing the Dicom Elements
31 * necessary to describe each part of a DICOMDIR
33 gdcmDicomDirElement *gdcmGlobal::ddElem = (gdcmDicomDirElement *)0;
37 * \brief Global container
43 * \brief constructor : populates the various H Tables
45 gdcmGlobal::gdcmGlobal(void) {
46 if (VR || TS || Dicts || ddElem)
47 dbg.Verbose(0, "gdcmGlobal::gdcmGlobal : VR or TS or Dicts already allocated");
48 Dicts = new gdcmDictSet();
51 ddElem = new gdcmDicomDirElement();
56 * \brief canonical destructor
58 gdcmGlobal::~gdcmGlobal() {
66 * \brief returns a pointer to the 'Value Representation Table'
68 gdcmVR *gdcmGlobal::GetVR(void) {
73 * \brief returns a pointer to the 'Transfert Syntax Table'
75 gdcmTS *gdcmGlobal::GetTS(void) {
80 * \brief returns a pointer to Dictionaries Table
82 gdcmDictSet *gdcmGlobal::GetDicts(void) {
87 * \brief returns a pointer to the DicomDir related elements Table
89 gdcmDicomDirElement *gdcmGlobal::GetDicomDirElements(void) {
94 * \defgroup Globals Utility functions
95 * \brief Here are some utility functions, belonging to NO class,
96 * dealing with strings, file names... that can be called
97 * from anywhere by whomsoever they can help.
103 * \brief Because is not yet available in g++2.96
105 std::istream& eatwhite(std::istream& is) {
118 * \brief Because not available in C++ (?)
120 void Tokenize (const std::string& str,
121 std::vector<std::string>& tokens,
122 const std::string& delimiters) {
123 std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
124 std::string::size_type pos = str.find_first_of (delimiters,lastPos);
125 while (std::string::npos != pos || std::string::npos != lastPos) {
126 tokens.push_back(str.substr(lastPos, pos - lastPos));
127 lastPos = str.find_first_not_of(delimiters, pos);
128 pos = str.find_first_of (delimiters, lastPos);
134 * \brief Weed out a string from the non-printable characters (in order
135 * to avoid corrupting the terminal of invocation when printing)
136 * @param s string to remove non printable characters from
138 std::string CreateCleanString(std::string s) {
141 for(int i=0;i<str.size();i++)
148 if(!isprint(s[str.size()-1]))
149 if(s[str.size()-1]==0)
150 str[str.size()-1]=' ';
157 * \brief Add a SEPARATOR to the end of the name is necessary
158 * @param name file/directory name to normalize
160 void NormalizePath(std::string &name)
162 const char SEPARATOR_X = '/';
163 const char SEPARATOR_WIN = '\\';
164 const std::string SEPARATOR = "/";
165 int size=name.size();
167 if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN))
175 * \brief Get the (directory) path from a full path file name
176 * @param fullName file/directory name to extract Path from
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);
191 * \brief Get the (last) name of a full path file name
192 * @param fullName file/directory name to extract end name from
194 std::string GetName(std::string &fullName)
196 int fin=fullName.length()-1;
197 char a =fullName.c_str()[fin];
198 if (a == '/' || a == '\\') {
202 for (int i=fin;i!=0;i--) {
203 if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\')
208 std::string lastName;
209 for (int j=deb;j<fin+1;j++)
210 lastName=lastName+fullName.c_str()[j];