Changeset 1754

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

modified CreateInfo? to take string as data input instead as filename of dtd file / added some convenience funcions in info / wrapped InfoVisitor? to enable subclassing from python

Files:

Legend:

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

    r1610 r1754  
    2929  return InfoHandle(RootPtr(new detail::InfoImpl())); 
    3030} 
    31 InfoHandle CreateInfo(const string& dtdfile
     31InfoHandle CreateInfo(const string& text
    3232{ 
    33   return InfoHandle(RootPtr(new detail::InfoImpl(true,dtdfile))); 
     33  return InfoHandle(RootPtr(new detail::InfoImpl(true,text))); 
    3434} 
    3535 
  • branches/qt_gui/src/info/lib/info_handle.hh

    r948 r1754  
    4545class DLLEXPORT InfoHandle { 
    4646  friend InfoHandle CreateInfo(); 
    47   friend InfoHandle CreateInfo(const string&); 
     47  friend InfoHandle CreateInfo(const string& text); 
    4848  friend InfoHandle LoadInfo(const string&); 
    4949 
  • branches/qt_gui/src/info/lib/info_impl.cc

    r1610 r1754  
    7575} 
    7676 
    77 InfoImpl::InfoImpl(bool dummy,const string& dtdfile): 
     77InfoImpl::InfoImpl(bool dummy,const string& text): 
    7878  document_("EMDataInfo"), 
    7979  def_list_() 
    8080{ 
    81   QFile file(QS(dtdfile)); 
    82   if (!document_.setContent(&file)) { 
    83     file.close(); 
     81  if (!document_.setContent(QString::fromStdString(text))) { 
    8482    throw(InfoError("QDomDocument.setContent failed")); 
    8583  } 
    86   file.close(); 
    8784} 
    8885 
  • branches/qt_gui/src/info/lib/info_impl.hh

    r1610 r1754  
    113113  InfoImpl(); 
    114114  InfoImpl(const string& file); 
    115   InfoImpl(bool dummy,const string& dtdfile); 
     115  InfoImpl(bool dummy,const string& text); 
    116116 
    117117  RootPtr Copy() const; 
  • branches/qt_gui/src/info/lib/info_item.cc

    r1677 r1754  
    201201} 
    202202 
     203double RetrieveFloatInfoItem(InfoGroup ig, const InfoPath& path, double def) 
     204{ 
     205  if(ig.HasItem(path)) { 
     206    return ig.GetItem(path).AsFloat(); 
     207  } 
     208  ig.RetrieveItem(path).SetFloat(def); 
     209  return def; 
     210} 
     211 
     212int RetrieveIntInfoItem(InfoGroup ig, const InfoPath& path, int def) 
     213{ 
     214  if(ig.HasItem(path)) { 
     215    return ig.GetItem(path).AsInt(); 
     216  } 
     217  ig.RetrieveItem(path).SetInt(def); 
     218  return def; 
     219} 
     220 
     221bool RetrieveBoolInfoItem(InfoGroup ig, const InfoPath& path, bool def) 
     222{ 
     223  if(ig.HasItem(path)) { 
     224    return ig.GetItem(path).AsBool(); 
     225  } 
     226  ig.RetrieveItem(path).SetBool(def); 
     227  return def; 
     228} 
     229 
     230geom::Vec3 RetrieveVectorInfoItem(InfoGroup ig, const InfoPath& path, const geom::Vec3& def) 
     231{ 
     232  if(ig.HasItem(path)) { 
     233    return ig.GetItem(path).AsVector(); 
     234  } 
     235  ig.RetrieveItem(path).SetVector(def); 
     236  return def; 
     237} 
     238 
     239string RetrieveStringInfoItem(InfoGroup ig, const InfoPath& path, const string& def) 
     240{ 
     241  if(ig.HasItem(path)) { 
     242    return ig.GetItem(path).GetValue(); 
     243  } 
     244  ig.RetrieveItem(path).SetValue(def); 
     245  return def; 
     246} 
     247 
    203248void SetFloatInfoItem(InfoGroup ig, const InfoPath& path, double val) 
    204249{ 
  • branches/qt_gui/src/info/lib/info_item.hh

    r1677 r1754  
    124124DLLEXPORT string GetStringInfoItem(const InfoGroup& ig, const InfoPath& path, const string& def); 
    125125 
     126// these convenience functions will create the InfoItem if not already present 
     127DLLEXPORT double RetrieveFloatInfoItem(InfoGroup ig, const InfoPath& path, double def); 
     128DLLEXPORT int RetrieveIntInfoItem(InfoGroup ig, const InfoPath& path, int def); 
     129DLLEXPORT bool RetrieveBoolInfoItem(InfoGroup ig, const InfoPath& path, bool def); 
     130DLLEXPORT geom::Vec3 RetrieveVectorInfoItem(InfoGroup ig, const InfoPath& path, const geom::Vec3& def); 
     131DLLEXPORT string RetrieveStringInfoItem(InfoGroup ig, const InfoPath& path, const string& def); 
     132 
    126133DLLEXPORT void SetFloatInfoItem(InfoGroup ig, const InfoPath& path, double val); 
    127134DLLEXPORT void SetIntInfoItem(InfoGroup ig, const InfoPath& path, int val); 
  • branches/qt_gui/src/info/pymod/wrap_info.cc

    r1744 r1754  
    5454  g->Apply(v,b); 
    5555} 
     56 
     57 
     58struct InfoVisitorWrap : InfoVisitor, wrapper<InfoVisitor> 
     59{ 
     60    void VisitItem(InfoItem& item) 
     61    { 
     62        if (override VisitItemOverride = get_override("VisitItem")) 
     63            VisitItemOverride(item); 
     64        InfoVisitor::VisitItem(item); 
     65    } 
     66 
     67    bool VisitGroup(InfoGroup& group) 
     68    { 
     69        if (override VisitGroupOverride = get_override("VisitGroup")) 
     70            return VisitGroupOverride(group); 
     71        return InfoVisitor::VisitGroup(group); 
     72    } 
     73 
     74    void VisitGroupFinish(InfoGroup& group) 
     75    { 
     76        if (override VisitGroupFinishOverride = get_override("VisitGroupFinish")) 
     77            VisitGroupFinishOverride(group); 
     78        InfoVisitor::VisitGroupFinish(group); 
     79    } 
     80 
     81    void VisitItemDefault(InfoItem& item) 
     82    { 
     83        InfoVisitor::VisitItem(item); 
     84    } 
     85    bool VisitGroupDefault(InfoGroup& group) 
     86    { 
     87        return InfoVisitor::VisitGroup(group); 
     88    } 
     89    void VisitGroupFinishDefault(InfoGroup& group) 
     90    { 
     91        InfoVisitor::VisitGroupFinish(group); 
     92    } 
     93 
     94}; 
    5695 
    5796} 
     
    148187  def("GetStringInfoItem",GetStringInfoItem); 
    149188 
     189  def("RetrieveFloatInfoItem",RetrieveFloatInfoItem); 
     190  def("RetrieveIntInfoItem",RetrieveIntInfoItem); 
     191  def("RetrieveBoolInfoItem",RetrieveBoolInfoItem); 
     192  def("RetrieveVectorInfoItem",RetrieveVectorInfoItem); 
     193  def("RetrieveStringInfoItem",RetrieveStringInfoItem); 
     194 
    150195  def("SetFloatInfoItem",SetFloatInfoItem); 
    151196  def("SetIntInfoItem",SetIntInfoItem); 
     
    156201  implicitly_convertible<string,InfoPath>(); 
    157202 
    158   class_<InfoVisitor>("InfoVisitor",no_init) 
     203  class_<InfoVisitorWrap, boost::noncopyable>("InfoVisitor",init<>()) 
     204    .def("VisitItem", &InfoVisitor::VisitItem, &InfoVisitorWrap::VisitItemDefault) 
     205    .def("VisitItem", &InfoVisitor::VisitGroup, &InfoVisitorWrap::VisitGroupDefault) 
     206    .def("VisitItem", &InfoVisitor::VisitGroupFinish, &InfoVisitorWrap::VisitGroupFinishDefault) 
    159207    ; 
    160208