Clear up confusion between labels and column names
The labels are strings used in the displaying of the columns of a table e.g. column titles or headers. The column names of an NTTable are the names of the fields containing the column data. There was some confusion in the implementation between these. Rename the labels variable columnNames and correct the comments. Tables were created with labels equal to the column names. Retain this behaviour for backwards compatibility, as a sensible default and to always create a valid table, but document this.
This commit is contained in:
@@ -24,10 +24,10 @@ NTTableBuilder::shared_pointer NTTableBuilder::add(
|
||||
std::string const & name, epics::pvData::ScalarType scalarType
|
||||
)
|
||||
{
|
||||
if (std::find(labels.begin(), labels.end(), name) != labels.end())
|
||||
if (std::find(columnNames.begin(), columnNames.end(), name) != columnNames.end())
|
||||
throw std::runtime_error("duplicate column name");
|
||||
|
||||
labels.push_back(name);
|
||||
columnNames.push_back(name);
|
||||
types.push_back(scalarType);
|
||||
|
||||
return shared_from_this();
|
||||
@@ -43,9 +43,9 @@ StructureConstPtr NTTableBuilder::createStructure()
|
||||
addArray("labels", pvString)->
|
||||
addNestedStructure("value");
|
||||
|
||||
vector<string>::size_type len = labels.size();
|
||||
vector<string>::size_type len = columnNames.size();
|
||||
for (vector<string>::size_type i = 0; i < len; i++)
|
||||
nestedBuilder->addArray(labels[i], types[i]);
|
||||
nestedBuilder->addArray(columnNames[i], types[i]);
|
||||
|
||||
builder = nestedBuilder->endNested();
|
||||
|
||||
@@ -88,10 +88,12 @@ NTTableBuilder::shared_pointer NTTableBuilder::addTimeStamp()
|
||||
|
||||
PVStructurePtr NTTableBuilder::createPVStructure()
|
||||
{
|
||||
size_t len = labels.size();
|
||||
shared_vector<string> l(len);
|
||||
for(size_t i=0; i<len; ++i) l[i] = labels[i];
|
||||
PVStructurePtr s = getPVDataCreate()->createPVStructure(createStructure());
|
||||
|
||||
// fill in labels with default values (the column names)
|
||||
size_t len = columnNames.size();
|
||||
shared_vector<string> l(len);
|
||||
for(size_t i=0; i<len; ++i) l[i] = columnNames[i];
|
||||
s->getSubField<PVStringArray>("labels")->replace(freeze(l));
|
||||
return s;
|
||||
}
|
||||
@@ -108,7 +110,7 @@ NTTableBuilder::NTTableBuilder()
|
||||
|
||||
void NTTableBuilder::reset()
|
||||
{
|
||||
labels.clear();
|
||||
columnNames.clear();
|
||||
types.clear();
|
||||
descriptor = false;
|
||||
alarm = false;
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace detail {
|
||||
|
||||
/**
|
||||
* Create a <b>PVStructure</b> that represents NTTable.
|
||||
* The returned PVStructure will have labels equal to the column names.
|
||||
* This resets this instance state and allows new instance to be created.
|
||||
* @return a new instance of <b>PVStructure</b>.
|
||||
*/
|
||||
@@ -89,6 +90,8 @@ namespace detail {
|
||||
|
||||
/**
|
||||
* Create a <b>NTTable</b> instance.
|
||||
* The returned NTTable will wrap a PVStructure which will have
|
||||
* labels equal to the column names.
|
||||
* This resets this instance state and allows new instance to be created.
|
||||
* @return a new instance of <b>NTTable</b>.
|
||||
*/
|
||||
@@ -106,7 +109,7 @@ namespace detail {
|
||||
|
||||
void reset();
|
||||
|
||||
std::vector<std::string> labels;
|
||||
std::vector<std::string> columnNames;
|
||||
std::vector<epics::pvData::ScalarType> types;
|
||||
|
||||
bool descriptor;
|
||||
@@ -192,7 +195,7 @@ public:
|
||||
* Attach an pvAlarm.
|
||||
* @param pvAlarm The pvAlarm that will be attached.
|
||||
* Does nothing if no alarm.
|
||||
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
|
||||
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
|
||||
*/
|
||||
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user