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
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() {
65 gdcmVR *gdcmGlobal::GetVR(void) {
69 gdcmTS *gdcmGlobal::GetTS(void) {
73 gdcmDictSet *gdcmGlobal::GetDicts(void) {
77 gdcmDicomDirElement *gdcmGlobal::GetDicomDirElements(void) {
82 * \defgroup Globals Utility functions
83 * \brief Here are some utility functions, belonging to NO class,
84 * dealing with strings, file names... that can be called
85 * from anywhere by whomsoever they can help.
90 * \brief Because is not yet available in g++2.96
92 std::istream& eatwhite(std::istream& is) {
105 * \brief Because not available in C++ (?)
107 void Tokenize (const std::string& str,
108 std::vector<std::string>& tokens,
109 const std::string& delimiters) {
110 std::string::size_type lastPos = str.find_first_not_of(delimiters,0);
111 std::string::size_type pos = str.find_first_of (delimiters,lastPos);
112 while (std::string::npos != pos || std::string::npos != lastPos) {
113 tokens.push_back(str.substr(lastPos, pos - lastPos));
114 lastPos = str.find_first_not_of(delimiters, pos);
115 pos = str.find_first_of (delimiters, lastPos);
121 * \brief Weed out a string from the non-printable characters (in order
122 * to avoid corrupting the terminal of invocation when printing)
123 * @param v characters array to remove non printable characters from
125 char *_cleanString(char *v) {
140 * \brief to prevent a flashing screen when non-printable character
141 * @param s string to remove non printable characters from
143 std::string _CreateCleanString(std::string s) {
146 for(int i=0;i<str.size();i++)
153 if(!isprint(s[str.size()-1]))
154 if(s[str.size()-1]==0)
155 str[str.size()-1]=' ';
162 * \brief Add a SEPARATOR to the end of the name is necessary
163 * @param name file/directory name to normalize
165 void NormalizePath(std::string &name)
167 const char SEPARATOR_X = '/';
168 const char SEPARATOR_WIN = '\\';
169 const std::string SEPARATOR = "/";
170 int size=name.size();
172 if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN))
180 * \brief Get the (directory) path from a full path file name
181 * @param fullName file/directory name to extract Path from
183 std::string GetPath(std::string &fullName)
185 int pos1=fullName.rfind("/");
186 int pos2=fullName.rfind("\\");
188 fullName.resize(pos1);
190 fullName.resize(pos2);
196 * \brief Get the (last) name of a full path file name
197 * @param fullName file/directory name to extract end name from
199 std::string GetName(std::string &fullName)
201 int fin=fullName.length()-1;
202 char a =fullName.c_str()[fin];
203 if (a == '/' || a == '\\') {
207 for (int i=fin;i!=0;i--) {
208 if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\')
213 std::string lastName;
214 for (int j=deb;j<fin+1;j++)
215 lastName=lastName+fullName.c_str()[j];