本文整理汇总了C++中PropertyList::open方法的典型用法代码示例。如果您正苦于以下问题:C++ PropertyList::open方法的具体用法?C++ PropertyList::open怎么用?C++ PropertyList::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyList
的用法示例。
在下文中一共展示了PropertyList::open方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
std::shared_ptr<Object> ObjectFactory :: create(std::string name, std::string type)
{
// create an Object class as a prototype to open config file of above name
std::unique_ptr<Object> prototype;
if(!Filesystem::hasExtension(name))
name += ".ini";
// deduce type from ini
if(type.empty())
{
// trying to deduce type of object without extension is impossible
if(!Filesystem::hasExtension(name, "ini"))
{
assert(false);
return std::shared_ptr<Object>();
}
PropertyList properties;
boost::filesystem::path path = System::get().imageResources().locate(name);
name = path.string();
if(!properties.open(name.c_str()))
{
assert(false);
return std::shared_ptr<Object>();
}
type = properties.getString("default", "type", "");
if(type.empty())
{
assert(false);
return std::shared_ptr<Object>();
}
}
//// locate an object
//if(Filesystem::hasExtension("ini"))
//{
// std::vector<boost::filesystem::path> search_paths;
// if(type == "backdrop")
// search_paths.push_back(boost::filesystem::path("data/backdrops/"));
// else
// search_paths.push_back(boost::filesystem::path("data/objects/"));
// std::vector<std::string> extensions;
// extensions.push_back("ini"); // load as image
// boost::filesystem::path found = Filesystem::locate(name, search_paths, extensions);
// if(found)
// name = found.string();
//}
// dispatch pattern by object type, return Object pointer
try{
std::shared_ptr<Object> object;
// add more object types to this list
if(type == "enemy")
object.reset(new Enemy(name));
else if(type == "particle")
object.reset(new Particle(name));
else if(type == "backdrop")
object.reset(new Backdrop(name));
else if(type == "item")
object.reset(new Item(name));
else
return std::shared_ptr<Object>();
if(object)
m_pWorld->add(object);
return object;
} catch(const Failure& f){
assert(false);
}
return std::shared_ptr<Object>();
}