]> Creatis software - creaImageIO.git/blob - src/creaImageIOTreeDescriptor.h
d36e9d667c2d0a748aa15cefe484f30c0164b100
[creaImageIO.git] / src / creaImageIOTreeDescriptor.h
1 #ifndef __creaImageIOTreeDescriptor_h_INCLUDED__
2 #define __creaImageIOTreeDescriptor_h_INCLUDED__
3
4 #include <creaImageIOTreeAttributeMapType.h>
5 #include <creaImageIOTreeLevelDescriptor.h>
6
7
8 namespace creaImageIO
9 {
10         using namespace std;
11   namespace tree
12   {
13     
14     /**
15      * \ingroup Tree
16      */
17     
18         ///Descriptor of the structure of a Tree (number of levels, descriptors of each level, ...). 
19           //Any Tree has at least one level (level 0) of name "Root"
20      
21     class Descriptor
22     {
23     public:
24       /// Ctor : creates the mandatory level 0 descriptor called "Root"
25       Descriptor();
26       /// Destructor
27       ~Descriptor();
28
29       /// Loads from a xml description file
30       void LoadXML(const std::string& filename);
31       /// Creates the default descriptor
32       void CreateDefault();
33
34       /// Returns the number of levels of the tree
35       unsigned int GetNumberOfLevels() 
36       { return mLevelDescriptorList.size(); }
37
38       /// Returns the LevelDescriptor of a given level (const ref)
39       const LevelDescriptor& GetLevelDescriptor(int level) const
40       { return mLevelDescriptorList[level]; }
41
42       /// Returns the AttributeDescriptorList of a given level (const ref)
43             /// type = 0 all attributes
44           /// type = 1 without ID and PATIENT_ID
45       const LevelDescriptor::AttributeDescriptorListType& 
46       GetAttributeDescriptorList(int level, int type = 0) const
47       { return mLevelDescriptorList[level].GetAttributeDescriptorList(type); }
48   
49           
50       /// Copy the AttributeDescriptorList without ID tag
51           void CopyAttributeDescriptorList(int level)
52           {
53                   mLevelDescriptorList[level].CopyAttributeDescriptorList();
54           }
55
56       /// Adds a LevelDescriptor at the end of the list
57       void Add(const LevelDescriptor&);
58       
59       /// Adds an AttributeDescriptor to level l
60       void Add(const AttributeDescriptor&, int l);
61       
62       
63       /// Builds the key to value map of all the attributes of the tree
64         void BuildAttributeMap( AttributeMapType& ) const;
65
66       /// The type of LevelDescriptor container
67         typedef std::vector<LevelDescriptor> LevelDescriptorListType;
68  
69       /// Returns the list of tree levels (const)
70         const LevelDescriptorListType& GetLevelDescriptorList() const { return mLevelDescriptorList; }
71
72       /// Clears the Descriptor
73       void Clear();
74
75           //Create Attribute Descriptors from a file
76         void createDescriptorfromFile(const std::string &i_file);
77
78
79         /// test if an attribute is present in DescriptionList
80         /// return level's name
81         const std::string isExist(const std::string i_attr);
82
83     private:
84       LevelDescriptorListType mLevelDescriptorList;
85       /// Creates the mandatory level 0 descriptor called "Root"
86       /// (assumes the list is empty)
87       void CreateLevel0Descriptor();
88   
89     };
90     // EO class Descriptor
91     //=====================================================================
92   } // EO namespace tree
93
94 } // EO namespace creaImageIO
95
96 // EOF
97 #endif