00001
00002
00003 #include "Iguana/Studio/interface/IgDocumentData.h"
00004 #include "Iguana/Framework/interface/IgDocumentDataRoot.h"
00005 #include "Iguana/Framework/interface/IgTwig.h"
00006
00007
00008
00009
00010
00011
00012
00013
00014 IG_DEFINE_STATE_ELEMENT (IgDocumentData, "Services/Studio/Document Data");
00015
00016
00017
00018
00019
00020 IgDocumentData::IgDocumentData (IgState *state, IgDocument *owner)
00021 : m_state (state),
00022 m_document (owner)
00023 {
00024 ASSERT (m_state);
00025
00026
00027
00028 m_state->put (s_key, this);
00029 }
00030
00031 IgDocumentData::~IgDocumentData (void)
00032 {
00033 ASSERT (m_state);
00034
00035
00036
00037 for (TwigMap::iterator i = m_rootMap.begin ();
00038 i != m_rootMap.end ();
00039 i++)
00040 {
00041 delete i->second;
00042 }
00043
00044 m_state->detach (s_key);
00045 }
00046
00047 IgDocument *
00048 IgDocumentData::document (void)
00049 {
00050 ASSERT (m_state);
00051 ASSERT (m_document);
00052
00053 return m_document;
00054 }
00055
00056
00057 IgSimpleTwig *
00058 IgDocumentData::root (const std::string &name , bool create)
00059 {
00060 ASSERT (m_state);
00061
00062
00063
00064
00065 std::string n = name;
00066 if (n.size () == 0)
00067 n = IgDocumentDataRoot::getCurrentRoot ();
00068
00069 TwigMap::iterator i = m_rootMap.find (n);
00070
00071 if (i == m_rootMap.end ())
00072 {
00073 IgSimpleTwig *twig = 0;
00074
00075 if (create)
00076 {
00077 twig = new IgSimpleTwig ("Objects");
00078 m_rootMap[n] = twig;
00079 }
00080 return twig;
00081 }
00082 return i->second;
00083 }
00084
00085 void
00086 IgDocumentData::root (IgSimpleTwig *twig,
00087 const std::string &rootName )
00088 {
00089 ASSERT (twig);
00090 std::string n = rootName;
00091 if (n.size () == 0)
00092 n = IgDocumentDataRoot::getCurrentRoot ();
00093 m_rootMap[n] = twig;
00094 }
00095
00096 IgSimpleTwig *
00097 IgDocumentData::add (const std::string &name, const std::string &rootName)
00098 {
00099
00100
00101 ASSERT (m_state);
00102
00103
00104
00105 return new IgSimpleTwig (root (rootName, true), name);
00106 }
00107
00108 IgTwig *
00109 IgDocumentData::find (const std::string &name, const std::string &rootName)
00110 {
00111
00112
00113
00114
00115
00116 ASSERT (m_state);
00117
00118
00119 IgSimpleTwig *parent = root (rootName, true);
00120 for (unsigned i = 0; i < parent->children (); ++i)
00121 {
00122 IgTwig *child = parent->child (i);
00123 if (child->name () == name)
00124 return child;
00125 }
00126 return 0;
00127 }
00128
00129 IgDocumentData::TwigMap::const_iterator
00130 IgDocumentData::begin (void)
00131 {
00132 return m_rootMap.begin ();
00133 }
00134
00135 IgDocumentData::TwigMap::const_iterator
00136 IgDocumentData::end (void)
00137 {
00138 return m_rootMap.end ();
00139 }