Changeset 1755
- Timestamp:
- 01/14/10 17:22:19 (2 years ago)
- Files:
-
- branches/qt_gui/src/info/lib/info_group.cc (modified) (14 diffs)
- branches/qt_gui/src/info/lib/info_group.hh (modified) (4 diffs)
- branches/qt_gui/src/info/lib/info_handle.cc (modified) (1 diff)
- branches/qt_gui/src/info/lib/info_handle.hh (modified) (2 diffs)
- branches/qt_gui/src/info/pymod/wrap_info.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/qt_gui/src/info/lib/info_group.cc
r1744 r1755 23 23 namespace iplt { namespace info { 24 24 25 26 25 27 InfoGroup::InfoGroup(const InfoHandle& root, const ElePtr& impl): 26 28 root_(root), … … 45 47 46 48 47 InfoGroup InfoGroup::GetGroup(const InfoPath& path ) const49 InfoGroup InfoGroup::GetGroup(const InfoPath& path, bool use_defaults) const 48 50 { 49 51 std::vector<string> plist=path.GetList(); … … 54 56 return last_group; 55 57 } else { 56 if(root_.HasDefaultGroup(path) ) {58 if(root_.HasDefaultGroup(path) && use_defaults) { 57 59 // TODO: prepend path to this group 58 60 return root_.GetDefaultGroup(path); … … 90 92 } 91 93 92 bool InfoGroup::HasGroup(const InfoPath& path ) const94 bool InfoGroup::HasGroup(const InfoPath& path, bool use_defaults) const 93 95 { 94 96 std::vector<string> plist=path.GetList(); … … 98 100 if(do_group_lookup(pos,plist.end(),last_group)) { 99 101 return true; 100 } else {102 } else if(use_defaults){ 101 103 // TODO: prepend path to this group 102 104 return root_.HasDefaultGroup(path); … … 106 108 107 109 InfoGroup InfoGroup::group_create(InfoGroup group, 108 std::vector<string>::const_iterator& pos,109 const std::vector<string>::const_iterator& end)110 std::vector<string>::const_iterator& pos, 111 const std::vector<string>::const_iterator& end) 110 112 { 111 113 InfoGroup subgroup = group.CreateGroup((*pos)); … … 115 117 } 116 118 117 InfoGroup InfoGroup::RetrieveGroup(const InfoPath& path) 118 { 119 std::vector<string> plist=path.GetList(); 120 if(plist.empty()) return *this; 121 std::vector<string>::const_iterator pos=plist.begin(); 122 InfoGroup last_group(*this); 123 bool ret=do_group_lookup(pos,plist.end(),last_group); 124 if(ret) { 125 return last_group; 119 InfoGroup InfoGroup::RetrieveGroup(const InfoPath& path, bool use_defaults) 120 { 121 if(HasGroup(path,use_defaults)) { 122 return GetGroup(path); 126 123 } else { 127 return group_create(last_group,pos,plist.end()); 128 } 129 124 std::vector<string> plist=path.GetList(); 125 InfoGroup last_group(*this); 126 std::vector<string>::const_iterator pos=plist.begin(); 127 bool ret=do_group_lookup(pos,plist.end(),last_group); 128 if(ret) { 129 return last_group; 130 } else { 131 return group_create(last_group,pos,plist.end()); 132 } 133 } 130 134 } 131 135 … … 145 149 tp=IT_BOOL; 146 150 } else if(tps=="vector" || tps=="VECTOR") { 147 tp=IT_VECTOR;151 tp=IT_VECTOR; 148 152 } else { 149 153 // keep string default, alternatively could throw error here... … … 155 159 } 156 160 157 InfoItem InfoGroup::GetItem(const InfoPath& path ) const161 InfoItem InfoGroup::GetItem(const InfoPath& path, bool use_defaults) const 158 162 { 159 163 InfoGroup grp=*this; 160 161 164 InfoPath grppath=path.Strip(); 162 163 165 std::vector<string> plist=grppath.GetList(); 164 165 166 std::vector<string>::const_iterator pos=plist.begin(); 166 167 167 string iname=path.GetList().back(); 168 169 168 InfoGroup last_group(*this); 170 169 if(do_group_lookup(pos,plist.end(),last_group)) { … … 173 172 ElePtr p(last_group.impl_->GetSub(iname)); 174 173 if(!p->HasAttribute("value")) { 175 throw InfoError(string("requested item '") + iname + string("' has not value attribute"));174 throw InfoError(string("requested item '") + iname + string("' has not value attribute")); 176 175 } 177 176 return InfoItem(root_,p,ResolveItemType(p)); … … 181 180 // check default 182 181 // TODO: prepend path to this group 183 if( root_.HasDefaultItem(path)) {182 if(use_defaults && root_.HasDefaultItem(path)) { 184 183 return root_.GetDefaultItem(path); 185 184 } … … 194 193 } 195 194 196 bool InfoGroup::HasItem(const InfoPath& path ) const195 bool InfoGroup::HasItem(const InfoPath& path, bool use_defaults) const 197 196 { 198 197 InfoGroup grp=*this; 199 200 198 InfoPath grppath=path.Strip(); 201 202 199 std::vector<string> plist=grppath.GetList(); 203 204 200 std::vector<string>::const_iterator pos=plist.begin(); 205 206 201 InfoGroup last_group(*this); 207 202 if(do_group_lookup(pos,plist.end(),last_group)) { … … 210 205 ElePtr p(last_group.impl_->GetSub(iname)); 211 206 if(p->HasAttribute("value")) { 212 return true;207 return true; 213 208 } 214 209 } 215 210 } 216 217 211 // fallback to default item 218 return root_.HasDefaultItem(path); 219 } 220 221 InfoItem InfoGroup::RetrieveItem(const InfoPath& path) 212 if(use_defaults){ 213 return root_.HasDefaultItem(path); 214 } 215 return false; 216 } 217 218 InfoItem InfoGroup::RetrieveItem(const InfoPath& path, bool use_defaults) 222 219 { 223 220 string item=path.GetList().back(); 224 221 225 InfoGroup grp = RetrieveGroup(path.Strip() );222 InfoGroup grp = RetrieveGroup(path.Strip(),use_defaults); 226 223 227 if(grp.HasItem(item )) {224 if(grp.HasItem(item,use_defaults)) { 228 225 return grp.GetItem(item); 229 226 } else { … … 232 229 } 233 230 234 void InfoGroup::Remove(const InfoPath& path) 235 { 236 std::vector<string> plist=path.GetList(); 237 std::vector<string>::const_iterator pos=plist.begin(); 238 if(plist.empty()){ 239 return; 240 } 241 InfoGroup last_group(*this); 242 if(do_group_lookup(pos,plist.end(),last_group)) { 243 InfoGroup p=last_group.GetParent(); 244 p.impl_->RemoveSub(last_group.GetName()); 245 } 231 void InfoGroup::Remove(const InfoPath& path, bool remove_defaults) 232 { 233 InfoGroup g=GetGroup(path,remove_defaults); 234 InfoGroup p=g.GetParent(); 235 p.impl_->RemoveSub(g.GetName()); 246 236 } 247 237 branches/qt_gui/src/info/lib/info_group.hh
r1677 r1755 23 23 #include <iplt/base.hh> 24 24 25 #include "info_fw.hh"26 25 #include "info_handle.hh" 27 26 #include "info_impl_fw.hh" … … 29 28 namespace iplt { namespace info { 30 29 31 class DLLEXPORT InfoGroup {30 class DLLEXPORT InfoGroup{ 32 31 friend class InfoHandle; // ctor access 33 32 friend class InfoItem; // ctor access … … 36 35 //! retrieve parent group 37 36 InfoGroup GetParent() const; 38 39 37 //! set name 40 38 void SetName(const string& name); 41 39 //! retrieve name 42 40 string GetName() const; 43 44 InfoGroup GetGroup(const InfoPath& path) const; 41 InfoGroup GetGroup(const InfoPath& path, bool use_defaults=true) const; 45 42 InfoGroup CreateGroup(const string& name); 46 bool HasGroup(const InfoPath& name) const; 47 InfoGroup RetrieveGroup(const InfoPath& path); 48 49 InfoItem GetItem(const InfoPath& path) const; 43 bool HasGroup(const InfoPath& name, bool use_defaults=true) const; 44 InfoGroup RetrieveGroup(const InfoPath& path, bool use_defaults=true); 45 InfoItem GetItem(const InfoPath& path, bool use_defaults=true) const; 50 46 InfoItem CreateItem(const string& name, const string& value); 51 bool HasItem(const InfoPath& path) const; 52 InfoItem RetrieveItem(const InfoPath& path); 53 54 void Remove(const InfoPath& path); 55 47 bool HasItem(const InfoPath& path, bool use_defaults=true) const; 48 InfoItem RetrieveItem(const InfoPath& path, bool use_defaults=true); 49 void Remove(const InfoPath& path, bool remove_defaults=false); 56 50 //! return attribute of given name 57 51 string GetAttribute(const string& name) const; … … 62 56 //! remove attribute of given name 63 57 void RemoveAttribute(const string& name); 64 65 58 std::vector<string> GetAttributeList() const; 66 67 59 string GetTextData() const; 68 60 void SetTextData(const string& td); 69 70 61 //! Apply visitor 71 62 /*! branches/qt_gui/src/info/lib/info_handle.cc
r1754 r1755 126 126 } 127 127 128 InfoGroup InfoHandle::GetParent() const 129 { 130 return Root().GetParent(); 131 } 132 133 void InfoHandle::SetName(const string& name) 134 { 135 Root().SetName(name); 136 } 137 138 string InfoHandle::GetName() const 139 { 140 return Root().GetName(); 141 } 142 143 InfoGroup InfoHandle::GetGroup(const InfoPath& path, bool use_defaults) const 144 { 145 return Root().GetGroup(path,use_defaults); 146 } 147 148 InfoGroup InfoHandle::CreateGroup(const string& name) 149 { 150 return Root().CreateGroup(name); 151 } 152 153 bool InfoHandle::HasGroup(const InfoPath& name, bool use_defaults) const 154 { 155 return Root().HasGroup(name,use_defaults); 156 } 157 158 InfoGroup InfoHandle::RetrieveGroup(const InfoPath& path, bool use_defaults) 159 { 160 return Root().RetrieveGroup(path,use_defaults); 161 } 162 163 InfoItem InfoHandle::GetItem(const InfoPath& path, bool use_defaults) const 164 { 165 return Root().GetItem(path,use_defaults); 166 } 167 168 InfoItem InfoHandle::CreateItem(const string& name, const string& value) 169 { 170 return Root().CreateItem(name,value); 171 } 172 173 bool InfoHandle::HasItem(const InfoPath& path, bool use_defaults) const 174 { 175 return Root().HasItem(path,use_defaults); 176 } 177 178 InfoItem InfoHandle::RetrieveItem(const InfoPath& path, bool use_defaults) 179 { 180 return Root().RetrieveItem(path,use_defaults); 181 } 182 183 void InfoHandle::Remove(const InfoPath& path, bool remove_defaults) 184 { 185 return Root().Remove(path,remove_defaults); 186 } 187 188 string InfoHandle::GetAttribute(const string& name) const 189 { 190 return Root().GetAttribute(name); 191 } 192 193 void InfoHandle::SetAttribute(const string& name, const string& value) 194 { 195 Root().SetAttribute(name,value); 196 } 197 198 bool InfoHandle::HasAttribute(const string& name) const 199 { 200 return Root().HasAttribute(name); 201 } 202 203 void InfoHandle::RemoveAttribute(const string& name) 204 { 205 Root().RemoveAttribute(name); 206 } 207 208 std::vector<string> InfoHandle::GetAttributeList() const 209 { 210 return Root().GetAttributeList(); 211 } 212 213 string InfoHandle::GetTextData() const 214 { 215 return Root().GetTextData(); 216 } 217 218 void InfoHandle::SetTextData(const string& td) 219 { 220 Root().SetTextData(td); 221 } 222 223 void InfoHandle::Apply(InfoVisitor& v, bool visit_this) 224 { 225 Root().Apply(v,visit_this); 226 } 227 228 void InfoHandle::Apply(InfoConstVisitor& v, bool visit_this) const 229 { 230 Root().Apply(v,visit_this); 231 } 232 233 128 234 }} // ns branches/qt_gui/src/info/lib/info_handle.hh
r1754 r1755 43 43 unless the Copy() method is used. 44 44 */ 45 class DLLEXPORT InfoHandle {45 class DLLEXPORT InfoHandle{ 46 46 friend InfoHandle CreateInfo(); 47 47 friend InfoHandle CreateInfo(const string& text); … … 74 74 InfoItem GetDefaultItem(const InfoPath& p) const; 75 75 76 //! group interface 77 InfoGroup GetParent() const; 78 void SetName(const string& name); 79 string GetName() const; 80 InfoGroup GetGroup(const InfoPath& path, bool use_defaults=true) const; 81 InfoGroup CreateGroup(const string& name); 82 bool HasGroup(const InfoPath& name, bool use_defaults=true) const; 83 InfoGroup RetrieveGroup(const InfoPath& path, bool use_defaults=true); 84 InfoItem GetItem(const InfoPath& path, bool use_defaults=true) const; 85 InfoItem CreateItem(const string& name, const string& value); 86 bool HasItem(const InfoPath& path, bool use_defaults=true) const; 87 InfoItem RetrieveItem(const InfoPath& path, bool use_defaults=true); 88 void Remove(const InfoPath& path, bool remove_defaults=false); 89 string GetAttribute(const string& name) const; 90 void SetAttribute(const string& name, const string& value); 91 bool HasAttribute(const string& name) const; 92 void RemoveAttribute(const string& name); 93 std::vector<string> GetAttributeList() const; 94 string GetTextData() const; 95 void SetTextData(const string& td); 96 void Apply(InfoVisitor& v, bool visit_this=true); 97 void Apply(InfoConstVisitor& v, bool visit_this=true) const; 98 76 99 private: 77 100 InfoHandle(RootPtr impl); branches/qt_gui/src/info/pymod/wrap_info.cc
r1754 r1755 35 35 InfoHandle (*CreateInfoPtr2)(const string&)=CreateInfo; 36 36 37 void info_group_apply1a(InfoGroup* g, InfoVisitor& v) 38 { 39 g->Apply(v); 40 } 41 42 void info_group_apply1b(InfoGroup* g, InfoVisitor& v, bool b) 43 { 44 g->Apply(v,b); 45 } 46 47 void info_group_apply2a(InfoGroup* g, InfoConstVisitor& v) 48 { 49 g->Apply(v); 50 } 51 52 void info_group_apply2b(InfoGroup* g, InfoConstVisitor& v, bool b) 37 void info_apply1a(InfoGroup* g, InfoVisitor& v) 38 { 39 g->Apply(v); 40 } 41 42 void info_apply1b(InfoGroup* g, InfoVisitor& v, bool b) 43 { 44 g->Apply(v,b); 45 } 46 47 void info_apply2a(InfoGroup* g, InfoConstVisitor& v) 48 { 49 g->Apply(v); 50 } 51 52 void info_apply2b(InfoGroup* g, InfoConstVisitor& v, bool b) 53 { 54 g->Apply(v,b); 55 } 56 57 void info_handle_apply1a(InfoHandle* g, InfoVisitor& v) 58 { 59 g->Apply(v); 60 } 61 62 void info_handle_apply1b(InfoHandle* g, InfoVisitor& v, bool b) 63 { 64 g->Apply(v,b); 65 } 66 67 void info_handle_apply2a(InfoHandle* g, InfoConstVisitor& v) 68 { 69 g->Apply(v); 70 } 71 72 void info_handle_apply2b(InfoHandle* g, InfoConstVisitor& v, bool b) 53 73 { 54 74 g->Apply(v,b); … … 95 115 96 116 } 117 118 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getgroup_overloads, GetGroup, 1, 2) 119 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retrievegroup_overloads, RetrieveGroup, 1, 2) 120 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(hasgroup_overloads, HasGroup, 1, 2) 121 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getitem_overloads, GetItem, 1, 2) 122 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(hasitem_overloads, HasItem, 1, 2) 123 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retrieveitem_overloads, RetrieveItem, 1, 2) 124 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(remove_overloads, Remove, 1, 2) 125 126 97 127 98 128 … … 135 165 ; 136 166 167 137 168 class_<InfoGroup>("InfoGroup",no_init) 138 169 .def("GetParent",&InfoGroup::GetParent) … … 140 171 .def("SetName",&InfoGroup::SetName) 141 172 .add_property("name",&InfoGroup::GetName,&InfoGroup::SetName) 142 .def("GetGroup",&InfoGroup::GetGroup )173 .def("GetGroup",&InfoGroup::GetGroup,getgroup_overloads()) 143 174 .def("CreateGroup",&InfoGroup::CreateGroup) 144 .def("RetrieveGroup",&InfoGroup::RetrieveGroup )145 .def("HasGroup",&InfoGroup::HasGroup )146 .def("GetItem",&InfoGroup::GetItem )175 .def("RetrieveGroup",&InfoGroup::RetrieveGroup,retrievegroup_overloads()) 176 .def("HasGroup",&InfoGroup::HasGroup,hasgroup_overloads()) 177 .def("GetItem",&InfoGroup::GetItem,getitem_overloads()) 147 178 .def("CreateItem",&InfoGroup::CreateItem) 148 .def("HasItem",&InfoGroup::HasItem )149 .def("RetrieveItem",&InfoGroup::RetrieveItem )150 .def("Remove",&InfoGroup::Remove )179 .def("HasItem",&InfoGroup::HasItem,hasitem_overloads()) 180 .def("RetrieveItem",&InfoGroup::RetrieveItem,retrieveitem_overloads()) 181 .def("Remove",&InfoGroup::Remove,remove_overloads()) 151 182 .def("GetAttribute",&InfoGroup::GetAttribute) 152 183 .def("SetAttribute",&InfoGroup::SetAttribute) 153 184 .def("HasAttribute",&InfoGroup::HasAttribute) 154 185 .def("GetAttributeList",&InfoGroup::GetAttributeList) 155 .def("Apply",info_ group_apply1a)156 .def("Apply",info_ group_apply1b)157 .def("Apply",info_ group_apply2a)158 .def("Apply",info_ group_apply2b)186 .def("Apply",info_apply1a) 187 .def("Apply",info_apply1b) 188 .def("Apply",info_apply2a) 189 .def("Apply",info_apply2b) 159 190 .def("GetTextData",&InfoGroup::GetTextData) 160 ; 161 162 class_<InfoHandle >("InfoHandle",no_init)191 ; 192 193 class_<InfoHandle >("InfoHandle",no_init) 163 194 .def("Import",&InfoHandle::Import) 164 195 .def("Export",&InfoHandle::Export) … … 170 201 .def("HasDefaultItem",&InfoHandle::HasDefaultItem) 171 202 .def("GetDefaultItem",&InfoHandle::GetDefaultItem) 203 .def("GetParent",&InfoHandle::GetParent) 204 .def("GetName",&InfoHandle::GetName) 205 .def("SetName",&InfoHandle::SetName) 206 .add_property("name",&InfoHandle::GetName,&InfoHandle::SetName) 207 .def("GetGroup",&InfoHandle::GetGroup,getgroup_overloads()) 208 .def("CreateGroup",&InfoHandle::CreateGroup) 209 .def("RetrieveGroup",&InfoHandle::RetrieveGroup,retrievegroup_overloads()) 210 .def("HasGroup",&InfoHandle::HasGroup,hasgroup_overloads()) 211 .def("GetItem",&InfoHandle::GetItem,getitem_overloads()) 212 .def("CreateItem",&InfoHandle::CreateItem) 213 .def("HasItem",&InfoHandle::HasItem,hasitem_overloads()) 214 .def("RetrieveItem",&InfoHandle::RetrieveItem,retrieveitem_overloads()) 215 .def("Remove",&InfoHandle::Remove,remove_overloads()) 216 .def("GetAttribute",&InfoHandle::GetAttribute) 217 .def("SetAttribute",&InfoHandle::SetAttribute) 218 .def("HasAttribute",&InfoHandle::HasAttribute) 219 .def("GetAttributeList",&InfoHandle::GetAttributeList) 220 .def("Apply",info_handle_apply1a) 221 .def("Apply",info_handle_apply1b) 222 .def("Apply",info_handle_apply2a) 223 .def("Apply",info_handle_apply2b) 224 .def("GetTextData",&InfoHandle::GetTextData) 172 225 ; 173 226
