namespace assets {
class Asset;
class AssetPropertyModifier
{
int LookUpVectorIndex(Asset a, int type , int index);
int LookUpNameIndex(Asset a, std::string s);
public:
double GetPropertyValue(Asset a, std::string property_name,
double not_used_just_an_overloader);
void SetPropertyValue(Asset a, std::string property_name,
double new_double_value);
};//class AssetPropertyModifier
}//namespace assets
在APM.cpp文件中:
namespace assets {
//LookUpNameIndex definition
//LookUpVectorIndex defintion
double AssetPropertyModifier::GetPropertyValue(Asset a,
std::string property_name,
double not_used_just_an_overloader)
{
//Using Verbose output to debug:
std::cout << "------------GET-------------------" << std::endl;
int name_index = LookUpNameIndex(a, property_name);
std::cout << "names vector index is " << name_index << std::endl;
int double_index = LookUpVectorIndex(a, a.DOUBLE, name_index);
std::cout << "double property vector index is " << double_index <<
std::endl;
double property_value =
a.asset_property_double_.at(double_index).real_number_value_;
std::cout << property_name << " are equal to " << property_value <<
std::endl;
return property_value;
}
void AssetPropertyModifier::SetPropertyValue(Asset a,
std::string property_name,
double new_double_value)
{
//Using Verbose output to debug:
std::cout << "------------SET-------------------" << std::endl;
int name_index = LookUpNameIndex(a, property_name);
std::cout << "names vector index is " << name_index << std::endl;
int double_index = LookUpVectorIndex(a, a.DOUBLE, name_index);
std::cout << "double vector index is " << double_index << std::endl;
a.asset_property_double_.at(double_index).real_number_value_ =
new_double_value;
std::cout << property_name << " was changed to " <<
a.asset_property_double_.at(double_index).real_number_value_
<< std::endl;
}//SetPropertyValue
}//namespace assets
------------GET-------------------
names vector index is 0
double property vector index is 0
Property Name are equal to 5.5
Current value = 5.5
------------SET-------------------
names vector index is 0
double vector index is 0
Property Name was changed to 4.4
------------GET-------------------
names vector index is 0
double property vector index is 0
Property Name are equal to 5.5
Current value = 5.5
//hard SET with public access to the vector and the property struct value
my_asset.asset_property_double_.at(0).real_number_value_ = 3.3;
//hard GET with public access:
std::cout << my_asset.asset_property_double_.at(0).real_number_value_ <<
std::endl;
//GET through APM but with public values still enabled:
std::cout << "Current value = " << apm.GetPropertyValue(my_asset, some_name,
_DOUBLE_)
<< std::endl;
该输出为:
3.3
------------GET-------------------
names vector index is 0
double property vector index is 0
Property Name are equal to 3.3
Current value = 3.3