本文整理汇总了C++中XMLElement::BoolAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLElement::BoolAttribute方法的具体用法?C++ XMLElement::BoolAttribute怎么用?C++ XMLElement::BoolAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLElement
的用法示例。
在下文中一共展示了XMLElement::BoolAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Initialize
int CTransportConfig::Initialize(const char* confname)
{
if (m_transports.size() <= 0)
{
XMLDocument doc;
if (doc.LoadFile(confname) != XML_NO_ERROR)
{
throw CMudException("load xml transports config file failed");
}
XMLHandle docHandle(&doc);
XMLHandle current_handle = docHandle.FirstChildElement("config").FirstChildElement("transports").FirstChild();
XMLElement* elem = current_handle.ToElement();
while (elem)
{
int id = elem->IntAttribute("id");
m_transports[id].id = id;
m_transports[id].name = elem->Attribute("name");
m_transports[id].x = elem->IntAttribute("x");
m_transports[id].y = elem->IntAttribute("y");
m_transports[id].enabled = elem->BoolAttribute("enabled");
STDOUT_DEBUG("id=%d, name=%s, x=%d, y=%d, enabled=%d",
id, m_transports[id].name.c_str(), m_transports[id].x, m_transports[id].y, m_transports[id].enabled);
elem = current_handle.NextSibling().ToElement();
}
}
return 0;
}
示例2: init
void VisualComponent::init(XMLElement *xmlData)
{
XMLElement *visibleElt = xmlData->FirstChildElement("Visible");
// if no visibility if specified, default to true
if (visibleElt == nullptr)
visible = true;
else
{
visible = visibleElt->BoolAttribute("value");
}
XMLElement *textureElt = xmlData->FirstChildElement("Texture");
// if no texture is specified, set it to null
if (textureElt == nullptr)
texture = nullptr;
else
{
string texID = textureElt->Attribute("id");
texture = TextureManager::get()->getTexture(texID);
}
XMLElement *dimElt = xmlData->FirstChildElement("Dimensions");
// if both are null, we have no dimension data
if (dimElt == nullptr && textureElt == nullptr)
throw BAD_DIMENSION_ERR;
// if no dimensions are specified, take them from the texture
else if (dimElt == nullptr)
{
width = texture->width;
height = texture->height;
}
else
{
width = dimElt->DoubleAttribute("w");
height = dimElt->DoubleAttribute("h");
}
XMLElement *colorElt = xmlData->FirstChildElement("Color");
// if no color is specified, default to white
if (colorElt == nullptr)
colorData = bm::Color(255, 255, 255, 255);
else
{
int r = colorElt->IntAttribute("r");
int g = colorElt->IntAttribute("g");
int b = colorElt->IntAttribute("b");
int a = colorElt->IntAttribute("a");
colorData = bm::Color(r, g, b, a);
}
}
示例3: if
void
GameObject::LoadProperties( XMLElement & e )
{
XMLElement * prop = e.FirstChildElement("Property");
while ( prop ){
g_Log << "Property id is: " << prop->Attribute("id") << "\n";
if ( !prop->Attribute("id") ) throw AttributeMissingException("Property - No id attribute");
if ( !prop->Attribute("type") ) throw AttributeMissingException("Property - No type attribute");
if ( !prop->Attribute("value") ) throw AttributeMissingException("Property - No value attribute");
string type = prop->Attribute("type");
if ( type == "bool" ) AddProperty( prop->Attribute("id"), prop->BoolAttribute("value"));
else if ( type == "int" ) AddProperty( prop->Attribute("id"), prop->IntAttribute("value"));
else if ( type == "float" ) AddProperty( prop->Attribute("id"), prop->FloatAttribute("value"));
else if ( type == "string" ) AddProperty( prop->Attribute("id"), prop->Attribute("value"));
else throw InvalidAttributeException("Invalid attribute type defined!");
prop = prop->NextSiblingElement("Property");
}
}
示例4: load
int Configure::load(const string& xmlpath)
{
if (m_doc.LoadFile(xmlpath.c_str()) != XML_NO_ERROR) {
g_sysLog.e("{Configure} can't load xml %s\n", xmlpath.c_str());
return ERR_LDCFG;
}
XMLElement* rootElement = m_doc.RootElement();
if (rootElement == NULL) {
g_sysLog.e("{Configure} can't get root element %s\n", xmlpath.c_str());
return ERR_LDCFG;
} else {
bool reset = rootElement->IntAttribute("reset");
if (reset)
return ERR_LDCFG;
int ver = rootElement->IntAttribute("version");
if (ver != CONF_VERSION)
return ERR_LDCFG; // Recreate configure.xml
}
XMLElement* tempElement = rootElement->FirstChildElement("srclan");
if (tempElement && tempElement->GetText()) {
m_srcLan = tempElement->GetText();
}
tempElement = rootElement->FirstChildElement("detlan");
if (tempElement && tempElement->GetText()) {
m_detLan = tempElement->GetText();
}
// Loading dictionary
vector<string> dictFiles;
scanDictDir(dictFiles);
XMLElement* dictsElement = rootElement->FirstChildElement("dict");
XMLElement* dictElement = dictsElement->FirstChildElement();
while (dictElement) {
struct DictNode dict;
const char* textE;
int pos;
if (dictElement->FirstChildElement("path")) {
if ((textE = dictElement->FirstChildElement("path")->GetText()) != NULL)
dict.path = textE;
}
if ((pos = findDict(dict.path, dictFiles)) == -1 ) {
dictsElement->DeleteChild(dictElement);
dictElement = dictElement->NextSiblingElement();
continue;
}
dictFiles[pos] = "";
dict.en = dictElement->BoolAttribute("en");
if (dictElement->Attribute("open"))
dict.open = string(dictElement->Attribute("open"));
if (dictElement->FirstChildElement("srclan")) {
if ((textE = dictElement->FirstChildElement("srclan")->GetText()) != NULL)
dict.srclan = textE;
}
if (dictElement->FirstChildElement("detlan")) {
if ((textE = dictElement->FirstChildElement("detlan")->GetText()) != NULL)
dict.detlan = textE;
}
if (dictElement->FirstChildElement("name")) {
if ((textE = dictElement->FirstChildElement("name")->GetText()) != NULL)
dict.name = textE;
}
if (dictElement->FirstChildElement("summary")) {
if ((textE = dictElement->FirstChildElement("summary")->GetText()) != NULL)
dict.summary = textE;
}
m_dictNodes.push_back(dict);
dictElement = dictElement->NextSiblingElement();
}
vector<string>::iterator iter = dictFiles.begin();
for (; iter != dictFiles.end(); iter++) {
if (*iter != "") {
struct DictNode d;
d.en = true;
d.path = *iter;
d.name = boost::filesystem::path(d.path).filename().string();
//printf("%s\n",d.name.c_str());
m_dictNodes.push_back(d);
}
}
// Loading dictionary -- end
tempElement = rootElement->FirstChildElement(XML_TAG_CWS);
if (tempElement) {
m_cws.bselection = tempElement->BoolAttribute("selection");
m_cws.bclipboard = tempElement->BoolAttribute("clipboard");
m_cws.bmouse = tempElement->BoolAttribute("mouse");
m_cws.benable = tempElement->BoolAttribute("enable");
m_cws.shortcutKey = tempElement->IntAttribute("shortcutkey");
//.........这里部分代码省略.........
示例5: logger
std::unique_ptr<ensoft::tmx::Map> ensoft::tmx::TmxLoader::loadMap(std::string filename)
{
Logger logger("TMX Loader");
logger.log("Loading " + filename);
XMLDocument doc;
XMLError error = doc.LoadFile(filename.c_str());
std::unique_ptr<ensoft::tmx::Map> map;
if (error != XMLError::XML_NO_ERROR)
{
logger.error("Error code: " + std::to_string(error));
}
else
{
// start parsing the TMX map
XMLElement *xmap = doc.FirstChildElement("map");
map = std::make_unique<ensoft::tmx::Map>(loadProperties(xmap));
map->version = xmap->Attribute("version");
map->orientation = xmap->Attribute("orientation");
map->width = xmap->IntAttribute("width");
map->height = xmap->IntAttribute("height");
map->tilewidth = xmap->IntAttribute("tilewidth");
map->tileheight = xmap->IntAttribute("tileheight");
map->renderorder = xmap->Attribute("renderorder");
map->properties = loadProperties(xmap);
// load all the tilesets
XMLElement *xtileset = xmap->FirstChildElement("tileset");
while (xtileset)
{
auto tileSet = std::make_unique<ensoft::tmx::TileSet>(loadProperties(xtileset));
tileSet->firstgid = xtileset->IntAttribute("firstgid");
tileSet->source = getAttributeString(xtileset, "source");
tileSet->name = getAttributeString(xtileset, "name");
tileSet->tilewidth = xtileset->IntAttribute("tilewidth");
tileSet->tileheight = xtileset->IntAttribute("tileheight");
tileSet->spacing = xtileset->IntAttribute("spacing");
tileSet->margin = xtileset->IntAttribute("margin");
// get the tiles for this tileset
XMLElement *xtile = xtileset->FirstChildElement("tile");
while (xtile)
{
auto tile = make_unique<ensoft::tmx::Tile>(loadProperties(xtile));
tile->id = xtile->IntAttribute("id");
tile->terrain = getAttributeString(xtile, "terrain");
tile->probability = xtile->FloatAttribute("probability");
tile->image = loadImage(xtile);
// keep track of all tiles and their global IDs
int tileGid = tileSet->firstgid + tile->id;
map->allTiles[tileGid] = tile.get();
std::cout << "[TMX Loader] Added: " << tile->image.source << " GID: " << tileGid << " Tileset: " << tileSet->name << std::endl;
tileSet->tiles.push_back(std::move(tile));
xtile = xtile->NextSiblingElement("tile");
}
map->tilesets.push_back(std::move(tileSet));
// try to find another tileset
xtileset = xtileset->NextSiblingElement("tileset");
}
XMLElement *xlayer = xmap->FirstChildElement("layer");
while (xlayer)
{
auto layer = std::make_shared<ensoft::tmx::Layer>(loadProperties(xlayer));
layer->name = xlayer->Attribute("name");
layer->x = xlayer->IntAttribute("x");
layer->y = xlayer->IntAttribute("y");
layer->width = xlayer->IntAttribute("width");
layer->height = xlayer->IntAttribute("height");
layer->opacity = xlayer->FloatAttribute("opacity");
layer->visible = xlayer->BoolAttribute("visible");
// load the data element
XMLElement *xdata = xlayer->FirstChildElement("data");
if (xdata)
{
string data = trim_copy(xdata->GetText());
loadData(*layer, map.get(), data);
}
map->layers.push_back(layer);
xlayer = xlayer->NextSiblingElement("layer");
}
XMLElement *ximagelayer = xmap->FirstChildElement("imagelayer");
while (ximagelayer)
{
auto imageLayer = std::make_unique<ensoft::tmx::ImageLayer>(loadProperties(ximagelayer));
imageLayer->name = ximagelayer->Attribute("name");
imageLayer->x = ximagelayer->IntAttribute("x");
imageLayer->y = ximagelayer->IntAttribute("y");
imageLayer->width = ximagelayer->IntAttribute("width");
imageLayer->height = ximagelayer->IntAttribute("height");
imageLayer->opacity = ximagelayer->FloatAttribute("opacity");
imageLayer->visible = ximagelayer->BoolAttribute("visible");
//.........这里部分代码省略.........