]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_statetreecontextinfoitem.h
Initial vogl checkin
[vogl] / src / vogleditor / vogleditor_statetreecontextinfoitem.h
1 #ifndef VOGLEDITOR_STATETREECONTEXTINFOITEM_H
2 #define VOGLEDITOR_STATETREECONTEXTINFOITEM_H
3
4 #include "vogleditor_statetreeitem.h"
5
6 class vogleditor_stateTreeContextInfoDiffableItem : public vogleditor_stateTreeItem
7 {
8 public:
9     vogleditor_stateTreeContextInfoDiffableItem(QString name, QString value, vogleditor_stateTreeItem* parent)
10         : vogleditor_stateTreeItem(name, value, parent),
11           m_pDiffBaseState(NULL)
12     {
13     }
14
15     void set_diff_base_state(const vogl_context_info* pBaseState) {
16         m_pDiffBaseState = pBaseState;
17     }
18
19     virtual bool hasChanged() const = 0;
20 protected:
21     const vogl_context_info* m_pDiffBaseState;
22 };
23
24 class vogleditor_stateTreeContextInfoBoolItem : public vogleditor_stateTreeContextInfoDiffableItem
25 {
26 public:
27     vogleditor_stateTreeContextInfoBoolItem(QString name, bool (vogl_context_info::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_context_info& info);
28     virtual ~vogleditor_stateTreeContextInfoBoolItem() { m_pState = NULL; }
29
30     const vogl_context_info* get_context_info() const { return m_pState; }
31     virtual bool hasChanged() const;
32     virtual QString getDiffedValue() const;
33
34 private:
35     const vogl_context_info* m_pState;
36     bool (vogl_context_info::* m_pFunc)(void) const;
37 };
38
39 class vogleditor_stateTreeContextInfoUIntItem : public vogleditor_stateTreeContextInfoDiffableItem
40 {
41 public:
42     vogleditor_stateTreeContextInfoUIntItem(QString name, uint (vogl_context_info::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_context_info& info);
43     virtual ~vogleditor_stateTreeContextInfoUIntItem() { m_pState = NULL; }
44
45     const vogl_context_info* get_context_info() const { return m_pState; }
46     virtual bool hasChanged() const;
47     virtual QString getDiffedValue() const;
48
49  private:
50     const vogl_context_info* m_pState;
51     uint (vogl_context_info::* m_pFunc)(void) const;
52 };
53
54
55 class vogleditor_stateTreeContextInfoStringItem : public vogleditor_stateTreeContextInfoDiffableItem
56 {
57 public:
58     vogleditor_stateTreeContextInfoStringItem(QString name, const vogl::dynamic_string& (vogl_context_info::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_context_info& info);
59     virtual ~vogleditor_stateTreeContextInfoStringItem() { m_pState = NULL;}
60
61     const vogl_context_info* get_context_info() const { return m_pState; }
62     virtual bool hasChanged() const;
63     virtual QString getDiffedValue() const;
64
65  private:
66     const vogl_context_info* m_pState;
67     dynamic_string m_value;
68     const vogl::dynamic_string& (vogl_context_info::* m_pFunc)(void) const;
69 };
70
71 class vogleditor_stateTreeContextInfoExtensionItem : public vogleditor_stateTreeContextInfoDiffableItem
72 {
73 public:
74     vogleditor_stateTreeContextInfoExtensionItem(QString name, const vogl::dynamic_string extensionName, vogleditor_stateTreeItem* parent, const vogl_context_info& info)
75         : vogleditor_stateTreeContextInfoDiffableItem(name, QString(extensionName.c_str()), parent),
76           m_pState(&info),
77           m_extensionName(extensionName)
78     {
79         setValue(QString(extensionName.c_str()));
80     }
81
82     virtual ~vogleditor_stateTreeContextInfoExtensionItem() { m_pState = NULL; }
83
84     const vogl_context_info* get_context_info() const { return m_pState; }
85     virtual bool hasChanged() const
86     {
87         if (m_pDiffBaseState == NULL)
88         {
89             return false;
90         }
91
92         // if the current extension is in the base list, then don't flag this as having changed
93         const dynamic_string_array& baseExtensions = m_pDiffBaseState->get_extensions();
94         for (const vogl::dynamic_string* iter = baseExtensions.begin(); iter != baseExtensions.end(); iter++)
95         {
96             if ((*iter) == m_extensionName)
97             {
98                 return false;
99             }
100         }
101
102         // if we've made it through the entire list, then this extension was not in the base context, so it is new (has changed).
103         return true;
104     }
105
106     // if an extension shows up as having changed, that means it didn't exist in the previous snapshot
107     virtual QString getDiffedValue() const { return "non-existent"; }
108
109  private:
110     const vogl_context_info* m_pState;
111     dynamic_string m_extensionName;
112 };
113
114 class vogleditor_stateTreeContextInfoItem : public vogleditor_stateTreeItem
115 {
116 public:
117     vogleditor_stateTreeContextInfoItem(QString name, QString value, vogleditor_stateTreeItem* parent, const vogl_context_info& info);
118     virtual ~vogleditor_stateTreeContextInfoItem()
119     {
120         m_pState = NULL; m_pDiffBaseState = NULL;
121     }
122
123     const vogl_context_info* get_context_info() const { return m_pState; }
124
125     void set_diff_base_state(const vogl_context_info* pBaseState) {
126         m_pDiffBaseState = pBaseState;
127         for (vogleditor_stateTreeContextInfoDiffableItem** iter = m_diffableItems.begin(); iter != m_diffableItems.end(); iter++)
128         {
129             (*iter)->set_diff_base_state(pBaseState);
130         }
131     }
132     virtual bool hasChanged() const;
133
134  private:
135     const vogl_context_info* m_pState;
136     const vogl_context_info* m_pDiffBaseState;
137     vogl::vector<vogleditor_stateTreeContextInfoDiffableItem*> m_diffableItems;
138 };
139
140 #endif // VOGLEDITOR_STATETREECONTEXTINFOITEM_H