00001 #ifndef IGUANA_FRAMEWORK_IG_TWIG_H
00002 # define IGUANA_FRAMEWORK_IG_TWIG_H
00003
00004
00005
00006 # include "Iguana/Framework/interface/config.h"
00007 # include "Iguana/Framework/interface/IgRepresentable.h"
00008 # include <classlib/utils/Callback.h>
00009 # include <string>
00010 # include <utility>
00011 # include <vector>
00012 # include <map>
00013
00014
00015
00016
00017
00018 class IgDatum;
00019
00020
00021
00022
00023
00024 class IGUANA_FRAMEWORK_API IgTwig : public IgRepresentable
00025 {
00026 public:
00032 static const int STRUCTURE_MASK = 1;
00033
00038 static const int SELF_MASK = 2;
00039
00047 static const int FLAGS_MASK = 4;
00048
00049 typedef lat::Callback1<IgDatum *&> Getter;
00050 typedef lat::Callback1<const IgDatum *> Setter;
00051 typedef std::pair<Getter,Setter> GetSetPair;
00052 typedef std::map<std::string, GetSetPair> Attributes;
00053
00054 IgTwig (IgTwig *parent = 0);
00055 ~IgTwig (void);
00056
00057
00058 virtual IgTwig * root (void) const;
00059 virtual IgTwig * parent (void) const;
00060 virtual unsigned children (void);
00061 virtual IgTwig * child (unsigned index);
00062 virtual unsigned indexOf (const IgTwig *child) const;
00063 IgTwig * lookup (const std::string &path);
00064
00065 virtual bool expand (void);
00066 virtual void add (IgTwig *child);
00067 virtual void remove (IgTwig *child);
00068 virtual void destroy (void);
00069 virtual void clear (void);
00070
00071
00072 virtual std::string name (void) const = 0;
00073 virtual void name (const std::string &name) = 0;
00074
00075 virtual std::string fullName (void);
00076
00077 virtual bool traverse (void) const;
00078 virtual bool selfTraverse (void) const = 0;
00079 virtual void selfTraverse (bool value) = 0;
00080
00081 virtual bool visible (void) const;
00082 virtual bool selfVisible (void) const = 0;
00083 virtual void selfVisible (bool value) = 0;
00084
00085 virtual bool cascade (void) const = 0;
00086 virtual void cascade (bool value) = 0;
00087
00088
00089 virtual void attributes (Attributes &attrs);
00090
00091 public:
00092
00093 virtual void added (IgTwig *parent);
00094 virtual void removed (IgTwig *parent);
00095 virtual void cleared (IgTwig *parent);
00096
00097 private:
00098 void getNameAttribute (IgDatum *&result);
00099 void getTraverseAttribute (IgDatum *&result);
00100 void getVisibleAttribute (IgDatum *&result);
00101 void getCascadeAttribute (IgDatum *&result);
00102
00103 void setNameAttribute (const IgDatum *value);
00104 void setTraverseAttribute (const IgDatum *value);
00105 void setVisibleAttribute (const IgDatum *value);
00106 void setCascadeAttribute (const IgDatum *value);
00107
00108 IgTwig *m_parent;
00109
00110 static const char s_name[];
00111 static const char s_traverse[];
00112 static const char s_visible[];
00113 static const char s_cascade[];
00114
00115
00116 IgTwig (const IgTwig &);
00117 IgTwig &operator= (const IgTwig &);
00118 };
00119
00120 class IGUANA_FRAMEWORK_API IgCompoundTwig : public IgTwig
00121 {
00122 public:
00123 IgCompoundTwig (IgTwig *parent = 0, unsigned sizeEstimate = 0);
00124 ~IgCompoundTwig (void);
00125
00126 virtual unsigned children (void);
00127 virtual IgTwig * child (unsigned index);
00128 virtual unsigned indexOf (const IgTwig *child) const;
00129
00130 virtual bool expand (void);
00131 virtual void add (IgTwig *child);
00132 virtual void remove (IgTwig *child);
00133 virtual void destroy (void);
00134 virtual void clear (void);
00135
00136 protected:
00137 static const unsigned int EXPANDED = 1;
00138
00139 unsigned flags (void) const;
00140 void flags (unsigned value);
00141 bool flag (unsigned n) const;
00142 void flag (unsigned n, bool value);
00143
00144 private:
00145 std::vector<IgTwig *> m_children;
00146 unsigned m_flags;
00147 };
00148
00149 class IGUANA_FRAMEWORK_API IgSimpleTwig : public IgCompoundTwig
00150 {
00151 public:
00152 explicit
00153 IgSimpleTwig (IgTwig *parent, const std::string &name = "",
00154 bool traverse = true, bool visible = true,
00155 bool cascade = true);
00156
00157 explicit
00158 IgSimpleTwig (const std::string &name,
00159 bool traverse = true, bool visible = true,
00160 bool cascade = true);
00161
00162
00163 virtual std::string name (void) const;
00164 virtual void name (const std::string &name);
00165
00166 virtual bool selfTraverse (void) const;
00167 virtual void selfTraverse (bool value);
00168
00169 virtual bool selfVisible (void) const;
00170 virtual void selfVisible (bool value);
00171
00172 virtual bool cascade (void) const;
00173 virtual void cascade (bool value);
00174
00175 protected:
00176 static const unsigned int TRAVERSE = 2;
00177 static const unsigned int VISIBLE = 4;
00178 static const unsigned int CASCADE = 8;
00179
00180 private:
00181 std::string m_name;
00182 };
00183
00184
00185
00186
00187 inline bool
00188 IgCompoundTwig::flag (unsigned n) const
00189 { return m_flags & n; }
00190
00191 inline void
00192 IgCompoundTwig::flag (unsigned n, bool value)
00193 { m_flags = (m_flags & ~n) | (value * n); }
00194
00195 inline unsigned
00196 IgCompoundTwig::flags (void) const
00197 { return m_flags; }
00198
00199 inline void
00200 IgCompoundTwig::flags (unsigned value)
00201 { m_flags = value; }
00202
00203 #endif // IGUANA_FRAMEWORK_IG_TWIG_H