1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-27 10:50:10 +03:00

feature #200: New erase method for Template class: removes and frees attributes with the given name.

This commit is contained in:
Carlos Martín 2010-05-31 17:39:27 +02:00 committed by Constantino Vázquez Blanco
parent 518a74ad1a
commit 2ff230cd79
3 changed files with 37 additions and 28 deletions

View File

@ -117,6 +117,14 @@ public:
const string& name,
vector<Attribute *>& 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.

View File

@ -101,9 +101,7 @@ int ImagePool::allocate (
char * error_msg;
int rc;
int num_attr;
vector<Attribute *> 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);

View File

@ -205,6 +205,33 @@ int Template::remove(const string& name, vector<Attribute *>& values)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Template::erase(const string& name)
{
int removed;
int num_attr;
vector<Attribute *> 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<const Attribute*>& values) const