Changeset 1755

Show
Ignore:
Timestamp:
01/14/10 17:22:19 (2 years ago)
Author:
andreas
Message:

added InfoGroup interface to InfoHandle / added boolean to control use of defaults in InfoHandles?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/qt_gui/src/info/lib/info_group.cc

    r1744 r1755  
    2323namespace iplt { namespace info { 
    2424 
     25 
     26 
    2527InfoGroup::InfoGroup(const InfoHandle& root, const ElePtr& impl): 
    2628  root_(root), 
     
    4547 
    4648 
    47 InfoGroup InfoGroup::GetGroup(const InfoPath& path) const 
     49InfoGroup InfoGroup::GetGroup(const InfoPath& path, bool use_defaults) const 
    4850{ 
    4951  std::vector<string> plist=path.GetList(); 
     
    5456    return last_group; 
    5557  } else { 
    56     if(root_.HasDefaultGroup(path)) { 
     58    if(root_.HasDefaultGroup(path) && use_defaults) { 
    5759    // TODO: prepend path to this group 
    5860    return root_.GetDefaultGroup(path); 
     
    9092}  
    9193 
    92 bool InfoGroup::HasGroup(const InfoPath& path) const 
     94bool InfoGroup::HasGroup(const InfoPath& path, bool use_defaults) const 
    9395{ 
    9496  std::vector<string> plist=path.GetList(); 
     
    98100  if(do_group_lookup(pos,plist.end(),last_group)) { 
    99101    return true; 
    100   } else
     102  } else if(use_defaults)
    101103    // TODO: prepend path to this group 
    102104    return root_.HasDefaultGroup(path); 
     
    106108 
    107109InfoGroup 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) 
    110112{ 
    111113  InfoGroup subgroup = group.CreateGroup((*pos)); 
     
    115117} 
    116118 
    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; 
     119InfoGroup InfoGroup::RetrieveGroup(const InfoPath& path, bool use_defaults) 
     120
     121  if(HasGroup(path,use_defaults)) { 
     122    return GetGroup(path); 
    126123  } 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  } 
    130134} 
    131135 
     
    145149      tp=IT_BOOL; 
    146150    } else if(tps=="vector" || tps=="VECTOR") { 
    147    tp=IT_VECTOR; 
     151      tp=IT_VECTOR; 
    148152    } else { 
    149153      // keep string default, alternatively could throw error here... 
     
    155159} 
    156160 
    157 InfoItem InfoGroup::GetItem(const InfoPath& path) const 
     161InfoItem InfoGroup::GetItem(const InfoPath& path, bool use_defaults) const 
    158162{ 
    159163  InfoGroup grp=*this; 
    160  
    161164  InfoPath grppath=path.Strip(); 
    162  
    163165  std::vector<string> plist=grppath.GetList(); 
    164  
    165166  std::vector<string>::const_iterator pos=plist.begin(); 
    166  
    167167  string iname=path.GetList().back(); 
    168  
    169168  InfoGroup last_group(*this); 
    170169  if(do_group_lookup(pos,plist.end(),last_group)) { 
     
    173172      ElePtr p(last_group.impl_->GetSub(iname)); 
    174173      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")); 
    176175      } 
    177176      return InfoItem(root_,p,ResolveItemType(p)); 
     
    181180  // check default 
    182181  // TODO: prepend path to this group 
    183   if(root_.HasDefaultItem(path)) { 
     182  if(use_defaults && root_.HasDefaultItem(path)) { 
    184183    return root_.GetDefaultItem(path); 
    185184  } 
     
    194193} 
    195194 
    196 bool InfoGroup::HasItem(const InfoPath& path) const 
     195bool InfoGroup::HasItem(const InfoPath& path, bool use_defaults) const 
    197196{ 
    198197  InfoGroup grp=*this; 
    199  
    200198  InfoPath grppath=path.Strip(); 
    201  
    202199  std::vector<string> plist=grppath.GetList(); 
    203  
    204200  std::vector<string>::const_iterator pos=plist.begin(); 
    205  
    206201  InfoGroup last_group(*this); 
    207202  if(do_group_lookup(pos,plist.end(),last_group)) { 
     
    210205      ElePtr p(last_group.impl_->GetSub(iname)); 
    211206      if(p->HasAttribute("value")) { 
    212    return true; 
     207        return true; 
    213208      } 
    214209    } 
    215210  }  
    216  
    217211  // 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 
     218InfoItem InfoGroup::RetrieveItem(const InfoPath& path, bool use_defaults) 
    222219{ 
    223220  string item=path.GetList().back(); 
    224221 
    225   InfoGroup grp = RetrieveGroup(path.Strip()); 
     222  InfoGroup grp = RetrieveGroup(path.Strip(),use_defaults); 
    226223   
    227   if(grp.HasItem(item)) { 
     224  if(grp.HasItem(item,use_defaults)) { 
    228225    return grp.GetItem(item); 
    229226  } else { 
     
    232229} 
    233230 
    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   }  
     231void 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()); 
    246236} 
    247237 
  • branches/qt_gui/src/info/lib/info_group.hh

    r1677 r1755  
    2323#include <iplt/base.hh> 
    2424 
    25 #include "info_fw.hh" 
    2625#include "info_handle.hh" 
    2726#include "info_impl_fw.hh" 
     
    2928namespace iplt { namespace info { 
    3029 
    31 class DLLEXPORT InfoGroup
     30class DLLEXPORT InfoGroup
    3231  friend class InfoHandle; // ctor access 
    3332  friend class InfoItem; // ctor access 
     
    3635  //! retrieve parent group 
    3736  InfoGroup GetParent() const; 
    38  
    3937  //! set name 
    4038  void SetName(const string& name); 
    4139  //! retrieve name 
    4240  string GetName() const; 
    43  
    44   InfoGroup GetGroup(const InfoPath& path) const; 
     41  InfoGroup GetGroup(const InfoPath& path, bool use_defaults=true) const; 
    4542  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; 
    5046  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); 
    5650  //! return attribute of given name 
    5751  string GetAttribute(const string& name) const; 
     
    6256  //! remove attribute of given name 
    6357  void RemoveAttribute(const string& name); 
    64  
    6558  std::vector<string> GetAttributeList() const; 
    66  
    6759  string GetTextData() const; 
    6860  void SetTextData(const string& td); 
    69  
    7061  //! Apply visitor 
    7162  /*! 
  • branches/qt_gui/src/info/lib/info_handle.cc

    r1754 r1755  
    126126} 
    127127 
     128InfoGroup InfoHandle::GetParent()  const 
     129{ 
     130  return Root().GetParent(); 
     131} 
     132 
     133void InfoHandle::SetName(const string& name) 
     134{ 
     135  Root().SetName(name); 
     136} 
     137 
     138string InfoHandle::GetName()  const 
     139{ 
     140  return Root().GetName(); 
     141} 
     142 
     143InfoGroup InfoHandle::GetGroup(const InfoPath& path, bool use_defaults)  const 
     144{ 
     145  return Root().GetGroup(path,use_defaults); 
     146} 
     147 
     148InfoGroup InfoHandle::CreateGroup(const string& name) 
     149{ 
     150  return Root().CreateGroup(name); 
     151} 
     152 
     153bool InfoHandle::HasGroup(const InfoPath& name, bool use_defaults)  const 
     154{ 
     155  return Root().HasGroup(name,use_defaults); 
     156} 
     157 
     158InfoGroup InfoHandle::RetrieveGroup(const InfoPath& path, bool use_defaults) 
     159{ 
     160  return Root().RetrieveGroup(path,use_defaults); 
     161} 
     162 
     163InfoItem InfoHandle::GetItem(const InfoPath& path, bool use_defaults)  const 
     164{ 
     165  return Root().GetItem(path,use_defaults); 
     166} 
     167 
     168InfoItem InfoHandle::CreateItem(const string& name, const string& value) 
     169{ 
     170  return Root().CreateItem(name,value); 
     171} 
     172 
     173bool InfoHandle::HasItem(const InfoPath& path, bool use_defaults)  const 
     174{ 
     175  return Root().HasItem(path,use_defaults); 
     176} 
     177 
     178InfoItem InfoHandle::RetrieveItem(const InfoPath& path, bool use_defaults) 
     179{ 
     180  return Root().RetrieveItem(path,use_defaults); 
     181} 
     182 
     183void InfoHandle::Remove(const InfoPath& path, bool remove_defaults) 
     184{ 
     185  return Root().Remove(path,remove_defaults); 
     186} 
     187 
     188string InfoHandle::GetAttribute(const string& name)  const 
     189{ 
     190  return Root().GetAttribute(name); 
     191} 
     192 
     193void InfoHandle::SetAttribute(const string& name, const string& value) 
     194{ 
     195  Root().SetAttribute(name,value); 
     196} 
     197 
     198bool InfoHandle::HasAttribute(const string& name)  const 
     199{ 
     200  return Root().HasAttribute(name); 
     201} 
     202 
     203void InfoHandle::RemoveAttribute(const string& name) 
     204{ 
     205  Root().RemoveAttribute(name); 
     206} 
     207 
     208std::vector<string> InfoHandle::GetAttributeList()  const 
     209{ 
     210  return Root().GetAttributeList(); 
     211} 
     212 
     213string InfoHandle::GetTextData()  const 
     214{ 
     215  return Root().GetTextData(); 
     216} 
     217 
     218void InfoHandle::SetTextData(const string& td) 
     219{ 
     220  Root().SetTextData(td); 
     221} 
     222 
     223void InfoHandle::Apply(InfoVisitor& v, bool visit_this) 
     224{ 
     225  Root().Apply(v,visit_this); 
     226} 
     227 
     228void InfoHandle::Apply(InfoConstVisitor& v, bool visit_this)  const 
     229{ 
     230  Root().Apply(v,visit_this); 
     231} 
     232 
     233 
    128234}} // ns 
  • branches/qt_gui/src/info/lib/info_handle.hh

    r1754 r1755  
    4343  unless the Copy() method is used. 
    4444*/ 
    45 class DLLEXPORT InfoHandle
     45class DLLEXPORT InfoHandle
    4646  friend InfoHandle CreateInfo(); 
    4747  friend InfoHandle CreateInfo(const string& text); 
     
    7474  InfoItem GetDefaultItem(const InfoPath& p) const; 
    7575 
     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 
    7699private: 
    77100  InfoHandle(RootPtr impl); 
  • branches/qt_gui/src/info/pymod/wrap_info.cc

    r1754 r1755  
    3535InfoHandle (*CreateInfoPtr2)(const string&)=CreateInfo; 
    3636 
    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) 
     37void info_apply1a(InfoGroup* g, InfoVisitor& v) 
     38
     39  g->Apply(v); 
     40
     41 
     42void info_apply1b(InfoGroup* g, InfoVisitor& v, bool b) 
     43
     44  g->Apply(v,b); 
     45
     46 
     47void info_apply2a(InfoGroup* g, InfoConstVisitor& v) 
     48
     49  g->Apply(v); 
     50
     51 
     52void info_apply2b(InfoGroup* g, InfoConstVisitor& v, bool b) 
     53
     54  g->Apply(v,b); 
     55
     56 
     57void info_handle_apply1a(InfoHandle* g, InfoVisitor& v) 
     58
     59  g->Apply(v); 
     60
     61 
     62void info_handle_apply1b(InfoHandle* g, InfoVisitor& v, bool b) 
     63
     64  g->Apply(v,b); 
     65
     66 
     67void info_handle_apply2a(InfoHandle* g, InfoConstVisitor& v) 
     68
     69  g->Apply(v); 
     70
     71 
     72void info_handle_apply2b(InfoHandle* g, InfoConstVisitor& v, bool b) 
    5373{ 
    5474  g->Apply(v,b); 
     
    95115 
    96116} 
     117 
     118BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getgroup_overloads, GetGroup, 1, 2) 
     119BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retrievegroup_overloads, RetrieveGroup, 1, 2) 
     120BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(hasgroup_overloads, HasGroup, 1, 2) 
     121BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getitem_overloads, GetItem, 1, 2) 
     122BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(hasitem_overloads, HasItem, 1, 2) 
     123BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retrieveitem_overloads, RetrieveItem, 1, 2) 
     124BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(remove_overloads, Remove, 1, 2) 
     125 
     126 
    97127 
    98128 
     
    135165    ; 
    136166 
     167 
    137168  class_<InfoGroup>("InfoGroup",no_init) 
    138169    .def("GetParent",&InfoGroup::GetParent) 
     
    140171    .def("SetName",&InfoGroup::SetName) 
    141172    .add_property("name",&InfoGroup::GetName,&InfoGroup::SetName) 
    142     .def("GetGroup",&InfoGroup::GetGroup
     173    .def("GetGroup",&InfoGroup::GetGroup,getgroup_overloads()
    143174    .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()
    147178    .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()
    151182    .def("GetAttribute",&InfoGroup::GetAttribute) 
    152183    .def("SetAttribute",&InfoGroup::SetAttribute) 
    153184    .def("HasAttribute",&InfoGroup::HasAttribute) 
    154185    .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) 
    159190    .def("GetTextData",&InfoGroup::GetTextData) 
    160     ; 
    161  
    162   class_<InfoHandle>("InfoHandle",no_init) 
     191    ;   
     192     
     193  class_<InfoHandle >("InfoHandle",no_init) 
    163194    .def("Import",&InfoHandle::Import) 
    164195    .def("Export",&InfoHandle::Export) 
     
    170201    .def("HasDefaultItem",&InfoHandle::HasDefaultItem) 
    171202    .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) 
    172225    ;   
    173226