Rename getAs getSubFieldT

Signed-off-by: Dave Hickin <david.hickin@diamond.ac.uk>
This commit is contained in:
Dave Hickin
2015-07-13 12:34:15 +01:00
parent e4689dd3f8
commit ebe2d6196c
6 changed files with 59 additions and 59 deletions

View File

@@ -7,7 +7,7 @@ The main changes since release 4.0 are:
* Convert::copyUnion now always copies between subfields.
* CreateRequest prevents a possible SEGFAULT.
* New stream operators for Field and PVField are provided.
* New method getAs that is like getSubField except that it throws exception
* New method getSubFieldT that is like getSubField except that it throws exception
Convert copy methods and equals operators
-----------------------------------------
@@ -73,10 +73,10 @@ Now it can be done as follows:
cout << pv << endl;
}
New method getAs that is like getSubField except that it throws exception
New method getSubFieldT that is like getSubField except that it throws exception
--------------------
<b>PVStructure</b> has a new template member <b>getAs(const char *name)</b>
<b>PVStructure</b> has a new template member <b>getSubFieldT(std::string const &fieldName)</b>
that is like <b>getSubField</b> except that it throws a runtime_error
instead of returning null.

View File

@@ -465,10 +465,10 @@ structure
PVStructurePtr doubleValue = getPVDataCreate()-&gt;createPVStructure(
getStandardField()-&gt;scalar(pvDouble,"alarm,timeStamp"));
PVDoublePtr pvdouble =
doubleValue-&gt;getAs&lt;PVDouble&gt;("value");
doubleValue-&gt;getSubField&lt;PVDouble&gt;("value");
pvdouble-&gt;put(1e5);
cout &lt;&lt; *doubleValue &lt;&lt; endl;
double value = doubleValue-&gt;getAs&lt;PVDouble&gt;("value")-&gt;get();
double value = doubleValue-&gt;getSubField&lt;PVDouble&gt;("value")-&gt;get();
cout &lt;&lt; "from get " &lt;&lt; value &lt;&lt; "\n\n";
</pre>
This produces:
@@ -491,7 +491,7 @@ from get 100000
PVStructurePtr doubleArrayValue = pvDataCreate-&gt;createPVStructure(
standardField-&gt;scalarArray(pvDouble,"alarm,timeStamp"));
PVDoubleArrayPtr pvDoubleArray =
doubleArrayValue-&gt;getAs&lt;PVDoubleArray&gt;("value");
doubleArrayValue-&gt;getSubField&lt;PVDoubleArray&gt;("value");
size_t len = 10;
shared_vector&lt;double&gt; xxx(len);
for(size_t i=0; i&lt; len; ++i) xxx[i] = i;
@@ -605,10 +605,10 @@ structure
createUnion(),
"alarm,timeStamp"));
PVStructurePtr pvTimeStamp =
pvStructure-&gt;getAs&lt;PVUnion&gt;("value")-&gt;select&lt;PVStructure&gt;(2);
pvTimeStamp-&gt;getAs&lt;PVLong&gt;("secondsPastEpoch")-&gt;put(1000);
pvStructure-&gt;getSubField&lt;PVUnion&gt;("value")-&gt;select&lt;PVStructure&gt;(2);
pvTimeStamp-&gt;getSubField&lt;PVLong&gt;("secondsPastEpoch")-&gt;put(1000);
cout &lt;&lt; *pvStructure) &lt;&lt; "\n";
pvStructure-&gt;getAs&lt;PVUnion&gt;("value")-&gt;select&lt;PVDouble&gt;(0)-&gt;put(1e5);
pvStructure-&gt;getSubField&lt;PVUnion&gt;("value")-&gt;select&lt;PVDouble&gt;(0)-&gt;put(1e5);
cout &lt;&lt; *pvStructure &lt;&lt; "\n\n";
</pre>
This produces:
@@ -648,13 +648,13 @@ epics:nt/NTUnion:1.0
standardField-&gt;variantUnion("alarm,timeStamp"));
PVStructurePtr pvTimeStamp =
pvDataCreate-&gt;createPVStructure(standardField-&gt;timeStamp());
pvStructure-&gt;getAs&lt;PVUnion&gt;("value")-&gt;set(pvTimeStamp);
pvTimeStamp-&gt;getAs&lt;PVLong&gt;("secondsPastEpoch")-&gt;put(1000);
pvStructure-&gt;getSubField&lt;PVUnion&gt;("value")-&gt;set(pvTimeStamp);
pvTimeStamp-&gt;getSubField&lt;PVLong&gt;("secondsPastEpoch")-&gt;put(1000);
cout &lt;&lt; *pvStructure &lt;&lt; "\n";
pvStructure-&gt;getAs&lt;PVUnion&gt;("value")-&gt;set(
pvStructure-&gt;getSubField&lt;PVUnion&gt;("value")-&gt;set(
pvDataCreate-&gt;createPVScalar(pvDouble));
PVDoublePtr pvValue = static_pointer_cast&lt;PVDouble&gt;(
pvStructure-&gt;getAs&lt;PVUnion&gt;("value")-&gt;get());
pvStructure-&gt;getSubField&lt;PVUnion&gt;("value")-&gt;get());
pvValue-&gt;put(1e5);
cout &lt;&lt; *pvStructure &lt;&lt; "\n\n";
</pre>
@@ -718,7 +718,7 @@ epics:nt/NTUnion:1.0
cout &lt;&lt; *pvStructure-&gt;getStructure() &lt;&lt; endl;
cout &lt;&lt; "data\n";
cout &lt;&lt; *pvStructure &lt;&lt; "\n";
PVUnionPtr pvUnion = pvStructure-&gt;getAs&lt;PVUnion&gt;("value");;
PVUnionPtr pvUnion = pvStructure-&gt;getSubField&lt;PVUnion&gt;("value");;
pvUnion-&gt;select("doubleValue");
PVDoublePtr pvDouble = pvUnion-&gt;get&lt;PVDouble&gt;();
pvDouble-&gt;put(1.55);
@@ -726,7 +726,7 @@ epics:nt/NTUnion:1.0
cout &lt;&lt; *pvStructure &lt;&lt; "\n";
cout &lt;&lt; "value = " &lt;&lt; pvDouble-&gt;get() &lt;&lt; "\n";
pvUnion-&gt;select("structValue");
pvDouble = pvUnion-&gt;get&lt;PVStructure&gt;()-&gt;getAs&lt;PVDouble&gt;("doubleValue");
pvDouble = pvUnion-&gt;get&lt;PVStructure&gt;()-&gt;getSubField&lt;PVDouble&gt;("doubleValue");
pvDouble-&gt;put(1.65);
cout &lt;&lt; "select structValue\n";
cout &lt;&lt; *pvStructure &lt;&lt; "\n";
@@ -2304,14 +2304,14 @@ public:
template&lt;typename PVT&gt;
std::tr1::shared_ptr&lt;PVT&gt; getSubField(std::string const &amp;fieldName) const
template&lt;typename PVT&gt;
PVT&amp; getAs(const char *name) const;
PVFieldPtr getSubField(std::size_t fieldOffset) const;
template&lt;typename PVT&gt;
std::tr1::shared_ptr&lt;PVT&gt; getSubField(std::size_t fieldOffset) const
template&lt;typename PVT&gt;
PVT&amp; getSubFieldT(std::string const &amp;fieldName) const;
virtual void serialize(
ByteBuffer *pbuffer,SerializableControl *pflusher) const ;
virtual void deserialize(
@@ -2332,9 +2332,6 @@ public:
<dt>getPVFields</dt>
<dd>Returns the array of subfields. The set of subfields must all have
different field names.</dd>
<dt>getAs(const char *name)</dt>
<dd>Like the getSubField except that it throws std::runtime_error if
the field does not exists or has the wrong type.</dd>
<dt>getSubField(std::string fieldName)</dt>
<dd>
Get a subField of a field.d
@@ -2353,6 +2350,9 @@ public:
<br />
<b>Note</b> The template version replaces getBooleanField, etc.<br/>
</dd>
<dt>getSubFieldT(std::string const &amp;fieldName)</dt>
<dd>Like getSubField except that it throws std::runtime_error if
the field does not exists or has the wrong type.</dd>
<dt>dumpValue</dt>
<dd>Method for streams I/O.</dd>
</dl>
@@ -5414,7 +5414,7 @@ public:
raiseMonitor = true;
if(pvFieldOptions!=NULL) {
PVStringPtr pvString =
pvFieldOptions-&gt;getAs&lt;PVString&gt;("raiseMonitor");
pvFieldOptions-&gt;getSubField&lt;PVString&gt;("raiseMonitor");
if(pvString!=NULL) {
std::string value = pvString-&gt;get();
if(value.compare("false")==0) raiseMonitor = false;

View File

@@ -465,10 +465,10 @@ structure
PVStructurePtr doubleValue = getPVDataCreate()-&gt;createPVStructure(
getStandardField()-&gt;scalar(pvDouble,"alarm,timeStamp"));
PVDoublePtr pvdouble =
doubleValue-&gt;getAs&lt;PVDouble&gt;("value");
doubleValue-&gt;getSubField&lt;PVDouble&gt;("value");
pvdouble-&gt;put(1e5);
cout &lt;&lt; *doubleValue &lt;&lt; endl;
double value = doubleValue-&gt;getAs&lt;PVDouble&gt;("value")-&gt;get();
double value = doubleValue-&gt;getSubField&lt;PVDouble&gt;("value")-&gt;get();
cout &lt;&lt; "from get " &lt;&lt; value &lt;&lt; "\n\n";
</pre>
This produces:
@@ -491,7 +491,7 @@ from get 100000
PVStructurePtr doubleArrayValue = pvDataCreate-&gt;createPVStructure(
standardField-&gt;scalarArray(pvDouble,"alarm,timeStamp"));
PVDoubleArrayPtr pvDoubleArray =
doubleArrayValue-&gt;getAs&lt;PVDoubleArray&gt;("value");
doubleArrayValue-&gt;getSubField&lt;PVDoubleArray&gt;("value");
size_t len = 10;
shared_vector&lt;double&gt; xxx(len);
for(size_t i=0; i&lt; len; ++i) xxx[i] = i;
@@ -605,10 +605,10 @@ structure
createUnion(),
"alarm,timeStamp"));
PVStructurePtr pvTimeStamp =
pvStructure-&gt;getAs&lt;PVUnion&gt;("value")-&gt;select&lt;PVStructure&gt;(2);
pvTimeStamp-&gt;getAs&lt;PVLong&gt;("secondsPastEpoch")-&gt;put(1000);
pvStructure-&gt;getSubField&lt;PVUnion&gt;("value")-&gt;select&lt;PVStructure&gt;(2);
pvTimeStamp-&gt;getSubField&lt;PVLong&gt;("secondsPastEpoch")-&gt;put(1000);
cout &lt;&lt; *pvStructure) &lt;&lt; "\n";
pvStructure-&gt;getAs&lt;PVUnion&gt;("value")-&gt;select&lt;PVDouble&gt;(0)-&gt;put(1e5);
pvStructure-&gt;getSubField&lt;PVUnion&gt;("value")-&gt;select&lt;PVDouble&gt;(0)-&gt;put(1e5);
cout &lt;&lt; *pvStructure &lt;&lt; "\n\n";
</pre>
This produces:
@@ -648,13 +648,13 @@ epics:nt/NTUnion:1.0
standardField-&gt;variantUnion("alarm,timeStamp"));
PVStructurePtr pvTimeStamp =
pvDataCreate-&gt;createPVStructure(standardField-&gt;timeStamp());
pvStructure-&gt;getAs&lt;PVUnion&gt;("value")-&gt;set(pvTimeStamp);
pvTimeStamp-&gt;getAs&lt;PVLong&gt;("secondsPastEpoch")-&gt;put(1000);
pvStructure-&gt;getSubField&lt;PVUnion&gt;("value")-&gt;set(pvTimeStamp);
pvTimeStamp-&gt;getSubField&lt;PVLong&gt;("secondsPastEpoch")-&gt;put(1000);
cout &lt;&lt; *pvStructure &lt;&lt; "\n";
pvStructure-&gt;getAs&lt;PVUnion&gt;("value")-&gt;set(
pvStructure-&gt;getSubField&lt;PVUnion&gt;("value")-&gt;set(
pvDataCreate-&gt;createPVScalar(pvDouble));
PVDoublePtr pvValue = static_pointer_cast&lt;PVDouble&gt;(
pvStructure-&gt;getAs&lt;PVUnion&gt;("value")-&gt;get());
pvStructure-&gt;getSubField&lt;PVUnion&gt;("value")-&gt;get());
pvValue-&gt;put(1e5);
cout &lt;&lt; *pvStructure &lt;&lt; "\n\n";
</pre>
@@ -718,7 +718,7 @@ epics:nt/NTUnion:1.0
cout &lt;&lt; *pvStructure-&gt;getStructure() &lt;&lt; endl;
cout &lt;&lt; "data\n";
cout &lt;&lt; *pvStructure &lt;&lt; "\n";
PVUnionPtr pvUnion = pvStructure-&gt;getAs&lt;PVUnion&gt;("value");;
PVUnionPtr pvUnion = pvStructure-&gt;getSubField&lt;PVUnion&gt;("value");;
pvUnion-&gt;select("doubleValue");
PVDoublePtr pvDouble = pvUnion-&gt;get&lt;PVDouble&gt;();
pvDouble-&gt;put(1.55);
@@ -726,7 +726,7 @@ epics:nt/NTUnion:1.0
cout &lt;&lt; *pvStructure &lt;&lt; "\n";
cout &lt;&lt; "value = " &lt;&lt; pvDouble-&gt;get() &lt;&lt; "\n";
pvUnion-&gt;select("structValue");
pvDouble = pvUnion-&gt;get&lt;PVStructure&gt;()-&gt;getAs&lt;PVDouble&gt;("doubleValue");
pvDouble = pvUnion-&gt;get&lt;PVStructure&gt;()-&gt;getSubField&lt;PVDouble&gt;("doubleValue");
pvDouble-&gt;put(1.65);
cout &lt;&lt; "select structValue\n";
cout &lt;&lt; *pvStructure &lt;&lt; "\n";
@@ -2304,14 +2304,14 @@ public:
template&lt;typename PVT&gt;
std::tr1::shared_ptr&lt;PVT&gt; getSubField(std::string const &amp;fieldName) const
template&lt;typename PVT&gt;
PVT&amp; getAs(const char *name) const;
PVFieldPtr getSubField(std::size_t fieldOffset) const;
template&lt;typename PVT&gt;
std::tr1::shared_ptr&lt;PVT&gt; getSubField(std::size_t fieldOffset) const
template&lt;typename PVT&gt;
PVT&amp; getSubFieldT(std::string const &amp;fieldName) const;
virtual void serialize(
ByteBuffer *pbuffer,SerializableControl *pflusher) const ;
virtual void deserialize(
@@ -2332,9 +2332,6 @@ public:
<dt>getPVFields</dt>
<dd>Returns the array of subfields. The set of subfields must all have
different field names.</dd>
<dt>getAs(const char *name)</dt>
<dd>Like the getSubField except that it throws std::runtime_error if
the field does not exists or has the wrong type.</dd>
<dt>getSubField(std::string fieldName)</dt>
<dd>
Get a subField of a field.d
@@ -2353,6 +2350,9 @@ public:
<br />
<b>Note</b> The template version replaces getBooleanField, etc.<br/>
</dd>
<dt>getSubFieldT(std::string const &amp;fieldName)</dt>
<dd>Like getSubField except that it throws std::runtime_error if
the field does not exists or has the wrong type.</dd>
<dt>dumpValue</dt>
<dd>Method for streams I/O.</dd>
</dl>
@@ -5414,7 +5414,7 @@ public:
raiseMonitor = true;
if(pvFieldOptions!=NULL) {
PVStringPtr pvString =
pvFieldOptions-&gt;getAs&lt;PVString&gt;("raiseMonitor");
pvFieldOptions-&gt;getSubField&lt;PVString&gt;("raiseMonitor");
if(pvString!=NULL) {
std::string value = pvString-&gt;get();
if(value.compare("false")==0) raiseMonitor = false;

View File

@@ -107,7 +107,7 @@ const PVFieldPtrArray & PVStructure::getPVFields() const
PVFieldPtr PVStructure::getSubField(string const &fieldName) const
{
PVField * field = GetAsImpl(fieldName.c_str(), false);
PVField * field = getSubFieldImpl(fieldName.c_str(), false);
if (field)
return field->shared_from_this();
else
@@ -134,7 +134,7 @@ PVFieldPtr PVStructure::getSubField(size_t fieldOffset) const
throw std::logic_error("PVStructure.getSubField: Logic error");
}
PVField* PVStructure::GetAsImpl(const char *name, bool throws) const
PVField* PVStructure::getSubFieldImpl(const char *name, bool throws) const
{
const PVStructure *parent = this;
if(!name)

View File

@@ -712,7 +712,7 @@ public:
}
private:
PVField *GetAsImpl(const char *name, bool throws = true) const;
PVField *getSubFieldImpl(const char *name, bool throws = true) const;
public:
/**
@@ -721,13 +721,13 @@ public:
* @returns A reference to the sub-field (never NULL)
* @throws std::runtime_error if the requested sub-field doesn't exist, or has a different type
* @code
* PVInt& ref = pvStruct->getAs<PVInt>("substruct.leaffield");
* PVInt& ref = pvStruct->getSubFieldT<PVInt>("substruct.leaffield");
* @endcode
*/
template<typename PVT>
PVT& getAs(const char *name) const
PVT& getSubFieldT(const char *name) const
{
PVT *raw = dynamic_cast<PVT*>(GetAsImpl(name));
PVT *raw = dynamic_cast<PVT*>(getSubFieldImpl(name));
if(!raw)
{
std::stringstream ss;
@@ -738,9 +738,9 @@ public:
}
template<typename PVT>
FORCE_INLINE PVT& getAs(std::string const &fieldName) const
FORCE_INLINE PVT& getSubFieldT(std::string const &fieldName) const
{
return this->getAs<PVT>(fieldName.c_str());
return this->getSubFieldT<PVT>(fieldName.c_str());
}
/**

View File

@@ -541,7 +541,7 @@ static void testFieldAccess()
PVIntPtr a = fld->getSubField<PVInt>("test");
testOk1(a!=NULL);
if(a.get()) {
PVInt& b = fld->getAs<PVInt>("test");
PVInt& b = fld->getSubFieldT<PVInt>("test");
testOk(&b==a.get(), "%p == %p", &b, a.get());
} else
testSkip(1, "test doesn't exist?");
@@ -549,7 +549,7 @@ static void testFieldAccess()
a = fld->getSubField<PVInt>("hello.world");
testOk1(a!=NULL);
if(a.get()) {
PVInt& b = fld->getAs<PVInt>("hello.world");
PVInt& b = fld->getSubFieldT<PVInt>("hello.world");
testOk(&b==a.get(), "%p == %p", &b, a.get());
} else
testSkip(1, "hello.world doesn't exist?");
@@ -579,7 +579,7 @@ static void testFieldAccess()
// null string
try{
char * name = NULL;
fld->getAs<PVInt>(name);
fld->getSubFieldT<PVInt>(name);
testFail("missing required exception");
}catch(std::invalid_argument& e){
testPass("caught expected exception: %s", e.what());
@@ -587,7 +587,7 @@ static void testFieldAccess()
// non-existent
try{
fld->getAs<PVInt>("invalid");
fld->getSubFieldT<PVInt>("invalid");
testFail("missing required exception");
}catch(std::runtime_error& e){
testPass("caught expected exception: %s", e.what());
@@ -595,7 +595,7 @@ static void testFieldAccess()
// wrong type
try{
fld->getAs<PVDouble>("test");
fld->getSubFieldT<PVDouble>("test");
testFail("missing required exception");
}catch(std::runtime_error& e){
testPass("caught expected exception: %s", e.what());
@@ -603,7 +603,7 @@ static void testFieldAccess()
// empty leaf field name
try{
fld->getAs<PVDouble>("hello.");
fld->getSubFieldT<PVDouble>("hello.");
testFail("missing required exception");
}catch(std::runtime_error& e){
testPass("caught expected exception: %s", e.what());
@@ -611,13 +611,13 @@ static void testFieldAccess()
// empty field name
try{
fld->getAs<PVDouble>("hello..world");
fld->getSubFieldT<PVDouble>("hello..world");
testFail("missing required exception");
}catch(std::runtime_error& e){
testPass("caught expected exception: %s", e.what());
}
try{
fld->getAs<PVDouble>(".");
fld->getSubFieldT<PVDouble>(".");
testFail("missing required exception");
}catch(std::runtime_error& e){
testPass("caught expected exception: %s", e.what());
@@ -625,7 +625,7 @@ static void testFieldAccess()
// whitespace
try{
fld->getAs<PVDouble>(" test");
fld->getSubFieldT<PVDouble>(" test");
testFail("missing required exception");
}catch(std::runtime_error& e){
testPass("caught expected exception: %s", e.what());
@@ -633,7 +633,7 @@ static void testFieldAccess()
// intermediate field not structure
try{
fld->getAs<PVDouble>("hello.world.invalid");
fld->getSubFieldT<PVDouble>("hello.world.invalid");
testFail("missing required exception");
}catch(std::runtime_error& e){
testPass("caught expected exception: %s", e.what());