creaImageIO_lib
creaImageIO::tree::Tree Class Reference

An attributed Tree structure. More...

#include <creaImageIOTree.h>

Inheritance diagram for creaImageIO::tree::Tree:
Collaboration diagram for creaImageIO::tree::Tree:

Public Types

typedef std::map< std::string,
std::string > 
AttributeMapType
 
typedef std::vector< Node * > ChildrenListType
 The type of children container. More...
 

Public Member Functions

 Tree ()
 Ctor. More...
 
virtual ~Tree ()
 Virtual destructor. More...
 
virtual TreeGetTree ()
 Returns the descriptor of the tree. More...
 
virtual const TreeGetTree () const
 Returns the tree to which the node belongs. More...
 
virtual int GetLevel () const
 Returns the level of the node in the tree. More...
 
const DescriptorGetDescriptor () const
 Returns the Descriptor of the tree (const) More...
 
DescriptorGetDescriptor ()
 Returns the descriptor of the tree. More...
 
unsigned int GetNumberOfLevels ()
 Returns the number of levels of the tree. More...
 
const LevelDescriptorGetLevelDescriptor (int level) const
 Returns the LevelDescriptor of a given level (const ref) More...
 
const
LevelDescriptor::AttributeDescriptorListType
GetAttributeDescriptorList (int level, int type=0) const
 
virtual void Print () const
 Print the node. More...
 
void CopyAttributeDescriptorList (int level)
 Copy descriptor list without ID tag. More...
 
const std::string isAttributeExist (const std::string i_attr)
 Test if this attribute is available in this tree description. More...
 
void InitializeAttributeMap ()
 Initializes the attribute map i.e. creates the entries. More...
 
const LevelDescriptorGetLevelDescriptor () const
 Returns the level descriptor of the node. More...
 
NodeGetParent () const
 Returns the parent of the node. More...
 
unsigned int GetNumberOfChildren () const
 
bool GetChildrenLoaded () const
 Returns true iff the node's children are loaded. More...
 
void SetChildrenLoaded (bool l)
 Sets the node's children. More...
 
ChildrenListTypeGetChildrenList ()
 Returns the list of children. More...
 
const ChildrenListTypeGetChildrenList () const
 Returns the list of children (const) More...
 
int RemoveChildrenFromList (Node *)
 Remove the given children from the children list. More...
 
AttributeMapTypeGetAttributeMap ()
 Get the Attributes Map. More...
 
const AttributeMapTypeGetAttributeMap () const
 Get the Attributes Map. More...
 
const std::string & GetAttribute (const std::string &k) const
 Get the Attribute for a specific key. More...
 
const std::string & GetCleanAttribute (const std::string &k) const
 Get the Attribute for a specific key without OS dependance (not implemented) More...
 
void SetAttribute (const std::string &k, const std::string &v)
 Set an Attribute for a specific key. More...
 
void UnsafeSetAttribute (const std::string &k, const std::string &v)
 Set an Attribute for a specific key(unsafe mode) More...
 
const AttributeDescriptorGetAttributeDescriptor (const std::string &k) const
 Get Descriptor for an Attribute. More...
 
bool Matches (const AttributeMapType &) const
 Returns true if the KEY attributes of the node match those of the map provided. More...
 
template<class T >
GetData () const
 Returns the node data casted into the type T. More...
 
void SetData (boost::shared_ptr< NodeData > d)
 Sets the node data. Deletes existing data if any. More...
 
void SortChildren (const LexicographicalComparator &)
 Sorts the children of the node. More...
 
std::string GetLabel () const
 Get the Label of the node. More...
 

Private Attributes

Descriptor mDescriptor
 

Detailed Description

An attributed Tree structure.

Definition at line 55 of file creaImageIOTree.h.

Member Typedef Documentation

typedef std::map<std::string,std::string> creaImageIO::tree::Node::AttributeMapType
inherited

Definition at line 67 of file creaImageIOTreeNode.h.

typedef std::vector<Node*> creaImageIO::tree::Node::ChildrenListType
inherited

The type of children container.

Definition at line 108 of file creaImageIOTreeNode.h.

Constructor & Destructor Documentation

creaImageIO::tree::Tree::Tree ( )

Ctor.

Definition at line 37 of file creaImageIOTree.cpp.

References GimmickMessage.

38  : Node(0)
39  {
40  GimmickMessage(5,"Default Tree constructor"
41  << std::endl);
42 
43  }
creaImageIO::tree::Tree::~Tree ( )
virtual

Virtual destructor.

Definition at line 45 of file creaImageIOTree.cpp.

46  {
47 
48  }

Member Function Documentation

void creaImageIO::tree::Tree::CopyAttributeDescriptorList ( int  level)
inline

Copy descriptor list without ID tag.

Definition at line 96 of file creaImageIOTree.h.

References creaImageIO::tree::Descriptor::CopyAttributeDescriptorList(), and GetDescriptor().

Referenced by creaImageIO::SQLiteTreeHandler::DBCreate(), and creaImageIO::SQLiteTreeHandler::DBImportTreeDescription().

97  {
99  }

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string & creaImageIO::tree::Node::GetAttribute ( const std::string &  k) const
inherited

Get the Attribute for a specific key.

Definition at line 172 of file creaImageIOTreeNode.cpp.

References creaImageIO::tree::Node::mAttributeMap.

Referenced by creaImageIO::WxGimmickView::CreateTreeView(), creaImageIO::SQLiteTreeHandler::DBGraftToParent(), creaImageIO::SQLiteTreeHandler::DBLoadChildren(), creaImageIO::SQLiteTreeHandler::DBRecursiveRemoveNode(), creaImageIO::SQLiteTreeHandler::DBSetAttribute(), creaImageIO::TreeHandlerImageAdder::FindNode(), creaImageIO::TreeHandlerImageAdder::FindNodePartial(), creaImageIO::SQLiteTreeHandler::GetNumberOfChildren(), creaImageIO::WxEditFieldsPanel::OnComboChange(), creaImageIO::WxTreeView::OnDumpTags(), creaImageIO::WxTreeView::OnPopupFilter(), creaImageIO::TreeHandlerImageAdder::remove(), creaImageIO::TimestampDatabaseHandler::RemoveNode(), creaImageIO::GimmickView::RequestReading(), and creaImageIO::WxEditFieldsPanel::WxEditFieldsPanel().

173  {
174  // std::cout << "this = "<<(void*)this<<std::endl;
175  // std::cout << "mFieldValueMap="<<(void*)(&mFieldValueMap)<<std::endl;
176  AttributeMapType::const_iterator i = mAttributeMap.find(k);
177  if (i == mAttributeMap.end())
178  {
179  static std::string def("");
180  return def;
181  // CREAIMAGEIO_ERROR("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
182  }
183  return i->second;
184  }

Here is the caller graph for this function:

const AttributeDescriptor & creaImageIO::tree::Node::GetAttributeDescriptor ( const std::string &  k) const
inherited

Get Descriptor for an Attribute.

Returns the attribute descriptor of the passed parameter.

Definition at line 139 of file creaImageIOTreeNode.cpp.

References GetAttributeDescriptorList(), creaImageIO::tree::Node::GetLevel(), and creaImageIO::tree::Node::GetTree().

Referenced by creaImageIO::WxTreeView::SortLevel().

140  {
141  LevelDescriptor::AttributeDescriptorListType::const_iterator a;
142  for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
144  ++a)
145  {
146 
147  if(a->GetKey()==k)
148  {
149  return *a;
150  }
151 
152  }
153  return *a;
154  }

Here is the call graph for this function:

Here is the caller graph for this function:

AttributeMapType& creaImageIO::tree::Node::GetAttributeMap ( )
inlineinherited

Get the Attributes Map.

Definition at line 119 of file creaImageIOTreeNode.h.

References creaImageIO::tree::Node::mAttributeMap.

Referenced by creaImageIO::SQLiteTreeHandler::SQLAppendAttributesValues().

119 { return mAttributeMap; }

Here is the caller graph for this function:

const AttributeMapType& creaImageIO::tree::Node::GetAttributeMap ( ) const
inlineinherited

Get the Attributes Map.

Definition at line 122 of file creaImageIOTreeNode.h.

References creaImageIO::tree::Node::mAttributeMap.

122 { return mAttributeMap; }
const ChildrenListType& creaImageIO::tree::Node::GetChildrenList ( ) const
inlineinherited

Returns the list of children (const)

Definition at line 112 of file creaImageIOTreeNode.h.

References creaImageIO::tree::Node::mChildren.

112 { return mChildren; }
bool creaImageIO::tree::Node::GetChildrenLoaded ( ) const
inlineinherited

Returns true iff the node's children are loaded.

Definition at line 102 of file creaImageIOTreeNode.h.

References creaImageIO::tree::Node::mChildrenLoaded.

Referenced by creaImageIO::SQLiteTreeHandler::DBLoadChildren().

102 { return mChildrenLoaded; }

Here is the caller graph for this function:

const std::string& creaImageIO::tree::Node::GetCleanAttribute ( const std::string &  k) const
inherited

Get the Attribute for a specific key without OS dependance (not implemented)

template<class T >
T creaImageIO::tree::Node::GetData ( ) const
inlineinherited

Returns the node data casted into the type T.

Definition at line 145 of file creaImageIOTreeNode.h.

References creaImageIO::tree::Node::mData.

146  { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
Descriptor& creaImageIO::tree::Tree::GetDescriptor ( )
inline

Returns the descriptor of the tree.

Definition at line 75 of file creaImageIOTree.h.

References mDescriptor.

75 { return mDescriptor; }
std::string creaImageIO::tree::Node::GetLabel ( ) const
inherited

Get the Label of the node.

Definition at line 239 of file creaImageIOTreeNode.cpp.

References creaImageIO::tree::LevelDescriptor::GetLabelList(), creaImageIO::tree::Node::GetLevelDescriptor(), GimmickDebugMessage, GimmickError, and creaImageIO::tree::Node::mAttributeMap.

Referenced by creaImageIO::WxGimmickView::CreateEditFieldsDialog(), creaImageIO::SQLiteTreeHandler::DBInsert(), creaImageIO::SQLiteTreeHandler::DBLoadChildren(), creaImageIO::SQLiteTreeHandler::DBSetAttribute(), creaImageIO::tree::Node::Matches(), Print(), and creaImageIO::tree::Node::Print().

240  {
241  std::string l;
242  const std::vector<std::string>& label
244 
245  std::vector<std::string>::const_iterator i;
246  for (i = label.begin(); i != label.end(); )
247  {
248  GimmickDebugMessage(9,"LABEL '"<<*i<<"'"<<std::endl);
249  AttributeMapType::const_iterator j = mAttributeMap.find(*i);
250  if (j != mAttributeMap.end())
251  {
252  l += j->second;
253  ++i;
254  if (i != label.end()) l += "|";
255  }
256  else
257  {
258  GimmickError("Node::GetLabel() : LABEL attribute '"
259  <<*i
260  <<"' is not in node attribute map (should be!)" );
261  }
262  }
263  if (l.size()==0) l="?";
264  return l;
265  }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual int creaImageIO::tree::Tree::GetLevel ( ) const
inlinevirtual

Returns the level of the node in the tree.

Reimplemented from creaImageIO::tree::Node.

Definition at line 70 of file creaImageIOTree.h.

70 { return 0; }
const LevelDescriptor & creaImageIO::tree::Node::GetLevelDescriptor ( ) const
inherited

Returns the level descriptor of the node.

Definition at line 130 of file creaImageIOTreeNode.cpp.

References creaImageIO::tree::Node::GetLevel(), GetLevelDescriptor(), and creaImageIO::tree::Node::GetTree().

Referenced by creaImageIO::tree::Node::GetLabel(), and creaImageIO::tree::Node::Matches().

131  {
132  return GetTree()->GetLevelDescriptor(GetLevel());
133  }

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int creaImageIO::tree::Node::GetNumberOfChildren ( ) const
inlineinherited

Returns the number of children of the node. Warning : if the children are not loaded then might return 0 even if the node has children ! see TreeHandler::GetNumberOfChildren

Definition at line 99 of file creaImageIOTreeNode.h.

References creaImageIO::tree::Node::mChildren.

Referenced by creaImageIO::SQLiteTreeHandler::DBRecursiveRemoveNode(), creaImageIO::TreeHandlerImageAdder::RemoveFile(), and creaImageIO::TimestampDatabaseHandler::RemoveNode().

99 { return (int)mChildren.size(); }

Here is the caller graph for this function:

Node* creaImageIO::tree::Node::GetParent ( ) const
inlineinherited

Returns the parent of the node.

Definition at line 93 of file creaImageIOTreeNode.h.

References creaImageIO::tree::Node::mParent.

Referenced by creaImageIO::SQLiteTreeHandler::Remove().

93 { return mParent; }

Here is the caller graph for this function:

virtual Tree* creaImageIO::tree::Tree::GetTree ( )
inlinevirtual

Returns the descriptor of the tree.

Returns the tree to which the node belongs

Reimplemented from creaImageIO::tree::Node.

Definition at line 66 of file creaImageIOTree.h.

Referenced by creaImageIO::SQLiteTreeHandler::DBGetParent(), creaImageIO::SQLiteTreeHandler::LoadChildren(), and creaImageIO::SQLiteTreeHandler::SetAttribute().

66 { return this; }

Here is the caller graph for this function:

virtual const Tree* creaImageIO::tree::Tree::GetTree ( ) const
inlinevirtual

Returns the tree to which the node belongs.

Reimplemented from creaImageIO::tree::Node.

Definition at line 68 of file creaImageIOTree.h.

68 { return this; }
void creaImageIO::tree::Node::InitializeAttributeMap ( )
inherited

Initializes the attribute map i.e. creates the entries.

Definition at line 115 of file creaImageIOTreeNode.cpp.

References GetAttributeDescriptorList(), creaImageIO::tree::Node::GetLevel(), creaImageIO::tree::Node::GetTree(), and creaImageIO::tree::Node::UnsafeSetAttribute().

Referenced by creaImageIO::SQLiteTreeHandler::DBCreate(), and creaImageIO::tree::Node::Node().

116  {
117  // Initialize attributes
118  LevelDescriptor::AttributeDescriptorListType::const_iterator a;
119  for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
121  ++a)
122  {
123  UnsafeSetAttribute( a->GetKey(), "" );
124  }
125  }

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string creaImageIO::tree::Tree::isAttributeExist ( const std::string  i_attr)
inline

Test if this attribute is available in this tree description.

Definition at line 102 of file creaImageIOTree.h.

References creaImageIO::tree::Descriptor::isExist(), and mDescriptor.

Referenced by creaImageIO::TreeHandlerImageAdder::isAttributeExist().

103  {
104  return mDescriptor.isExist(i_attr);
105  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool creaImageIO::tree::Node::Matches ( const AttributeMapType m) const
inherited

Returns true if the KEY attributes of the node match those of the map provided.

Definition at line 204 of file creaImageIOTreeNode.cpp.

References creaImageIO::tree::LevelDescriptor::GetIdentifierList(), creaImageIO::tree::Node::GetLabel(), creaImageIO::tree::Node::GetLevelDescriptor(), GimmickDebugMessage, and creaImageIO::tree::Node::mAttributeMap.

205  {
206  GimmickDebugMessage(2,"'"<<GetLabel()<<"' matching..."<<std::endl);
207  const std::vector<std::string>& id
209  std::vector<std::string>::const_iterator i;
210  for (i = id.begin(); i != id.end(); ++i)
211  {
212  if (mAttributeMap.find(*i)->second != m.find(*i)->second )
213  {
214  GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values do not match"<<std::endl);
215  return false;
216  }
217  GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values match"<<std::endl);
218  }
219  return true;
220  }

Here is the call graph for this function:

void creaImageIO::tree::Tree::Print ( ) const
virtual

Print the node.

Reimplemented from creaImageIO::tree::Node.

Definition at line 50 of file creaImageIOTree.cpp.

References creaImageIO::tree::Node::GetChildrenList(), creaImageIO::tree::Node::GetLabel(), and GimmickMessage.

Referenced by creaImageIO::Gimmick::Print().

51  {
52  GimmickMessage(1,GetLabel()<<std::endl);
53  ChildrenListType::const_iterator i;
54  for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
55  {
56  (*i)->Print();
57  }
58 
59  }

Here is the call graph for this function:

Here is the caller graph for this function:

int creaImageIO::tree::Node::RemoveChildrenFromList ( Node node)
inherited

Remove the given children from the children list.

Definition at line 158 of file creaImageIOTreeNode.cpp.

References creaImageIO::tree::Node::GetChildrenList().

Referenced by creaImageIO::SQLiteTreeHandler::Remove().

159  {
160  ChildrenListType::iterator i = find(GetChildrenList().begin(),
161  GetChildrenList().end(),
162  node);
163  if (i != GetChildrenList().end())
164  {
165  GetChildrenList().erase(i);
166  }
167  return (int)GetChildrenList().size();
168  }

Here is the call graph for this function:

Here is the caller graph for this function:

void creaImageIO::tree::Node::SetAttribute ( const std::string &  k,
const std::string &  v 
)
inherited

Set an Attribute for a specific key.

Definition at line 188 of file creaImageIOTreeNode.cpp.

References creaImageIO::tree::Node::mAttributeMap.

Referenced by creaImageIO::SQLiteTreeHandler::DBGraftToParent(), creaImageIO::SQLiteTreeHandler::DBInsert(), creaImageIO::SQLiteTreeHandler::DBSetAttribute(), and creaImageIO::TreeHandlerImageAdder::EditField().

190  {
191  AttributeMapType::iterator i = mAttributeMap.find(k);
192  if (i==mAttributeMap.end())
193  {
194  std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with key '"
195  <<k<<"'"<<std::endl;
196  creaError( "[Gimmick!] Node::SetAttribute : no attribute with key '"
197  <<k<<"'");
198  }
199  i->second = v;
200  }

Here is the caller graph for this function:

void creaImageIO::tree::Node::SetChildrenLoaded ( bool  l)
inlineinherited

Sets the node's children.

Definition at line 105 of file creaImageIOTreeNode.h.

References creaImageIO::tree::Node::mChildrenLoaded.

Referenced by creaImageIO::SQLiteTreeHandler::DBCreate(), creaImageIO::SQLiteTreeHandler::DBGraftToParent(), and creaImageIO::SQLiteTreeHandler::DBLoadChildren().

105 { mChildrenLoaded = l; }

Here is the caller graph for this function:

void creaImageIO::tree::Node::SetData ( boost::shared_ptr< NodeData d)
inlineinherited

Sets the node data. Deletes existing data if any.

Definition at line 149 of file creaImageIOTreeNode.h.

References creaImageIO::tree::Node::mData.

149 {mData.reset(); mData = d; }//{ if (mData) delete mData; mData = d; }
void creaImageIO::tree::Node::SortChildren ( const LexicographicalComparator )
inherited

Sorts the children of the node.

void creaImageIO::tree::Node::UnsafeSetAttribute ( const std::string &  k,
const std::string &  v 
)
inlineinherited

Set an Attribute for a specific key(unsafe mode)

Definition at line 135 of file creaImageIOTreeNode.h.

References creaImageIO::tree::Node::mAttributeMap.

Referenced by creaImageIO::SQLiteTreeHandler::DBImportTreeDescription(), creaImageIO::SQLiteTreeHandler::DBLoadChildren(), creaImageIO::tree::Node::InitializeAttributeMap(), and creaImageIO::tree::Node::Node().

136  { mAttributeMap[k] = v; }

Here is the caller graph for this function:

Member Data Documentation

Descriptor creaImageIO::tree::Tree::mDescriptor
private

Definition at line 108 of file creaImageIOTree.h.

Referenced by GetDescriptor(), and isAttributeExist().


The documentation for this class was generated from the following files: