GenericObject.cpp
From Giona
(Difference between revisions)
| (2 intermediate revisions not shown) | |||
| Line 3: | Line 3: | ||
* GenericObject.cpp | * GenericObject.cpp | ||
* ================= | * ================= | ||
| - | |||
* Implementation of a generic object | * Implementation of a generic object | ||
| + | * -------------------------------------------------------- | ||
| + | * Author: Rosario Marino | ||
*/ | */ | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
#include "GenericObject.h" | #include "GenericObject.h" | ||
| Line 23: | Line 15: | ||
GenericObject::GenericObject() | GenericObject::GenericObject() | ||
{ | { | ||
| - | this->attributeList = new | + | Debug::debug("GenericObject::GenericObject()"); |
| + | this->attributeList = new GenericAttributeList(); | ||
this->description = EMPTY_STRING; | this->description = EMPTY_STRING; | ||
this->name = EMPTY_STRING; | this->name = EMPTY_STRING; | ||
| - | this->lastError = | + | this->lastError = ERROR_NO; |
} | } | ||
| Line 34: | Line 27: | ||
int GenericObject::getLastError() | int GenericObject::getLastError() | ||
{ | { | ||
| + | Debug::debug("int GenericObject::getLastError()"); | ||
return this->lastError; | return this->lastError; | ||
} | } | ||
| Line 40: | Line 34: | ||
* Sets the name of the object | * Sets the name of the object | ||
*/ | */ | ||
| - | + | bool GenericObject::setName(STRING name) | |
{ | { | ||
| + | Debug::debug("bool GenericObject::setName(STRING name)"); | ||
| + | if(name==NULL) | ||
| + | { | ||
| + | Debug::debugError("bool GenericObject::setName(STRING name)", "ERROR_NULL_PARAMETER", "parameter: name"); | ||
| + | this->lastError=ERROR_NULL_PARAMETER; | ||
| + | return false; | ||
| + | } | ||
| + | if(strcmp(name, EMPTY_STRING)==0) | ||
| + | { | ||
| + | Debug::debugError("bool GenericObject::setName(STRING name)", "ERROR_EMPTY_STRING", "parameter: name");; | ||
| + | this->lastError=ERROR_EMPTY_STRING; | ||
| + | return false; | ||
| + | } | ||
this->name = name; | this->name = name; | ||
| + | return true; | ||
} | } | ||
| Line 50: | Line 58: | ||
STRING GenericObject::getName() | STRING GenericObject::getName() | ||
{ | { | ||
| + | Debug::debug("STRING GenericObject::getName()"); | ||
return this->name; | return this->name; | ||
} | } | ||
| Line 58: | Line 67: | ||
int GenericObject::getAttributeNumber() | int GenericObject::getAttributeNumber() | ||
{ | { | ||
| - | return this->attributeList-> | + | Debug::debug("int GenericObject::getAttributeNumber()"); |
| + | return this->attributeList->getAttributeNumber(); | ||
} | } | ||
| Line 64: | Line 74: | ||
* Sets the description of the object | * Sets the description of the object | ||
*/ | */ | ||
| - | + | bool GenericObject::setDescription(STRING description) | |
{ | { | ||
| + | Debug::debug("bool GenericObject::setDescription(STRING description)"); | ||
| + | if(description==NULL) | ||
| + | { | ||
| + | Debug::debugError("bool GenericObject::setDescription(STRING description)", "ERROR_NULL_PARAMETER", "parameter: description"); | ||
| + | this->lastError=ERROR_NULL_PARAMETER; | ||
| + | return false; | ||
| + | } | ||
| + | if(strcmp(description, EMPTY_STRING)==0) | ||
| + | { | ||
| + | Debug::debugError("bool GenericObject::setDescription(STRING description)", "ERROR_EMPTY_STRING", "parameter: description"); | ||
| + | this->lastError=ERROR_EMPTY_STRING; | ||
| + | return false; | ||
| + | } | ||
this->description = description; | this->description = description; | ||
| + | return true; | ||
} | } | ||
| Line 74: | Line 98: | ||
STRING GenericObject::getDescription() | STRING GenericObject::getDescription() | ||
{ | { | ||
| + | Debug::debug("STRING GenericObject::getDescription()"); | ||
return this->description; | return this->description; | ||
} | } | ||
/* | /* | ||
| - | * Returns the value of the attribute | + | * Returns the value of the attribute. |
| + | * Returns NULL in case of error | ||
*/ | */ | ||
STRING GenericObject::getAttributeValue(STRING name) | STRING GenericObject::getAttributeValue(STRING name) | ||
{ | { | ||
| - | STRING | + | Debug::debug("STRING GenericObject::getAttributeValue(STRING name)"); |
| - | + | STRING value=this->attributeList->getAttributeValue(name); | |
| - | if( | + | if(value==NULL) |
| - | + | { | |
| + | this->lastError=ERROR_GENERIC_ATTRIBUTE_LIST_ERROR; | ||
| + | Debug::debugError("STRING GenericObject::getAttributeValue(STRING name)","ERROR_GENERIC_ATTRIBUTE_LIST_ERROR", "Try to run with debug error activated"); | ||
| + | } | ||
return value; | return value; | ||
} | } | ||
/* | /* | ||
| - | * Returns the description of the attribute | + | * Returns the description of the attribute. Returns NULL in case of error |
*/ | */ | ||
| - | STRING GenericObject::getAttributeDescription(STRING | + | STRING GenericObject::getAttributeDescription(STRING name) |
{ | { | ||
| - | STRING | + | Debug::debug("STRING GenericObject::getAttributeDescription(STRING name)"); |
| - | + | STRING description=this->attributeList->getAttributeDescription(name); | |
| - | if( | + | if(description==NULL) |
| - | + | { | |
| - | return | + | this->lastError=ERROR_GENERIC_ATTRIBUTE_LIST_ERROR; |
| + | Debug::debugError("STRING GenericObject::getAttributeDescription(STRING name)","ERROR_GENERIC_ATTRIBUTE_LIST_ERROR", "Try to run with debug error activated"); | ||
| + | } | ||
| + | return description; | ||
} | } | ||
| + | /* | ||
| + | * Delete the attribute | ||
| + | * Returns false in case of error | ||
| + | */ | ||
| + | bool GenericObject::deleteAttibute(STRING name) | ||
| + | { | ||
| + | if(!this->attributeList->deleteAttibute(name)) | ||
| + | { | ||
| + | this->lastError=ERROR_GENERIC_ATTRIBUTE_LIST_ERROR; | ||
| + | Debug::debugError("bool GenericObject::deleteAttibute(STRING name)","ERROR_GENERIC_ATTRIBUTE_LIST_ERROR", "Try to run with debug error activated"); | ||
| + | return false; | ||
| + | } | ||
| + | return true; | ||
| + | } | ||
/* | /* | ||
* Sets the value of the attribute | * Sets the value of the attribute | ||
* If the attribute with such name does not exists, a new one | * If the attribute with such name does not exists, a new one | ||
| - | * is created | + | * is created. Returns false in case of error. |
*/ | */ | ||
| - | + | bool GenericObject::setAttributeValue(STRING name, STRING value) | |
{ | { | ||
| - | + | if(!this->attributeList->setAttributeValue(name,value)) | |
| - | + | ||
{ | { | ||
| - | + | this->lastError=ERROR_GENERIC_ATTRIBUTE_LIST_ERROR; | |
| - | + | Debug::debugError("bool GenericObject::setAttributeValue(STRING name, STRING value)","ERROR_GENERIC_ATTRIBUTE_LIST_ERROR", "Try to run with debug error activated"); | |
| - | + | return false; | |
| - | + | ||
| - | + | ||
} | } | ||
| - | + | return true; | |
} | } | ||
| Line 124: | Line 167: | ||
* returns FALSE if the attribute does not exist | * returns FALSE if the attribute does not exist | ||
*/ | */ | ||
| - | + | bool GenericObject::setAttributeDescription(STRING name, STRING description) | |
| - | + | { | |
| - | + | if(!this->attributeList->setAttributeDescription(name,description)) | |
| - | + | { | |
| - | + | this->lastError=ERROR_GENERIC_ATTRIBUTE_LIST_ERROR; | |
| - | + | Debug::debugError("bool GenericObject::setAttributeDescription(STRING name, STRING description)","ERROR_GENERIC_ATTRIBUTE_LIST_ERROR", "Try to run with debug error activated"); | |
| - | return | + | return false; |
| + | } | ||
| + | return true; | ||
} | } | ||
| Line 138: | Line 183: | ||
STRING* GenericObject::getAttributeNameList() | STRING* GenericObject::getAttributeNameList() | ||
{ | { | ||
| - | + | Debug::debug("STRING* GenericObject::getAttributeNameList()"); | |
| - | + | return this->attributeList->getAttributeNameList(); | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
} | } | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
/* | /* | ||
| Line 179: | Line 192: | ||
GenericObject::~GenericObject() | GenericObject::~GenericObject() | ||
{ | { | ||
| + | Debug::debug("GenericObject::~GenericObject()"); | ||
delete (attributeList); | delete (attributeList); | ||
} | } | ||
| - | |||
| - | |||
</pre> | </pre> | ||
| + | [[Il database Object Oriented Generico|BACK]] | ||
[[Category:Codice Sorgente]] | [[Category:Codice Sorgente]] | ||
Current revision as of 16:28, 19 December 2007
/*
* GenericObject.cpp
* =================
* Implementation of a generic object
* --------------------------------------------------------
* Author: Rosario Marino
*/
#include "GenericObject.h"
/*
* Constructor
*/
GenericObject::GenericObject()
{
Debug::debug("GenericObject::GenericObject()");
this->attributeList = new GenericAttributeList();
this->description = EMPTY_STRING;
this->name = EMPTY_STRING;
this->lastError = ERROR_NO;
}
/*
* Returns last error code
*/
int GenericObject::getLastError()
{
Debug::debug("int GenericObject::getLastError()");
return this->lastError;
}
/*
* Sets the name of the object
*/
bool GenericObject::setName(STRING name)
{
Debug::debug("bool GenericObject::setName(STRING name)");
if(name==NULL)
{
Debug::debugError("bool GenericObject::setName(STRING name)", "ERROR_NULL_PARAMETER", "parameter: name");
this->lastError=ERROR_NULL_PARAMETER;
return false;
}
if(strcmp(name, EMPTY_STRING)==0)
{
Debug::debugError("bool GenericObject::setName(STRING name)", "ERROR_EMPTY_STRING", "parameter: name");;
this->lastError=ERROR_EMPTY_STRING;
return false;
}
this->name = name;
return true;
}
/*
* Returns the name of the object
*/
STRING GenericObject::getName()
{
Debug::debug("STRING GenericObject::getName()");
return this->name;
}
/*
* Returns the number of attributes
*/
int GenericObject::getAttributeNumber()
{
Debug::debug("int GenericObject::getAttributeNumber()");
return this->attributeList->getAttributeNumber();
}
/*
* Sets the description of the object
*/
bool GenericObject::setDescription(STRING description)
{
Debug::debug("bool GenericObject::setDescription(STRING description)");
if(description==NULL)
{
Debug::debugError("bool GenericObject::setDescription(STRING description)", "ERROR_NULL_PARAMETER", "parameter: description");
this->lastError=ERROR_NULL_PARAMETER;
return false;
}
if(strcmp(description, EMPTY_STRING)==0)
{
Debug::debugError("bool GenericObject::setDescription(STRING description)", "ERROR_EMPTY_STRING", "parameter: description");
this->lastError=ERROR_EMPTY_STRING;
return false;
}
this->description = description;
return true;
}
/*
* Returns the description of the object
*/
STRING GenericObject::getDescription()
{
Debug::debug("STRING GenericObject::getDescription()");
return this->description;
}
/*
* Returns the value of the attribute.
* Returns NULL in case of error
*/
STRING GenericObject::getAttributeValue(STRING name)
{
Debug::debug("STRING GenericObject::getAttributeValue(STRING name)");
STRING value=this->attributeList->getAttributeValue(name);
if(value==NULL)
{
this->lastError=ERROR_GENERIC_ATTRIBUTE_LIST_ERROR;
Debug::debugError("STRING GenericObject::getAttributeValue(STRING name)","ERROR_GENERIC_ATTRIBUTE_LIST_ERROR", "Try to run with debug error activated");
}
return value;
}
/*
* Returns the description of the attribute. Returns NULL in case of error
*/
STRING GenericObject::getAttributeDescription(STRING name)
{
Debug::debug("STRING GenericObject::getAttributeDescription(STRING name)");
STRING description=this->attributeList->getAttributeDescription(name);
if(description==NULL)
{
this->lastError=ERROR_GENERIC_ATTRIBUTE_LIST_ERROR;
Debug::debugError("STRING GenericObject::getAttributeDescription(STRING name)","ERROR_GENERIC_ATTRIBUTE_LIST_ERROR", "Try to run with debug error activated");
}
return description;
}
/*
* Delete the attribute
* Returns false in case of error
*/
bool GenericObject::deleteAttibute(STRING name)
{
if(!this->attributeList->deleteAttibute(name))
{
this->lastError=ERROR_GENERIC_ATTRIBUTE_LIST_ERROR;
Debug::debugError("bool GenericObject::deleteAttibute(STRING name)","ERROR_GENERIC_ATTRIBUTE_LIST_ERROR", "Try to run with debug error activated");
return false;
}
return true;
}
/*
* Sets the value of the attribute
* If the attribute with such name does not exists, a new one
* is created. Returns false in case of error.
*/
bool GenericObject::setAttributeValue(STRING name, STRING value)
{
if(!this->attributeList->setAttributeValue(name,value))
{
this->lastError=ERROR_GENERIC_ATTRIBUTE_LIST_ERROR;
Debug::debugError("bool GenericObject::setAttributeValue(STRING name, STRING value)","ERROR_GENERIC_ATTRIBUTE_LIST_ERROR", "Try to run with debug error activated");
return false;
}
return true;
}
/*
* Sets the description of the attribute if it exists.
* returns FALSE if the attribute does not exist
*/
bool GenericObject::setAttributeDescription(STRING name, STRING description)
{
if(!this->attributeList->setAttributeDescription(name,description))
{
this->lastError=ERROR_GENERIC_ATTRIBUTE_LIST_ERROR;
Debug::debugError("bool GenericObject::setAttributeDescription(STRING name, STRING description)","ERROR_GENERIC_ATTRIBUTE_LIST_ERROR", "Try to run with debug error activated");
return false;
}
return true;
}
/*
* Returns the array of all attribute names
*/
STRING* GenericObject::getAttributeNameList()
{
Debug::debug("STRING* GenericObject::getAttributeNameList()");
return this->attributeList->getAttributeNameList();
}
/*
* Destructor
*/
GenericObject::~GenericObject()
{
Debug::debug("GenericObject::~GenericObject()");
delete (attributeList);
}
