コード例 #1
0
ファイル: item.cpp プロジェクト: edubart/otserv
void ItemAttributes::setStrAttr(const itemAttrTypes& type, const std::string& value)
{
	if (!validateStrAttrType(type))
	{
		return;
	}

	if (value.length() == 0)
	{
		return;
	}

	//this will create the attribute if it does not exist
	Attribute* attr = getAttr(type);

	if (attr)
	{
		//if has a previous value delete it
		if (attr->value)
		{
			delete(std::string*)attr->value;
		}

		//create the new value as string
		attr->value = (void*)new std::string(value);
	}
}
コード例 #2
0
ファイル: item.cpp プロジェクト: TwistedScorpio/OTHire
void ItemAttributes::removeAttribute(itemAttrTypes type)
{
	//check if we have it
	if((type & m_attributes) != 0){
		//go trough the linked list until find it
		Attribute* prevAttr = NULL;
		Attribute* curAttr = m_firstAttr;
		while(curAttr != NULL){
			if(curAttr->type == type){
				//found so remove it from the linked list
				if(prevAttr){
					prevAttr->next = curAttr->next;
				}
				else{
					m_firstAttr = curAttr->next;
				}
				//remove it from flags
				m_attributes = m_attributes & ~type;

				//delete string if it is string type
				if(validateStrAttrType(type)){
					delete (std::string*)curAttr->value;
				}
				//finally delete the attribute and return
				delete curAttr;
				return;
			}

			//advance in the linked list
			prevAttr = curAttr;
			curAttr = curAttr->next;
		}
	}
}
コード例 #3
0
ファイル: item.cpp プロジェクト: oneshot-git/forgottenserver
const std::string& ItemAttributes::getStrAttr(itemAttrTypes type) const
{
	if (!validateStrAttrType(type)) {
		return emptyString;
	}

	Attribute* attr = getAttrConst(type);
	if (attr) {
		return *(std::string*)attr->value;
	} else {
		return emptyString;
	}
}
コード例 #4
0
ファイル: item.cpp プロジェクト: TwistedScorpio/OTHire
const std::string& ItemAttributes::getStrAttr(itemAttrTypes type) const
{
	if(!validateStrAttrType(type))
		return emptyString;

	//this will *NOT* create the attribute if it does not exist
	Attribute* attr = getAttrConst(type);
	if(attr){
		return *(std::string*)attr->value;
	}
	else{
		return emptyString;
	}
}
コード例 #5
0
ファイル: item.cpp プロジェクト: HeberPcL/forgottenserver
void ItemAttributes::deleteAttrs(Attribute* attr)
{
	if (attr) {
		if (validateStrAttrType(attr->type)) {
			delete (std::string*)attr->value;
		}

		Attribute* next_attr = attr->next;
		attr->next = NULL;

		if (next_attr) {
			deleteAttrs(next_attr);
		}

		delete attr;
	}
}
コード例 #6
0
ファイル: item.cpp プロジェクト: TwistedScorpio/OTHire
void ItemAttributes::deleteAttrs(Attribute* attr)
{
	//deletes all attributes recursively
	if(attr){
		//if is string type, delete the allocated string
		if(validateStrAttrType(attr->type)){
			delete (std::string*)attr->value;
		}
		Attribute* next_attr = attr->next;
		attr->next = NULL;
		//delete next while it was not NULL
		if(next_attr){
			deleteAttrs(next_attr);
		}
		delete attr;
	}
}
コード例 #7
0
ファイル: item.cpp プロジェクト: HeberPcL/forgottenserver
void ItemAttributes::setStrAttr(itemAttrTypes type, const std::string& value)
{
	if (!validateStrAttrType(type)) {
		return;
	}

	if (value.length() == 0) {
		return;
	}

	Attribute* attr = getAttr(type);

	if (attr) {
		if (attr->value) {
			delete (std::string*)attr->value;
		}

		attr->value = (void*)new std::string(value);
	}
}
コード例 #8
0
ファイル: item.cpp プロジェクト: edubart/otserv
const std::string& ItemAttributes::getStrAttr(const itemAttrTypes& type) const
{
	static const std::string EMPTY_STRING;

	if (!validateStrAttrType(type))
	{
		return EMPTY_STRING;
	}

	//this will *NOT* create the attribute if it does not exist
	Attribute* attr = getAttrConst(type);

	if (attr)
	{
		return *(std::string*)attr->value;
	}
	else
	{
		return EMPTY_STRING;
	}
}