added support for setting a different name for a template when it appears in a message
This commit is contained in:
+12
-3
@@ -1371,9 +1371,10 @@ void DataFieldTemplates::clear()
|
|||||||
m_fieldsByName.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);
|
map<string, DataField*>::iterator it = m_fieldsByName.find(name);
|
||||||
if (it != m_fieldsByName.end()) {
|
if (it != m_fieldsByName.end()) {
|
||||||
if (!replace)
|
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)
|
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;
|
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);
|
result_t result = DataField::create(begin, end, this, field, false, true, false);
|
||||||
if (result != RESULT_OK)
|
if (result != RESULT_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
result = add(field, true);
|
result = add(field, name, true);
|
||||||
if (result != RESULT_OK)
|
if (result != RESULT_OK)
|
||||||
delete field;
|
delete field;
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -730,11 +730,12 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Adds a template @a DataField instance to this map.
|
* Adds a template @a DataField instance to this map.
|
||||||
* @param field the @a DataField instance to add.
|
* @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.
|
* @param replace whether replacing an already stored instance is allowed.
|
||||||
* @return @a RESULT_OK on success, or an error code.
|
* @return @a RESULT_OK on success, or an error code.
|
||||||
* Note: the caller may not free the added instance on success.
|
* 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
|
// @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);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user