diff --git a/include/Template.h b/include/Template.h index b8d7030197..d4763a7370 100644 --- a/include/Template.h +++ b/include/Template.h @@ -117,6 +117,14 @@ public: const string& name, vector& values); + + /** + * Removes an attribute from the template, and frees the attributes. + * @param name of the attribute + * @returns the number of attributes removed + */ + virtual int erase(const string& name); + /** * Gets all the attributes with the given name. * @param name the attribute name. diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 05d37f7c5f..ddaf5c50f6 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -101,9 +101,7 @@ int ImagePool::allocate ( char * error_msg; int rc; - int num_attr; - vector attrs; // --------------------------------------------------------------------- // Build a new Image object @@ -130,19 +128,8 @@ int ImagePool::allocate ( goto error_name; } - img->image_template.remove("NAME", attrs); + img->image_template.erase("NAME"); - // Clear attrs - if ((num_attr = (int) attrs.size()) > 0) - { - for (int i = 0; i < num_attr ; i++) - { - if (attrs[i] != 0) - { - delete attrs[i]; - } - } - } img->get_template_attribute("TYPE", type); @@ -152,20 +139,7 @@ int ImagePool::allocate ( } else { - attrs.clear(); - img->image_template.remove("TYPE", attrs); - - // Clear attrs - if ((num_attr = (int) attrs.size()) > 0) - { - for (int i = 0; i < num_attr ; i++) - { - if (attrs[i] != 0) - { - delete attrs[i]; - } - } - } + img->image_template.erase("TYPE"); } img->get_template_attribute("ORIGINAL_PATH", original_path); diff --git a/src/template/Template.cc b/src/template/Template.cc index f6d9ab64fb..d13aab59bd 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -205,6 +205,33 @@ int Template::remove(const string& name, vector& values) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int Template::erase(const string& name) +{ + int removed; + int num_attr; + vector attrs; + + // Call remove + removed = remove(name, attrs); + + // Clear attrs + if ((num_attr = (int) attrs.size()) > 0) + { + for (int i = 0; i < num_attr ; i++) + { + if (attrs[i] != 0) + { + delete attrs[i]; + } + } + } + + return removed; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + int Template::get( const string& name, vector& values) const