creaImageIO_lib
creaImageIO::tree::Node Class Reference

Node of an attributed Tree structure. More...

#include <creaImageIOTreeNode.h>

Inheritance diagram for creaImageIO::tree::Node:
Collaboration diagram for creaImageIO::tree::Node:

Public Types

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

Public Member Functions

 Node (Node *parent)
 Ctor with parent. More...
 
 Node (Node *parent, const AttributeMapType &)
 Ctor with parent and attributes map. More...
 
virtual ~Node ()
 Virtual destructor. More...
 
void InitializeAttributeMap ()
 Initializes the attribute map i.e. creates the entries. More...
 
const LevelDescriptorGetLevelDescriptor () const
 Returns the level descriptor of the node. More...
 
virtual TreeGetTree ()
 Returns the tree to which the node belongs. 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...
 
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...
 
virtual void Print () const
 Print the node. More...
 
std::string GetLabel () const
 Get the Label of the node. More...
 

Private Attributes

NodemParent
 The parent of the node. More...
 
ChildrenListType mChildren
 The list of children. More...
 
AttributeMapType mAttributeMap
 The map of attributes. More...
 
boost::shared_ptr< NodeDatamData
 User data. More...
 
bool mChildrenLoaded
 Are the children loaded ? More...
 

Detailed Description

Node of an attributed Tree structure.

Definition at line 64 of file creaImageIOTreeNode.h.

Member Typedef Documentation

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

Definition at line 67 of file creaImageIOTreeNode.h.

The type of children container.

Definition at line 108 of file creaImageIOTreeNode.h.

Constructor & Destructor Documentation

creaImageIO::tree::Node::Node ( Node parent)

Ctor with parent.

Definition at line 41 of file creaImageIOTreeNode.cpp.

References GetChildrenList(), GetLevel(), GimmickDebugMessage, InitializeAttributeMap(), and mData.

42  : mParent(parent),//mData(0),
43  mChildrenLoaded(false)
44  {
45  mData.reset();
46  if (parent)
47  {
48  GimmickDebugMessage(6,"Default Node constructor (level "<<GetLevel()<<")"
49  << std::endl);
50  // Insert into parent's children list
52  parent->GetChildrenList().push_back(this);
53  }
54  else
55  {
56  GimmickDebugMessage(6,"Default Node constructor without parent"
57  << std::endl);
58  }
59  }

Here is the call graph for this function:

creaImageIO::tree::Node::Node ( Node parent,
const AttributeMapType attr 
)

Ctor with parent and attributes map.

Definition at line 64 of file creaImageIOTreeNode.cpp.

References creaImageIO::tree::Tree::GetAttributeDescriptorList(), GetChildrenList(), GetLevel(), GetTree(), GimmickDebugMessage, mData, and UnsafeSetAttribute().

65  : mParent(parent),//mData(0),
66  mChildrenLoaded(false)
67  {
68  mData.reset();
69  GimmickDebugMessage(6,"Node constructor (level "<<GetLevel()<<")"
70  << std::endl);
71 
72  if (parent)
73  {
74  // Insert into parent's children list
75  parent->GetChildrenList().push_back(this);
76  // Initialize attributes
77  LevelDescriptor::AttributeDescriptorListType::const_iterator a;
78  for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
80  ++a)
81  {
82  std::string v;
83  AttributeMapType::const_iterator i = attr.find(a->GetKey());
84  if ( i != attr.end() )
85  {
86  v = i->second;
87  }
88  GimmickDebugMessage(6,"Setting attribute '"<<a->GetName()<<"' = '"
89  <<v<<"'"<<std::endl);
90  UnsafeSetAttribute( a->GetKey(), v );
91  }
92  }
93 
94  }

Here is the call graph for this function:

creaImageIO::tree::Node::~Node ( )
virtual

Virtual destructor.

Definition at line 99 of file creaImageIOTreeNode.cpp.

References GetChildrenList(), GimmickDebugMessage, and mData.

100  {
101  GimmickDebugMessage(6,"Node destructor"
102  << std::endl);
103  ChildrenListType::iterator i;
104  for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
105  {
106  delete *i;
107  }
108  mData.reset();
109  }

Here is the call graph for this function:

Member Function Documentation

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

Get the Attribute for a specific key.

Definition at line 172 of file creaImageIOTreeNode.cpp.

References 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

Get Descriptor for an Attribute.

Returns the attribute descriptor of the passed parameter.

Definition at line 139 of file creaImageIOTreeNode.cpp.

References creaImageIO::tree::Tree::GetAttributeDescriptorList(), GetLevel(), and 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 ( )
inline

Get the Attributes Map.

Definition at line 119 of file creaImageIOTreeNode.h.

References mAttributeMap.

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

119 { return mAttributeMap; }

Here is the caller graph for this function:

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

Get the Attributes Map.

Definition at line 122 of file creaImageIOTreeNode.h.

References mAttributeMap.

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

Returns the list of children (const)

Definition at line 112 of file creaImageIOTreeNode.h.

References mChildren.

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

Returns true iff the node's children are loaded.

Definition at line 102 of file creaImageIOTreeNode.h.

References 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

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

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

Returns the node data casted into the type T.

Definition at line 145 of file creaImageIOTreeNode.h.

References mData.

146  { if (mData!=0) return dynamic_cast<T>(mData); return 0; }
std::string creaImageIO::tree::Node::GetLabel ( ) const

Get the Label of the node.

Definition at line 239 of file creaImageIOTreeNode.cpp.

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

Referenced by creaImageIO::WxGimmickView::CreateEditFieldsDialog(), creaImageIO::SQLiteTreeHandler::DBInsert(), creaImageIO::SQLiteTreeHandler::DBLoadChildren(), creaImageIO::SQLiteTreeHandler::DBSetAttribute(), Matches(), creaImageIO::tree::Tree::Print(), and 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:

const LevelDescriptor & creaImageIO::tree::Node::GetLevelDescriptor ( ) const

Returns the level descriptor of the node.

Definition at line 130 of file creaImageIOTreeNode.cpp.

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

Referenced by GetLabel(), and 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
inline

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 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
inline

Returns the parent of the node.

Definition at line 93 of file creaImageIOTreeNode.h.

References mParent.

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

93 { return mParent; }

Here is the caller graph for this function:

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

Returns the tree to which the node belongs.

Reimplemented in creaImageIO::tree::Tree.

Definition at line 85 of file creaImageIOTreeNode.h.

References GetTree(), and mParent.

Referenced by creaImageIO::SQLiteTreeHandler::DBLoadChildren(), GetAttributeDescriptor(), GetLevelDescriptor(), GetTree(), InitializeAttributeMap(), and Node().

85 { return mParent->GetTree(); }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Returns the tree to which the node belongs.

Reimplemented in creaImageIO::tree::Tree.

Definition at line 87 of file creaImageIOTreeNode.h.

References GetTree(), and mParent.

87 { return mParent->GetTree(); }

Here is the call graph for this function:

void creaImageIO::tree::Node::InitializeAttributeMap ( )

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

Definition at line 115 of file creaImageIOTreeNode.cpp.

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

Referenced by creaImageIO::SQLiteTreeHandler::DBCreate(), and 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:

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

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(), GetLabel(), GetLevelDescriptor(), GimmickDebugMessage, and 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::Node::Print ( ) const
virtual

Print the node.

Reimplemented in creaImageIO::tree::Tree.

Definition at line 224 of file creaImageIOTreeNode.cpp.

References GetChildrenList(), GetLabel(), GetLevel(), and GimmickMessage.

225  {
226  std::string mess;
227  for (int i = 0; i<GetLevel(); ++i) mess += " ";
228  mess += "|_ " + GetLabel();
229  GimmickMessage(1,mess<<std::endl);
230  ChildrenListType::const_iterator j;
231  for (j=GetChildrenList().begin(); j!=GetChildrenList().end(); j++)
232  {
233  (*j)->Print();
234  }
235  }

Here is the call graph for this function:

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

Remove the given children from the children list.

Definition at line 158 of file creaImageIOTreeNode.cpp.

References 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 
)

Set an Attribute for a specific key.

Definition at line 188 of file creaImageIOTreeNode.cpp.

References 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)
inline

Sets the node's children.

Definition at line 105 of file creaImageIOTreeNode.h.

References 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)
inline

Sets the node data. Deletes existing data if any.

Definition at line 149 of file creaImageIOTreeNode.h.

References mData.

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

Sorts the children of the node.

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

Set an Attribute for a specific key(unsafe mode)

Definition at line 135 of file creaImageIOTreeNode.h.

References mAttributeMap.

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

136  { mAttributeMap[k] = v; }

Here is the caller graph for this function:

Member Data Documentation

AttributeMapType creaImageIO::tree::Node::mAttributeMap
private

The map of attributes.

Definition at line 167 of file creaImageIOTreeNode.h.

Referenced by GetAttribute(), GetAttributeMap(), GetLabel(), Matches(), SetAttribute(), and UnsafeSetAttribute().

ChildrenListType creaImageIO::tree::Node::mChildren
private

The list of children.

Definition at line 165 of file creaImageIOTreeNode.h.

Referenced by GetChildrenList(), and GetNumberOfChildren().

bool creaImageIO::tree::Node::mChildrenLoaded
private

Are the children loaded ?

Definition at line 171 of file creaImageIOTreeNode.h.

Referenced by GetChildrenLoaded(), and SetChildrenLoaded().

boost::shared_ptr<NodeData> creaImageIO::tree::Node::mData
private

User data.

Definition at line 169 of file creaImageIOTreeNode.h.

Referenced by GetData(), Node(), SetData(), and ~Node().

Node* creaImageIO::tree::Node::mParent
private

The parent of the node.

Definition at line 163 of file creaImageIOTreeNode.h.

Referenced by GetLevel(), GetParent(), and GetTree().


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