本文整理汇总了C++中FileReader::get_name方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::get_name方法的具体用法?C++ FileReader::get_name怎么用?C++ FileReader::get_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::get_name方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void
ResourceManager::parse(const std::string& section, FileReader& reader)
{
if (reader.get_name() == "section")
{
parse_section(section, reader);
}
else if (reader.get_name() == "sprite")
{
std::string name;
reader.read_string("name", name);
if (!section.empty())
name = section + "/" + name;
if (resources[name])
delete resources[name];
resources[name] = new SpriteDescription(reader);
}
else if (reader.get_name() == "alias")
{
std::string name;
std::string link;
reader.read_string("name", name);
reader.read_string("link", link);
//std::cout << "alias: " << name << " -> " << link << std::endl;
}
else if (reader.get_name() == "name")
{
// ignore (ugly)
}
else
{
std::cout << "ResourceManager: unknown token: '" << reader.get_name() << "'" << std::endl;
}
}
示例2: if
void
SectorBuilder::parse_object(const FileReader& reader)
{
GameObjectHandle obj;
if(reader.get_name() == "tilemap")
{
std::auto_ptr<TileMap> tilemap(new TileMap(reader));
if (tilemap->get_name() == "interactive")
m_sector.interactive_tilemap = tilemap.get();
else if (tilemap->get_name() == "interactivebackground")
m_sector.interactivebackground_tilemap = tilemap.get();
obj.reset(tilemap.release());
}
else if (reader.get_name() == "navgraph-edge-ref")
{
// FIXME: Implement me
}
else if(reader.get_name() == "background")
{
// TODO
}
else if(reader.get_name() == "layer")
{
parse_layer(reader);
}
else
{
obj = ObjectFactory::create(reader);
if (!obj)
{
std::cout << "Skipping unknown Object: " << reader.get_name() << "\n";
}
}
if (obj)
{
std::string id_str;
if (reader.read("id", id_str))
{
id_table[id_str] = obj;
}
std::string parent_str;
if (reader.read("parent", parent_str))
{
if (!parent_str.empty())
parent_table[obj] = parent_str;
}
m_sector.add(obj);
}
}
示例3: runtime_error
TileFactory::TileFactory(const Pathname& filename) :
tiles(),
packers(),
color_packer(),
descriptions()
{
packers.push_back(new TilePacker(1024, 1024));
packers.push_back(new TilePacker(1024, 1024));
color_packer = 0;
FileReader reader = FileReader::parse(filename);
if(reader.get_name() != "windstille-tiles")
{
std::ostringstream msg;
msg << "'" << filename << "' is not a windstille tiles file";
throw std::runtime_error(msg.str());
}
std::vector<FileReader> sections = reader.get_sections();
for(std::vector<FileReader>::iterator i = sections.begin(); i != sections.end(); ++i)
{
if (i->get_name() == "tiles") {
parse_tiles(*i);
} else if (i->get_name() == "tilegroup") {
// ignore
}
}
}
示例4: if
ServerEvent::ServerEvent(const FileReader& reader) :
type(PINGU_ACTION_EVENT),
time_stamp(0),
pingu_id(0),
pos(),
pingu_action(ActionName::WALKER)
{
if (reader.get_name() == "armageddon")
{
type = ARMAGEDDON_EVENT;
reader.read_int("time", time_stamp);
}
else if (reader.get_name() == "end")
{
type = END_EVENT;
reader.read_int("time", time_stamp);
}
else if (reader.get_name() == "finish")
{
type = FINISH_EVENT;
reader.read_int("time", time_stamp);
}
else if (reader.get_name() == "pingu-action")
{
std::string raw_x;
std::string raw_y;
type = PINGU_ACTION_EVENT;
reader.read_int ("time", time_stamp);
reader.read_int ("id", pingu_id);
if (reader.read_string("raw-x", raw_x))
pos.x = Math::string2float(raw_x);
if (reader.read_string("raw-y", raw_y))
pos.y = Math::string2float(raw_y);
reader.read_enum("action", pingu_action, &ActionName::from_string);
}
else
{
throw std::runtime_error(std::string("ServerEvent: Parse error: Unknown event: ")
+ reader.get_name());
}
}
示例5: if
void
WorldObjRenderer::process_object_with_surface(const FileReader& reader)
{
Vector3f pos;
ResDescriptor desc;
if (!(reader.read_vector("position", pos) &&
reader.read_desc("surface", desc)))
{
log_error("object (%1%) does not have 'position' and 'surface'", reader.get_name());
}
else
{
if (reader.get_name() == "exit" ||
reader.get_name() == "hotspots")
{
render_sprite(desc, pos);
}
else if (reader.get_name() == "groundpiece")
{
std::string type;
reader.read_string("type", type);
if (type == "remove")
{
// FIXME: don't have blit_remove()
render_surface(desc, pos);
}
else
{
render_surface(desc, pos);
}
}
else
{
int repeat = 1;
reader.read_int("repeat", repeat);
render_surface(desc, pos, repeat);
}
}
}
示例6: from_file_reader
Options
Options::from_file(const Pathname& filename)
{
FileReader reader = FileReader::parse(filename);
if (reader.get_name() != "pingus-config")
{
raise_exception(std::runtime_error, "Error: " << filename << ": not a (pingus-config) file");
}
return from_file_reader(reader);
}
示例7: pathname
FontDescription::FontDescription(const Pathname& pathname_) :
pathname(pathname_),
char_spacing(),
vertical_spacing(),
size(),
images()
{
char_spacing = 1.0f;
vertical_spacing = 1.0f;
FileReader reader = FileReader::parse(pathname);
if (reader.get_name() != "pingus-font")
{
raise_exception(std::runtime_error, "FontDescription: not a pingus-font file");
}
else
{
reader.read_float("char-spacing", char_spacing);
reader.read_float("vertical-spacing", vertical_spacing);
reader.read_int("size", size);
FileReader images_reader;
if (reader.read_section("images", images_reader))
{
std::vector<FileReader> images_lst = images_reader.get_sections();
for(std::vector<FileReader>::iterator i = images_lst.begin(); i != images_lst.end(); ++i)
{
GlyphImageDescription image_desc;
i->read_path("filename", image_desc.pathname);
FileReader glyph_section;
if (i->read_section("glyphs", glyph_section))
{
std::vector<FileReader> glyph_reader = glyph_section.get_sections();
for(std::vector<FileReader>::iterator j = glyph_reader.begin(); j != glyph_reader.end(); ++j)
{
image_desc.glyphs.push_back(GlyphDescription(*j));
}
}
images.push_back(image_desc);
}
}
}
}
示例8: runtime_error
SectorBuilder::SectorBuilder(const Pathname& filename, Sector& sector) :
m_filename(filename),
m_sector(sector),
id_table(),
parent_table()
{
FileReader reader = FileReader::parse(m_filename);
if(reader.get_name() != "windstille-sector")
{
std::ostringstream msg;
msg << "'" << m_filename << "' is not a windstille-sector file";
throw std::runtime_error(msg.str());
}
else
{
parse_body(reader);
}
}
示例9: completion
Levelset::Levelset(const Pathname& pathname)
: completion(0)
{
FileReader reader = FileReader::parse(pathname);
if (reader.get_name() != "pingus-levelset")
{
PingusError::raise("Error: " + pathname.str() + ": not a 'pingus-levelset' file");
}
else
{
reader.read_string("title", title);
reader.read_string("description", description);
std::string image;
if (reader.read_string("image", image))
this->image = Resource::load_sprite(image);
FileReader level_reader = reader.read_section("levels");
std::vector<FileReader> sections = level_reader.get_sections();
for(std::vector<FileReader>::iterator i = sections.begin(); i != sections.end(); ++i)
{
if (i->get_name() == "level")
{
Level* level = new Level();
if (i->read_string("filename", level->resname))
{
level->plf = PLFResMgr::load_plf(level->resname);
level->accessible = false;
level->finished = false;
levels.push_back(level);
}
else
{
std::cout << "Levelset: " << pathname.str() << " is missing filename tag" << std::endl;
delete level;
}
}
}
}
refresh();
}
示例10: get_name
std::string get_name() const
{
return m_reader.get_name();
}
示例11: runtime_error
SpriteData::SpriteData(const Pathname& pathname) :
actions()
{
if (pathname.exists())
{
const std::string ext = pathname.get_extension();
if (ext == "sprite")
{
FileReader reader = FileReader::parse(pathname);
if(reader.get_name() != "sprite") {
std::ostringstream msg;
msg << "File " << pathname << " is not a windstille sprite";
throw std::runtime_error(msg.str());
}
parse(pathname.get_dirname(), reader);
}
else if (ext == "png" || ext == "jpg")
{
std::auto_ptr<SpriteAction> action(new SpriteAction());
action->name = "default";
action->speed = 1.0;
action->scale = 1.0f;
action->offset = Vector2f(0, 0);
action->surfaces.push_back(Surface::create(pathname));
actions.push_back(action.release());
}
else
{
std::ostringstream str;
str << "Sprite " << pathname << " has unknown suffix: '" << ext << "'";
throw std::runtime_error(str.str());
}
}
else if (pathname.get_raw_path().length() > std::string(".sprite").length())
{ // If sprite file is not found, we search for a file with the
// same name ending in .png
Pathname pngfile(pathname.get_raw_path().substr(0, pathname.get_raw_path().length() - std::string(".sprite").length()) + ".png",
pathname.get_type());
if (pngfile.exists())
{
std::auto_ptr<SpriteAction> action(new SpriteAction);
action->name = "default";
action->speed = 1.0;
action->scale = 1.0f;
action->offset = Vector2f(0, 0);
action->surfaces.push_back(Surface::create(pngfile));
actions.push_back(action.release());
}
else
{
std::ostringstream str;
str << "Couldn't find " << pngfile;
throw std::runtime_error(str.str());
}
}
else
{
std::ostringstream str;
str << "Couldn't find " << pathname;
throw std::runtime_error(str.str());
}
}
示例12: runtime_error
Controller*
Manager::create_controller(const Pathname& filename)
{
std::unique_ptr<Controller> controller(new Controller(desc));
FileReader reader = FileReader::parse(filename);
if (reader.get_name() != "pingus-controller")
{
throw std::runtime_error("Controller: invalid config file '" + filename.str() + "'");
}
else
{
const std::vector<FileReader>& sections = reader.get_sections();
for (std::vector<FileReader>::const_iterator i = sections.begin();
i != sections.end(); ++i)
{
if (StringUtil::has_suffix(i->get_name(), "pointer"))
{
const std::vector<FileReader>& pointers = i->get_sections();
for(std::vector<FileReader>::const_iterator j = pointers.begin(); j != pointers.end(); ++j)
{
int id = desc.get_definition(i->get_name()).id;
ControllerPointer* ctrl_pointer = controller->get_pointer(id);
Pointer* pointer = create_pointer(*j, ctrl_pointer);
if (pointer)
ctrl_pointer->add_pointer(pointer);
else
std::cout << "Manager: pointer: Couldn't create pointer " << j->get_name() << std::endl;
}
}
else if (StringUtil::has_suffix(i->get_name(), "scroller"))
{
const std::vector<FileReader>& scrollers = i->get_sections();
for(std::vector<FileReader>::const_iterator j = scrollers.begin(); j != scrollers.end(); ++j)
{
int id = desc.get_definition(i->get_name()).id;
ControllerScroller* ctrl_scroller = controller->get_scroller(id);
Scroller* scroller = create_scroller(*j, ctrl_scroller);
if (scroller)
ctrl_scroller->add_scroller(scroller);
else
std::cout << "Manager: scroller: Couldn't create scroller " << j->get_name() << std::endl;
}
}
else if (StringUtil::has_suffix(i->get_name(), "button"))
{
const std::vector<FileReader>& buttons = i->get_sections();
for(std::vector<FileReader>::const_iterator j = buttons.begin(); j != buttons.end(); ++j)
{
int id = desc.get_definition(i->get_name()).id;
ControllerButton* ctrl_button = controller->get_button(id);
Button* button = create_button(*j, ctrl_button);
if (button)
ctrl_button->add_button(button);
else
std::cout << "Manager: button: Couldn't create button " << j->get_name() << std::endl;
}
}
else if (StringUtil::has_suffix(i->get_name(), "axis"))
{
const std::vector<FileReader>& axes = i->get_sections();
for(std::vector<FileReader>::const_iterator j = axes.begin(); j != axes.end(); ++j)
{
int id = desc.get_definition(i->get_name()).id;
ControllerAxis* ctrl_axis = controller->get_axis(id);
Axis* axis = create_axis(*j, ctrl_axis);
if (axis)
ctrl_axis->add_axis(axis);
else
std::cout << "Manager: axis: Couldn't create axis " << j->get_name() << std::endl;
}
}
else if (StringUtil::has_suffix(i->get_name(), "keyboard"))
{
const std::vector<FileReader>& keyboards = i->get_sections();
for(std::vector<FileReader>::const_iterator j = keyboards.begin(); j != keyboards.end(); ++j)
{
int id = desc.get_definition(i->get_name()).id;
ControllerKeyboard* ctrl_keyboard = controller->get_keyboard(id);
Keyboard* keyboard = create_keyboard(*j, ctrl_keyboard);
if (keyboard)
ctrl_keyboard->add_keyboard(keyboard);
else
std::cout << "Manager: keyboard: Couldn't create keyboard " << j->get_name() << std::endl;
}
}
else
{
throw std::runtime_error(std::string("Manager: Unkown Element in Controller Config: ")
+ i->get_name());
}
}
}
Controller* ctrl = controller.release();
controllers.push_back(ctrl);
return ctrl;
//.........这里部分代码省略.........
示例13: pout
void
PingusLevel::load(const std::string& resname,
const Pathname& pathname)
{
impl->resname = resname;
FileReader reader = FileReader::parse(pathname);
if (reader.get_name() != "pingus-level")
{
PingusError::raise("Error: " + pathname.str() + ": not a 'pingus-level' file");
}
else
{
int version;
if (reader.read_int("version", version))
pout(PINGUS_DEBUG_LOADING) << "Levelfile Version: " << version << std::endl;
else
pout(PINGUS_DEBUG_LOADING) << "Unknown Levelfile Version: " << version << std::endl;
FileReader head;
if (!reader.read_section("head", head))
{
PingusError::raise("Error: (head) section not found in '" + pathname.str() + "'");
}
else
{
pout(PINGUS_DEBUG_LOADING) << "Reading head" << std::endl;
head.read_string("levelname", impl->levelname);
head.read_string("description", impl->description);
head.read_size ("levelsize", impl->size);
head.read_string("music", impl->music);
head.read_int ("time", impl->time);
head.read_int ("difficulty", impl->difficulty);
head.read_int ("number-of-pingus", impl->number_of_pingus);
head.read_int ("number-to-save", impl->number_to_save);
head.read_color ("ambient-light", impl->ambient_light);
head.read_string("author", impl->author);
pout(PINGUS_DEBUG_LOADING) << "Size: " << impl->size.width << " " << impl->size.height << std::endl;
FileReader actions;
if (head.read_section("actions", actions))
{
std::vector<std::string> lst = actions.get_section_names();
for(std::vector<std::string>::iterator i = lst.begin(); i != lst.end(); ++i)
{
int count = 0;
pout(PINGUS_DEBUG_LOADING) << "Actions: " << i->c_str() << std::endl;
if (actions.read_int(i->c_str(), count))
impl->actions[*i] = count;
}
}
else
{
PingusError::raise("Error: (pingus-level head actions) not found in '" + pathname.str() + "'");
}
}
FileReader objects;
if (reader.read_section("objects", objects))
{
std::vector<FileReader> object_lst = objects.get_sections();
for(std::vector<FileReader>::iterator i = object_lst.begin(); i != object_lst.end(); ++i)
{
impl->objects.push_back(*i);
}
}
}
}