# gdcmCodeString.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program: GDCM (Grassroots DICOM). A DICOM library
    00004   Module:  $URL$
    00005
    00006   Copyright (c) 2006-2010 Mathieu Malaterre
    00007   All rights reserved.
    00008   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
    00009
    00010      This software is distributed WITHOUT ANY WARRANTY; without even
    00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00012      PURPOSE.  See the above copyright notice for more information.
    00013
    00014 =========================================================================*/
    00015 #ifndef GDCMCODESTRING_H
    00016 #define GDCMCODESTRING_H
    00017
    00018 #include "gdcmString.h"
    00019
    00020 namespace gdcm
    00021 {
    00022
    00040 // Note to myself: because note all wrapped language support exception
    00041 // we could not support throwing an exception during object construction.
    00042 class GDCM_EXPORT CodeString
    00043 {
    00044   friend std::ostream& operator<< (std::ostream& os, const CodeString& str);
    00045   friend bool operator==(const CodeString &ref, const CodeString& cs);
    00046   friend bool operator!=(const CodeString &ref, const CodeString& cs);
    00047   typedef String<'\\',16> InternalClass;
    00048 public:
    00049   typedef InternalClass::value_type             value_type;
    00050   typedef InternalClass::pointer                pointer;
    00051   typedef InternalClass::reference              reference;
    00052   typedef InternalClass::const_reference        const_reference;
    00053   typedef InternalClass::size_type              size_type;
    00054   typedef InternalClass::difference_type        difference_type;
    00055   typedef InternalClass::iterator               iterator;
    00056   typedef InternalClass::const_iterator         const_iterator;
    00057   typedef InternalClass::reverse_iterator       reverse_iterator;
    00058   typedef InternalClass::const_reverse_iterator const_reverse_iterator;
    00059
    00061   CodeString(): Internal() {}
    00062   CodeString(const value_type* s): Internal(s) { Internal = Internal.Trim(); }
    00063   CodeString(const value_type* s, size_type n): Internal(s, n) {
    00064     Internal = Internal.Trim(); }
    00065   CodeString(const InternalClass& s, size_type pos=0, size_type n=InternalClass::npos):
    00066     Internal(s, pos, n) { Internal = Internal.Trim(); }
    00067
    00069   bool IsValid() const;
    00070
    00072   std::string GetAsString() const {
    00073     return Internal;
    00074   }
    00075
    00077   GDCM_LEGACY(std::string Trim() const)
    00078
    00079
    00080   size_type Size() const { return Internal.size(); }
    00081
    00084   GDCM_LEGACY(size_type size() const)
    00085
    00086 protected:
    00087   std::string TrimInternal() const {
    00088     return Internal.Trim();
    00089   }
    00090
    00091 private:
    00092   String<'\\',16> Internal;
    00093 };
    00094
    00095 inline std::ostream& operator<< (std::ostream& os, const CodeString& str)
    00096 {
    00097   os << str.Internal;
    00098   return os;
    00099 }
    00100
    00101 inline bool operator==(const CodeString &ref, const CodeString& cs)
    00102 {
    00103   return ref.Internal == cs.Internal;
    00104 }
    00105 inline bool operator!=(const CodeString &ref, const CodeString& cs)
    00106 {
    00107   return ref.Internal != cs.Internal;
    00108 }
    00109
    00110
    00111 } // end namespace gdcm
    00112
    00113 #endif //GDCMCODESTRING_H