Program: gdcm
Module: $RCSfile: gdcmUtil.cxx,v $
Language: C++
- Date: $Date: 2004/10/28 22:21:57 $
- Version: $Revision: 1.57 $
+ Date: $Date: 2004/11/05 20:23:14 $
+ Version: $Revision: 1.60 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
}
/**
- * \ingroup Globals
+ * \ingroup Util
* \brief Get the (last) name of a full path file name
* @param fullName file/directory name to extract end name from
*/
}
}
+/**
+ * \ingroup Util
+ * \brief Create a /DICOM/ string:
+ * It should a of even lenght (no odd length ever)
+ * It can contains as many \0 as you want.
+ * This function is similar to DicomString(const char*),
+ * except it doesn't take a lenght.
+ * It only pad with a null character if length is odd
+ */
+std::string Util::DicomString(const char* s)
+{
+ size_t l = strlen(s);
+ if( l%2 )
+ {
+ l++;
+ }
+ std::string r(s, s+l);
+ assert( !(r.size() % 2) );
+ return r;
+}
+
+/**
+ * \ingroup Util
+ * \brief Create a /DICOM/ string:
+ * It should a of even length (no odd length ever)
+ * It can contains as many \0 as you want.
+ */
+std::string Util::DicomString(const char* s, size_t l)
+{
+ std::string r(s, s+l);
+ assert( !(r.size() % 2) );
+ return r;
+}
template <class T>
std::ostream& binary_write(std::ostream& os, const T& val)
std::ostream& binary_write(std::ostream& os, const uint16_t& val)
{
#ifdef GDCM_WORDS_BIGENDIAN
- uint16_t *swap;
- swap = (((*val>>8)&0xff) | ((*val&0xff)<<8));
- return os.write(reinterpret_cast<const char*>(swap), 2);
+ uint16_t swap;
+ swap = ((( val << 8 ) & 0x0ff00 ) | (( val >> 8 ) & 0x00ff ) );
+ return os.write(reinterpret_cast<const char*>(&swap), 2);
#else
return os.write(reinterpret_cast<const char*>(&val), 2);
#endif //GDCM_WORDS_BIGENDIAN
std::ostream& binary_write(std::ostream& os, const uint32_t& val)
{
#ifdef GDCM_WORDS_BIGENDIAN
- uint32_t *swap;
+ uint32_t swap;
swap = ( ((val<<24) & 0xff000000) | ((val<<8) & 0x00ff0000) |
((val>>8) & 0x0000ff00) | ((val>>24) & 0x000000ff) );
- return os.write(reinterpret_cast<const char*>(swap), 4);
+ return os.write(reinterpret_cast<const char*>(&swap), 4);
#else
return os.write(reinterpret_cast<const char*>(&val), 4);
#endif //GDCM_WORDS_BIGENDIAN
return os.write(val, strlen(val));
}
+std::ostream& binary_write(std::ostream& os, std::string const & val)
+{
+ return os.write(val.c_str(), val.size());
+}
+
} // end namespace gdcm