MeVisLabToolboxReference
MeVis/Foundation/Sources/DicomTree/MLDicomTree/DCMTree_Tree.h
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // **InsertLicense** code
00003 //-----------------------------------------------------------------------------
00005 
00010 //-----------------------------------------------------------------------------
00011 
00012 #ifndef CLASS_DCMTREE_TREE
00013 #define CLASS_DCMTREE_TREE
00014 
00015 #include "DCMTree_Lib.h"
00016 #include "DCMTree_TagId.h"
00017 #include "DCMTree_Defines.h"
00018 
00019 #ifdef _MSC_VER
00020   // 4365: signed/unsigned mismatch
00021   // 4548: expression before comma has no effect; expected expression with side-effect
00022   #pragma warning (push)
00023   #pragma warning (disable : 4365 4548)
00024 #endif
00025 #include <iostream>
00026 #include <fstream>
00027 #include <set>
00028 #ifdef _MSC_VER
00029   #pragma warning (pop)
00030 #endif
00031 
00048 namespace DCMTree
00049 {
00050     class DCMTREE_EXPORT Tree:public DCMTree_Serialization::Serializable,public DCMTree_Serialization::Deserializable
00051     {
00052     public:
00054         Tree();
00055 
00060         Tree (const Tree &other);
00061 
00068         Tree (Const_TreePtr parent);
00069 
00071         virtual ~Tree();
00072 
00074         Const_TreePtr parent() const;
00075 
00077         Const_TreePtr root () const;
00078 
00080         bool hasParent() const;
00081 
00083         bool hasDict() const;
00084 
00086         Const_DictPtr getDict () const;
00087 
00090         void setDict (Const_DictPtr dictPtr);
00091 
00097         Tree &operator= (const Tree &other);
00098 
00103         const TagPtrMap &tags();
00104 
00108         boost::uint32_t tagsSize() const;
00109 
00113         TagIdVectorPtr tagIds (TagSelector sel=AllTags) const;
00114 
00118         TagIdVectorPtr tagIds (const TagId &fromtag, const TagId &totag, TagSelector sel=AllTags) const;
00119 
00124         bool hasTag (const TagId &tagid, TagSelector sel=AllTags) const;
00125 
00130         bool hasTag (const std::string& tagName, TagSelector sel=AllTags) const;
00131 
00136         Const_TagPtr getTag (const TagId &tagid, TagSelector sel=AllTags) const;
00137 
00144         Const_TagPtr getTag (const TagId &tagid, const std::string& privateCreator, Vr privateVr=UN, TagSelector sel=AllTags) const;
00145 
00150         Const_TagPtr getTag (const std::string& tagName, TagSelector sel=AllTags) const;
00151         
00156         TagPtr getTag_rw (const TagId &tagid);
00157 
00162         Const_TagPtrMapPtr getTags (TagSelector sel=AllTags) const;
00163 
00168         Const_TagPtrMapPtr getTags (const TagId &fromtag, const TagId &totag, TagSelector sel=AllTags) const;
00169         
00175         void setTag (const TagId &tagid, Const_TagPtr tagdata);
00180         void setTag (Const_TagPtr tagdata);
00181 
00186         void setTags (Const_TreePtr tags);
00187 
00189         void addTag (const TagId &tagid, TagPtr tagdata);
00194         void addTag (TagPtr tagdata);
00195 
00196         /* add the given tags to this, NO copy, parent tags are ignored **/
00197         void addTags (TreePtr tags);
00198 
00202         void removeTag (const TagId &tagid);
00203 
00207         void removeTags (TagIdVectorPtr tags);
00208         
00212         TreePtr copy() const;
00213 
00217         TreePtr copy (const TagId &fromtag, const TagId &totag) const;
00218 
00222         TreePtr copy (TagIdVectorPtr tags) const;
00223 
00227         TreePtr mergedCopy (TagSelector sel) const;
00228 
00229 
00235         std::string getPrivateCreator (TagId tagId) const;
00236 
00243         unsigned short findPrivateSlot (unsigned short groupid, const std::string &creator, 
00244                                         bool newOrExisting = false) const;
00245 
00253         unsigned short getPrivateSlot (unsigned short groupid, const std::string &creator);
00254 
00258         void removePrivateTags (unsigned short groupId, unsigned short slot);
00259 
00263         void convertCharacterSet (const std::string &originalcharacterset,const std::string &newcharacterset);
00264 
00270         void fromStream (std::istream &in, bool readName=false);
00271 
00277         void toStream (std::ostream &out, bool writeName=false) const;
00278 
00279         virtual void serializeX (DCMTree_Serialization::Sink &sink) const;
00280         virtual void deserializeX (DCMTree_Serialization::Source &source);
00281 
00282 
00283     private:
00284 
00288         void addTagsToSet (std::set<RawTagId> &tagIdSet, TagSelector sel, const TagId &fromtag, const TagId &totag) const;
00289 
00293         void addTagsToMap (Const_TagPtrMap &tagMap, TagSelector sel, const TagId &fromtag, const TagId &totag) const;
00294 
00296         Const_TagPtr const_tag4tagid (const TagId &tagid,const TagSelector sel) const;
00297 
00299         TagPtr tag4tagid (const TagId &tagid);
00300 
00305         void checkForTag (const TagId &tagid,const TagSelector sel) const;
00306 
00308         bool isDeleted (const TagId &tagid) const;
00309 
00311         void markAsDeleted (const TagId &tagid);
00312 
00314         void undelete (const TagId &tagid);
00315 
00316 
00318         TagPtrMap _tags;
00319 
00321         std::set<RawTagId> _deletedtags;
00322 
00328         Const_TreePtr _parent;
00329 
00331         Const_DictPtr _dictionary;
00332     };
00333 
00334 
00336     inline std::ostream &operator << (std::ostream &out,const Tree &t)
00337     {
00338         t.toStream (out, false);
00339         return out;
00340     }
00341 
00342 
00344     inline std::istream &operator >> (std::istream &in,Tree &t)
00345     {
00346         t.fromStream (in, false);
00347         return in;
00348     }
00349 }
00350 
00351 #endif
00352 
00353