X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmUtil.cxx;h=ebb8191d56b9cba8ba022c84109a29df7af67a4b;hb=82874940805320d00eecb834bfa8643822c49e45;hp=ed2fe33f7578197ebf5c60a28dd7f6b018f06183;hpb=2f27193f6cbd42d1143738e40563b4a4bd4a0c8a;p=gdcm.git diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index ed2fe33f..ebb8191d 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2004/10/25 04:47:43 $ - Version: $Revision: 1.55 $ + 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 @@ -130,17 +130,19 @@ std::string Util::CreateCleanString(std::string const & s) * \brief Add a SEPARATOR to the end of the name is necessary * @param name file/directory name to normalize */ -void Util::NormalizePath(std::string &name) +std::string Util::NormalizePath(std::string const & pathname) { const char SEPARATOR_X = '/'; const char SEPARATOR_WIN = '\\'; const std::string SEPARATOR = "/"; + std::string name = pathname; int size = name.size(); if( name[size-1] != SEPARATOR_X && name[size-1] != SEPARATOR_WIN ) { name += SEPARATOR; } + return name; } /** @@ -166,7 +168,7 @@ std::string Util::GetPath(std::string const & fullName) } /** - * \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 */ @@ -187,5 +189,80 @@ std::string Util::GetName(std::string const & fullName) } } +/** + * \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 +std::ostream& binary_write(std::ostream& os, const T& val) +{ + return os.write(reinterpret_cast(&val), sizeof val); +} + +std::ostream& binary_write(std::ostream& os, const uint16_t& val) +{ +#ifdef GDCM_WORDS_BIGENDIAN + uint16_t swap; + swap = ((( val << 8 ) & 0x0ff00 ) | (( val >> 8 ) & 0x00ff ) ); + return os.write(reinterpret_cast(&swap), 2); +#else + return os.write(reinterpret_cast(&val), 2); +#endif //GDCM_WORDS_BIGENDIAN +} + +std::ostream& binary_write(std::ostream& os, const uint32_t& val) +{ +#ifdef GDCM_WORDS_BIGENDIAN + uint32_t swap; + swap = ( ((val<<24) & 0xff000000) | ((val<<8) & 0x00ff0000) | + ((val>>8) & 0x0000ff00) | ((val>>24) & 0x000000ff) ); + return os.write(reinterpret_cast(&swap), 4); +#else + return os.write(reinterpret_cast(&val), 4); +#endif //GDCM_WORDS_BIGENDIAN +} + +//template <> +std::ostream& binary_write(std::ostream& os, const char* val) +{ + 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