Public Types | Public Member Functions | Private Attributes

creaImageIO::tree::Node Class Reference

Node of an attributed Tree structure. More...

#include <creaImageIOTreeNode.h>

Inheritance diagram for creaImageIO::tree::Node:
Inheritance graph
[legend]
Collaboration diagram for creaImageIO::tree::Node:
Collaboration graph
[legend]

List of all members.

Public Types

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

Public Member Functions

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

Private Attributes

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

Detailed Description

Node of an attributed Tree structure.

Definition at line 36 of file creaImageIOTreeNode.h.


Member Typedef Documentation

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

Definition at line 39 of file creaImageIOTreeNode.h.

The type of children container.

Definition at line 80 of file creaImageIOTreeNode.h.


Constructor & Destructor Documentation

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

Ctor with parent.

Definition at line 14 of file creaImageIOTreeNode.cpp.

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

      : mParent(parent),//mData(0),
        mChildrenLoaded(false)
    {
        mData.reset();
      if (parent) 
        {
          GimmickDebugMessage(6,"Default Node constructor (level "<<GetLevel()<<")"
                         << std::endl);
          // Insert into parent's children list
          InitializeAttributeMap();
         parent->GetChildrenList().push_back(this);
        }
      else
        {
          GimmickDebugMessage(6,"Default Node constructor without parent"       
                         << std::endl);
        }
    }

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 37 of file creaImageIOTreeNode.cpp.

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

     : mParent(parent),//mData(0),
        mChildrenLoaded(false)
    {
        mData.reset();
      GimmickDebugMessage(6,"Node constructor (level "<<GetLevel()<<")"
                     << std::endl);

     if (parent) 
        {
          // Insert into parent's children list
          parent->GetChildrenList().push_back(this);
          // Initialize attributes
          LevelDescriptor::AttributeDescriptorListType::const_iterator a;
          for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
               a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
               ++a)
            {
              std::string v;
              AttributeMapType::const_iterator i = attr.find(a->GetKey());
              if ( i != attr.end() )  
                {
                  v = i->second;
                }
              GimmickDebugMessage(6,"Setting attribute '"<<a->GetName()<<"' = '"
                             <<v<<"'"<<std::endl);
              UnsafeSetAttribute( a->GetKey(), v );
            }
        }
      
    }

Here is the call graph for this function:

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

Virtual destructor.

Definition at line 72 of file creaImageIOTreeNode.cpp.

References GetChildrenList(), GimmickDebugMessage, and mData.

    {
      GimmickDebugMessage(6,"Node destructor"
                     << std::endl);
      ChildrenListType::iterator i;
      for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
        {
          delete *i;
        }
        mData.reset();
    }

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 145 of file creaImageIOTreeNode.cpp.

References mAttributeMap.

Referenced by 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::TreeHandlerImageAdder::remove(), creaImageIO::TimestampDatabaseHandler::RemoveNode(), creaImageIO::GimmickView::RequestReading(), and creaImageIO::WxEditFieldsPanel::WxEditFieldsPanel().

    {
      //    std::cout << "this = "<<(void*)this<<std::endl;
      //    std::cout << "mFieldValueMap="<<(void*)(&mFieldValueMap)<<std::endl;
      AttributeMapType::const_iterator i = mAttributeMap.find(k);
      if (i == mAttributeMap.end())
        {
          static std::string def("");
          return def;
          //    CREAIMAGEIO_ERROR("DicomNode::GetFieldValue : no field with key '"<<k<<"'");
        }
      return i->second;
  }

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 112 of file creaImageIOTreeNode.cpp.

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

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

        {
                LevelDescriptor::AttributeDescriptorListType::const_iterator a;
      for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
           a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
           ++a)
                {
                
                        if(a->GetKey()==k)
                        {
                                return *a;
                        }
                
                }
                return *a;
        }

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 91 of file creaImageIOTreeNode.h.

References mAttributeMap.

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

{ 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 94 of file creaImageIOTreeNode.h.

References mAttributeMap.

{ return mAttributeMap; }

const ChildrenListType& creaImageIO::tree::Node::GetChildrenList (  )  const [inline]

Returns the list of children (const).

Definition at line 84 of file creaImageIOTreeNode.h.

References mChildren.

{ return mChildren; }

ChildrenListType& creaImageIO::tree::Node::GetChildrenList (  )  [inline]
bool creaImageIO::tree::Node::GetChildrenLoaded (  )  const [inline]

Returns true iff the node's children are loaded.

Definition at line 74 of file creaImageIOTreeNode.h.

References mChildrenLoaded.

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

{ 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 117 of file creaImageIOTreeNode.h.

References mData.

      { 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 212 of file creaImageIOTreeNode.cpp.

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

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

    {
      std::string l;
      const std::vector<std::string>& label 
        = GetLevelDescriptor().GetLabelList();
      
      std::vector<std::string>::const_iterator i;
      for (i = label.begin(); i != label.end(); )
        {
          GimmickDebugMessage(9,"LABEL '"<<*i<<"'"<<std::endl);
          AttributeMapType::const_iterator j = mAttributeMap.find(*i);
          if (j != mAttributeMap.end())
            {
              l += j->second;
              ++i;
              if (i != label.end()) l += "|";
            }
          else 
            {
              GimmickError("Node::GetLabel() : LABEL attribute '"
                           <<*i
                           <<"' is not in node attribute map (should be!)" );
            }
        }
      if (l.size()==0) l="?";
      return l;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual int creaImageIO::tree::Node::GetLevel (  )  const [inline, virtual]
const LevelDescriptor & creaImageIO::tree::Node::GetLevelDescriptor (  )  const

Returns the level descriptor of the node.

Definition at line 103 of file creaImageIOTreeNode.cpp.

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

Referenced by GetLabel(), and Matches().

    { 
      return GetTree()->GetLevelDescriptor(GetLevel()); 
    }

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 71 of file creaImageIOTreeNode.h.

References mChildren.

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

{ return 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 65 of file creaImageIOTreeNode.h.

References mParent.

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

{ return mParent; }

Here is the caller graph for this function:

virtual const Tree* creaImageIO::tree::Node::GetTree (  )  const [inline, virtual]

Returns the tree to which the node belongs.

Reimplemented in creaImageIO::tree::Tree.

Definition at line 59 of file creaImageIOTreeNode.h.

References GetTree(), and mParent.

{ return mParent->GetTree(); }

Here is the call graph for this function:

virtual Tree* creaImageIO::tree::Node::GetTree (  )  [inline, virtual]

Returns the tree to which the node belongs.

Reimplemented in creaImageIO::tree::Tree.

Definition at line 57 of file creaImageIOTreeNode.h.

References GetTree(), and mParent.

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

{ return mParent->GetTree(); }

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Definition at line 88 of file creaImageIOTreeNode.cpp.

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

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

    {
      // Initialize attributes
      LevelDescriptor::AttributeDescriptorListType::const_iterator a;
      for (a = GetTree()->GetAttributeDescriptorList(GetLevel()).begin();
           a!= GetTree()->GetAttributeDescriptorList(GetLevel()).end();
           ++a)
        {
          UnsafeSetAttribute( a->GetKey(), "" );
        }
    }

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 177 of file creaImageIOTreeNode.cpp.

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

    {
      GimmickDebugMessage(2,"'"<<GetLabel()<<"' matching..."<<std::endl);
      const std::vector<std::string>& id 
        = GetLevelDescriptor().GetIdentifierList();
      std::vector<std::string>::const_iterator i;
      for (i = id.begin(); i != id.end(); ++i)
        {
          if (mAttributeMap.find(*i)->second != m.find(*i)->second ) 
            {
              GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values do not match"<<std::endl);
              return false;
            }
          GimmickDebugMessage(2,"IDENTIFIER '"<<*i<<"' values match"<<std::endl);
        }
      return true;
    }

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 197 of file creaImageIOTreeNode.cpp.

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

    {
      std::string mess;
      for (int i = 0; i<GetLevel(); ++i) mess += "  ";
      mess += "|_ " + GetLabel();
      GimmickMessage(1,mess<<std::endl);
      ChildrenListType::const_iterator j;
      for (j=GetChildrenList().begin(); j!=GetChildrenList().end(); j++)
        {
          (*j)->Print();
        } 
    }

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 131 of file creaImageIOTreeNode.cpp.

References GetChildrenList().

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

    {
      ChildrenListType::iterator i = find(GetChildrenList().begin(),
                                          GetChildrenList().end(),
                                          node);
      if (i != GetChildrenList().end())
        {
          GetChildrenList().erase(i);
        }
        return GetChildrenList().size();
    }

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 161 of file creaImageIOTreeNode.cpp.

References mAttributeMap.

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

  {
    AttributeMapType::iterator i = mAttributeMap.find(k);
    if (i==mAttributeMap.end())
      {
        std::cout<<"[Gimmick!] Node::SetAttribute : no attribute with key '"
                 <<k<<"'"<<std::endl;
        creaError( "[Gimmick!] Node::SetAttribute : no attribute with key '"
                   <<k<<"'");
      }
    i->second = v;
  }

Here is the caller graph for this function:

void creaImageIO::tree::Node::SetChildrenLoaded ( bool  l  )  [inline]

Sets the node's children.

Definition at line 77 of file creaImageIOTreeNode.h.

References mChildrenLoaded.

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

{ 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 121 of file creaImageIOTreeNode.h.

References mData.

{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 107 of file creaImageIOTreeNode.h.

References mAttributeMap.

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

      { mAttributeMap[k] = v; }

Here is the caller graph for this function:


Member Data Documentation

The map of attributes.

Definition at line 139 of file creaImageIOTreeNode.h.

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

The list of children.

Definition at line 137 of file creaImageIOTreeNode.h.

Referenced by GetChildrenList(), and GetNumberOfChildren().

Are the children loaded ?

Definition at line 143 of file creaImageIOTreeNode.h.

Referenced by GetChildrenLoaded(), and SetChildrenLoaded().

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

User data.

Definition at line 141 of file creaImageIOTreeNode.h.

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

The parent of the node.

Definition at line 135 of file creaImageIOTreeNode.h.

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


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