added support for setting a different name for a template when it appears in a message

This commit is contained in:
john30
2015-06-20 10:10:51 +02:00
parent 3751c11336
commit b0e97b01f5
2 changed files with 14 additions and 4 deletions
+12 -3
View File
@@ -1371,9 +1371,10 @@ void DataFieldTemplates::clear()
m_fieldsByName.clear();
}
result_t DataFieldTemplates::add(DataField* field, bool replace)
result_t DataFieldTemplates::add(DataField* field, string name, bool replace)
{
string name = field->getName();
if (name.length() == 0)
name = field->getName();
map<string, DataField*>::iterator it = m_fieldsByName.find(name);
if (it != m_fieldsByName.end()) {
if (!replace)
@@ -1393,11 +1394,19 @@ result_t DataFieldTemplates::add(DataField* field, bool replace)
result_t DataFieldTemplates::addFromFile(vector<string>::iterator& begin, const vector<string>::iterator end, void* arg, vector< vector<string> >* defaults, const string& filename, unsigned int lineNo)
{
DataField* field = NULL;
string name;
if (begin != end) {
size_t colon = begin->find(':');
if (colon!=string::npos) {
name = begin->substr(0, colon);
begin->erase(0, colon+1);
}
}
result_t result = DataField::create(begin, end, this, field, false, true, false);
if (result != RESULT_OK)
return result;
result = add(field, true);
result = add(field, name, true);
if (result != RESULT_OK)
delete field;
+2 -1
View File
@@ -730,11 +730,12 @@ public:
/**
* Adds a template @a DataField instance to this map.
* @param field the @a DataField instance to add.
* @param name the name to use in the map, or the empty string to use the @a DataField name.
* @param replace whether replacing an already stored instance is allowed.
* @return @a RESULT_OK on success, or an error code.
* Note: the caller may not free the added instance on success.
*/
result_t add(DataField* field, bool replace=false);
result_t add(DataField* field, string name="", bool replace=false);
// @copydoc
virtual result_t addFromFile(vector<string>::iterator& begin, const vector<string>::iterator end, void* arg, vector< vector<string> >* defaults, const string& filename, unsigned int lineNo);