From 704007092c48c55d4fa548b9516c2bab4237b060 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 22 Apr 2013 14:48:59 -0400 Subject: [PATCH] Convert::getFullName becomes PVField::getFullName Compatibility wrapper using current Convert API Allow PVField::getFieldName to be inline'd Avoid multiple resize and copy operations on result String. --- pvDataApp/factory/Convert.cpp | 15 --------------- pvDataApp/factory/PVField.cpp | 30 +++++++++++++++++++++++++----- pvDataApp/pv/convert.h | 6 +++++- pvDataApp/pv/pvData.h | 9 ++++++++- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/pvDataApp/factory/Convert.cpp b/pvDataApp/factory/Convert.cpp index 40aa52a..0414622 100644 --- a/pvDataApp/factory/Convert.cpp +++ b/pvDataApp/factory/Convert.cpp @@ -421,21 +421,6 @@ Convert::Convert() Convert::~Convert(){} -void Convert::getFullName(StringBuilder buf,PVFieldPtr const & pvField) -{ - buf->empty(); - *buf += pvField->getFieldName(); - PVStructure *parent; - while((parent=pvField->getParent())!=0) { - parent = pvField->getParent(); - String name = parent->getFieldName(); - if(name.length()>0) { - buf->insert(0,"."); - buf->insert(0,name); - } - } -} - bool Convert::equals(PVFieldPtr const &a,PVFieldPtr const &b) { return convertEquals(a.get(),b.get()); diff --git a/pvDataApp/factory/PVField.cpp b/pvDataApp/factory/PVField.cpp index e4574d9..577ccb8 100644 --- a/pvDataApp/factory/PVField.cpp +++ b/pvDataApp/factory/PVField.cpp @@ -64,11 +64,6 @@ void PVField::message(String message,MessageType messageType) PVField::message(message,messageType,""); } -String PVField::getFieldName() const -{ - return fieldName; -} - void PVField::setRequester(RequesterPtr const &req) { if(parent!=NULL) { @@ -223,6 +218,31 @@ namespace format } }; +String PVField::getFullName() const +{ + size_t size=fieldName.size(); + + for(PVField *fld=getParent(); fld; fld=fld->getParent()) + { + size+=fld->fieldName.size()+1; + } + + String ret(size, '.'); + size_t pos=size - fieldName.size(); + + ret.replace(pos, String::npos, fieldName); + + for(PVField *fld=getParent(); fld; fld=fld->getParent()) + { + const String& nref = fld->fieldName; + assert(pos >= nref.size()+1); + pos -= nref.size()+1; + ret.replace(pos, String::npos, nref); + } + assert(pos==0); + return ret; +} + void PVField::computeOffset(const PVField * pvField) { const PVStructure * pvTop = pvField->getParent(); if(pvTop==NULL) { diff --git a/pvDataApp/pv/convert.h b/pvDataApp/pv/convert.h index 266aab2..1fd83dd 100644 --- a/pvDataApp/pv/convert.h +++ b/pvDataApp/pv/convert.h @@ -77,7 +77,11 @@ public: * @param builder The builder that will have the result. * @param pvField The pvField. */ - void getFullName(StringBuilder buf,PVFieldPtr const & pvField); + void getFullName(StringBuilder buf,PVFieldPtr const & pvField) + { + *buf = pvField->getFullName(); + } + /** * Do fields have the same definition. * diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index 4f15742..45098ab 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -244,7 +244,13 @@ public: * Get the fieldName for this field. * @return The name or empty string if top level field. */ - String getFieldName() const ; + inline const String& getFieldName() const {return fieldName;} + /** + * Fully expand the name of this field using the + * names of its parent fields with a dot '.' seperating + * each name. + */ + String getFullName() const; /** * Register the message requester. * At most one requester can be registered. @@ -343,6 +349,7 @@ public: */ virtual std::ostream& dumpValue(std::ostream& o) const = 0; + protected: PVField::shared_pointer getPtrSelf() {