1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef _MYX_GRT_WALKER_H_
#define _MYX_GRT_WALKER_H_
// XXX TODO get rid of this or rewrite to remove the macro-fest
#include "grtpp.h"
//#include <stack>
#include <deque>
#include <gmodule.h>
#include "grtpp_util.h"
#include "grts/structs.h"
#include "grts/structs.workbench.physical.h"
#include "grts/structs.model.h"
#include "grts/structs.workbench.logical.h"
namespace bec {
typedef std::deque<GrtObjectRef> CallStack;
template <class T>
struct CatalogIterator
{
typedef int (T::*CGrtCb)(const GrtObjectRef &);
typedef boost::function<int (GrtObjectRef)> CGrtSlot;
std::vector<CGrtSlot> allTypesSlots;
void append_allTypesCb(T* self, CGrtCb cb) {allTypesSlots.push_back(boost::bind(cb, self, _1));}
#define WB_ITERATOR_SUPPORT_OBJECT_TYPE(type) \
typedef int (T::*C##type##Cb)(const grt::Ref<type>&); \
typedef boost::function<int (grt::Ref<type>) > C##type##Slot; \
std::vector<C##type##Slot> type##Slots;\
std::vector<CGrtSlot> type##GrtSlots;\
void append(T* self, C##type##Cb cb) {type##Slots.push_back(boost::bind(cb, self, _1));}\
void append_##type##GrtCb(T* self, CGrtCb cb) {type##GrtSlots.push_back(boost::bind(cb, self, _1));}
/*
typedef int (T::*Cdb_TableCb)(db_Table);
typedef boost::function<int (db_Table)> Cdb_TableSlot;
std::vector<Cdb_TableSlot> db_TableSlots;
std::vector<CGrtSlot> db_TableGrtSlots;
void append(Cdb_TableCbRef cb) {db_TableSlots.push_back(Cdb_TableSlot(cb));}
void append_db_TableGrtCb(CGrtCb cb) {db_TableGrtSlots.push_back(CGrtSlot(cb));}
*/
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_Schema);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_Table);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_Trigger);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_Column);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_Index);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_ForeignKey);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_View);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_Routine);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_RoutineGroup);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_Role);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_User);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(db_RolePrivilege);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(model_Layer);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(model_Object);
WB_ITERATOR_SUPPORT_OBJECT_TYPE(model_Diagram);
CallStack call_stack;
//std::stack<GrtObjectRef> call_stack; // myehorov: fix to enable compilation of wb_find_dialog
private:
//template<class TT>
//struct stack_item
//{
// std::stack<TT> &_stack;
// stack_item(TT &value, std::stack<TT> &_stack) :_stack(_stack) {_stack.push(value);}
// ~stack_item() {_stack.pop();}
//};
struct stack_item
{
CallStack &_stack;
stack_item(const GrtObjectRef &value, CallStack &_stack) :_stack(_stack) {_stack.push_back(value);}
~stack_item() {_stack.pop_back();}
};
public:
#define EXIST_CB(type) \
(!type##Slots.empty() || !type##GrtSlots.empty() || !allTypesSlots.empty())
#define CALL_CB(type,obj) \
{\
for(size_t i= 0, cb_count= type##Slots.size(); i < cb_count; i++)\
{\
res&= type##Slots[i](obj);\
if (!res && breakOnError)\
return res;\
}\
for(size_t i= 0, cb_count= type##GrtSlots.size(); i < cb_count; i++)\
{\
res&= type##GrtSlots[i](obj);\
if (!res && breakOnError)\
return res;\
}\
for(size_t i= 0, cb_count= allTypesSlots.size(); i < cb_count; i++)\
{\
res&= allTypesSlots[i](obj);\
if (!res && breakOnError)\
return res;\
}\
}
#define ITERATE_LIST(type,list,object) \
{\
grt::ListRef<type> list= object->list();\
if (EXIST_CB(type))\
for(size_t i= 0, count= list.count(); i < count; i++)\
{\
grt::Ref<type> item= list.get(i);\
CALL_CB(type, item);\
}\
}
#define ITERATE_LIST_DEEP(type,list,object) \
{\
grt::ListRef<type> list= object->list();\
/*if (EXIST_CB(type)) TODO ?? */ \
for(size_t i= 0, count= list.count(); i < count; i++)\
{\
grt::Ref<type> item= list.get(i);\
CALL_CB(type, item);\
res&= iterate(Self, item, breakOnError);\
if (!res && breakOnError)\
return res;\
}\
}
int iterate(T &Self, const workbench_logical_ModelRef &model, bool breakOnError= false, bool model_diagrams= true)
{
stack_item _centry(model, call_stack);
int res= 1;
if (model_diagrams)
{
res&= iterate_diagrams(Self, model, breakOnError);
if (!res && breakOnError)
return res;
}
return res;
}
int iterate(T &Self, const workbench_physical_ModelRef &model, bool breakOnError= false, bool model_diagrams= true)
{
stack_item _centry(model, call_stack);
int res= 1;
if (model_diagrams)
{
res&= iterate_diagrams(Self, model, breakOnError);
if (!res && breakOnError)
return res;
}
res&= iterate(Self, model->catalog(), breakOnError);
if (!res && breakOnError)
return res;
return res;
}
int iterate(T &Self, const model_ObjectRef &figure, bool breakOnError= false)
{
int res= 1;
stack_item _centry(figure, call_stack);
for(size_t i= 0, cb_count= allTypesSlots.size(); i < cb_count; i++)
{
res&= allTypesSlots[i](figure);
if (!res && breakOnError)
return res;
}
if (EXIST_CB(db_Table) && workbench_physical_TableFigureRef::can_wrap(figure))
{
workbench_physical_TableFigureRef table_figure(workbench_physical_TableFigureRef::cast_from(figure));
if (table_figure->table().is_valid())
{
CALL_CB(db_Table, table_figure->table());
res= iterate(Self, table_figure->table(), breakOnError);
if (!res && breakOnError)
return res;
}
}
if (EXIST_CB(db_View) && workbench_physical_ViewFigureRef::can_wrap(figure))
{
workbench_physical_ViewFigureRef view_figure(workbench_physical_ViewFigureRef::cast_from(figure));
if (view_figure->view().is_valid())
CALL_CB(db_View, view_figure->view());
}
if ((EXIST_CB(db_RoutineGroup) || EXIST_CB(db_Routine))
&& workbench_physical_RoutineGroupFigureRef::can_wrap(figure))
{
workbench_physical_RoutineGroupFigureRef rgroup_figure(workbench_physical_RoutineGroupFigureRef::cast_from(figure));
if (rgroup_figure->routineGroup().is_valid())
{
db_RoutineGroupRef routineGroup= rgroup_figure->routineGroup();
CALL_CB(db_RoutineGroup, routineGroup);
ITERATE_LIST(db_Routine, routines, rgroup_figure->routineGroup());
}
}
return res;
}
int iterate(T &Self, const model_DiagramRef &view, bool breakOnError= false)
{
stack_item _centry(view, call_stack);
int res= 1;
ITERATE_LIST(model_Layer, layers, view);
ITERATE_LIST_DEEP(model_Object, figures, view);
return res;
}
int iterate_diagrams(T &Self, const model_ModelRef &model, bool breakOnError= false)
{
stack_item _centry(model, call_stack);
int res= 1;
ITERATE_LIST_DEEP(model_Diagram, diagrams, model);
return res;
}
int iterate(T &Self, const db_TableRef &table, bool breakOnError= false)
{
if ( !EXIST_CB(db_Column)
&& !EXIST_CB(db_Index)
&& !EXIST_CB(db_ForeignKey)
&& !EXIST_CB(db_Trigger))
return 1;
stack_item _centry(table, call_stack);
int res= 1;
ITERATE_LIST(db_Column, columns, table);
ITERATE_LIST(db_Index, indices, table);
ITERATE_LIST(db_ForeignKey, foreignKeys, table);
ITERATE_LIST(db_Trigger, triggers, table);
return res;
}
int iterate(T &Self, const db_SchemaRef &schema, bool breakOnError= false)
{
stack_item _centry(schema, call_stack);
int res= 1;
ITERATE_LIST_DEEP(db_Table, tables, schema);
ITERATE_LIST(db_View, views, schema);
ITERATE_LIST(db_Routine, routines, schema);
ITERATE_LIST(db_RoutineGroup, routineGroups, schema);
return res;
}
int iterate(T &Self, const db_CatalogRef &catalog, bool breakOnError= false)
{
int res= 1;
stack_item _centry(catalog, call_stack);
ITERATE_LIST_DEEP(db_Schema, schemata, catalog);
ITERATE_LIST(db_User, users, catalog);
ITERATE_LIST_DEEP(db_Role, roles, catalog);
return res;
}
int iterate(T &Self, const db_RoleRef &role, bool breakOnError= false)
{
int res= 1;
stack_item _centry(role, call_stack);
ITERATE_LIST(db_RolePrivilege, privileges, role);
return res;
}
#define CASE_ITERATE(type) \
if (grt::Ref<type>::can_wrap(object))\
return iterate(Self, grt::Ref<type>::cast_from(object), breakOnError);
#define CASE_ITERATE_MODEL(type, model_diagrams) \
if (grt::Ref<type>::can_wrap(object))\
return iterate(Self, grt::Ref<type>::cast_from(object), breakOnError, model_diagrams);
int iterate(T &Self, const GrtObjectRef &object, bool breakOnError= false, bool model_diagrams= true)
{
stack_item _centry(object, call_stack);
CASE_ITERATE_MODEL(workbench_logical_Model, model_diagrams);
CASE_ITERATE_MODEL(workbench_physical_Model, model_diagrams);
CASE_ITERATE(model_Diagram);
CASE_ITERATE(model_Object);
CASE_ITERATE(db_Catalog);
CASE_ITERATE(db_Schema);
CASE_ITERATE(db_Table);
CASE_ITERATE(db_Role);
int res =1;
for(size_t i= 0, cb_count= allTypesSlots.size(); i < cb_count; i++)
{
res&= allTypesSlots[i](object);
if (!res && breakOnError)
return res;
}
return 1;
}
};
}
#endif /* _MYX_GRT_WALKER_H_ */
|