本文整理汇总了C++中XMLNode::GetName方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLNode::GetName方法的具体用法?C++ XMLNode::GetName怎么用?C++ XMLNode::GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLNode
的用法示例。
在下文中一共展示了XMLNode::GetName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitFromXMLNode
void Gauge::InitFromXMLNode(XMLNode gaugeNode)
{
Check(gaugeNode.IsValid() && gaugeNode.GetName() == "Gauge");
double scale = globals->m_PrefManager->GetPrefD("DefaultGaugeScale");
double zoom = globals->m_PrefManager->GetPrefD("Zoom");
double x, y; // temp variables
// Set the units per pixel
if (gaugeNode.HasChild("UnitsPerPixel"))
{
SetUnitsPerPixel(gaugeNode.GetChild("UnitsPerPixel").GetTextAsDouble());
}
else
{
SetUnitsPerPixel(globals->m_PrefManager->GetPrefD("UnitsPerPixel"));
}
// Set the position
if (gaugeNode.HasChild("Position"))
{
gaugeNode.GetChild("Position").GetTextAsCoord(x, y);
SetPosition(x * zoom, y * zoom);
}
else
{
SetPosition(0.0, 0.0);
}
// Set the scale
if (gaugeNode.HasChild("Scale")) {
gaugeNode.GetChild("Scale").GetTextAsCoord(x, y);
SetScale(x * zoom * scale, y * zoom * scale);
}
else
{
SetScale(zoom * scale, zoom * scale);
}
// Set the gauge outline
if (gaugeNode.HasChild("Outline"))
{
SetGaugeOutline(gaugeNode.GetChild("Outline").GetTextAsBool());
}
CustomXMLInit(gaugeNode);
}
示例2: LoadFromFile
FontRenderer* FontRenderer::LoadFromFile(const char *path, SpriteBatch *spriteBatch)
{
assert(spriteBatch != NULL);
FontLetter texLetters[256];
XMLNode *xmlDoc = XMLLoader::LoadFromFile(path);
if (xmlDoc == NULL)
return NULL;
std::string bmpFilename = xmlDoc->GetAttribAsString("bitmap");
if (bmpFilename.empty())
return NULL;
Path _path(path);
Texture *tex = LoadFontBitmap(_path.GetPath() + bmpFilename);
if (tex == NULL)
return NULL;
if (xmlDoc->GetName() != "alphabet")
{
delete xmlDoc;
return NULL;
}
for (uint32_t i = 0; i < xmlDoc->GetChildrenCount(); i++)
{
std::string letter = xmlDoc[i].GetAttribAsString("letter");
std::string bounds = xmlDoc[i].GetAttribAsString("bounds");
sm::Rect<int> boundsValues;
if (!ParseBounds(bounds, boundsValues))
return NULL;
texLetters[letter[0]].Size = sm::Point<int>(boundsValues.Width, boundsValues.Height);
texLetters[letter[0]].Coords = TexPart(tex, boundsValues);
}
FontRenderer *fontRenderer = new FontRenderer();
fontRenderer->m_spriteBatch = spriteBatch;
if (fontRenderer != NULL)
{
memcpy(fontRenderer ->texLetters, texLetters, sizeof(FontLetter) * 256);
}
return fontRenderer;
}
示例3: if
bool
ApplePropertyList::ExtractStringFromValueNode (const XMLNode &node, std::string &value)
{
value.clear();
#if defined( LIBXML2_DEFINED )
if (node.IsValid())
{
llvm::StringRef element_name = node.GetName();
if (element_name == "true" || element_name == "false")
{
// The text value _is_ the element name itself...
value = element_name.str();
return true;
}
else if (element_name == "dict" || element_name == "array")
return false; // dictionaries and arrays have no text value, so we fail
else
return node.GetElementText(value);
}
#endif
return false;
}
示例4: assert
/**
* Recursively parse an XML element.
*/
static bool
XML::ParseXMLElement(XMLNode &node, Parser *pXML)
{
bool is_declaration;
const TCHAR *text = nullptr;
XMLNode *pNew;
enum Status status; // inside or outside a tag
enum Attrib attrib = eAttribName;
/* the name of the attribute that is currently being */
tstring attribute_name;
assert(pXML);
// If this is the first call to the function
if (pXML->nFirst) {
// Assume we are outside of a tag definition
pXML->nFirst = false;
status = eOutsideTag;
} else {
// If this is not the first call then we should only be called when inside a tag.
status = eInsideTag;
}
// Iterate through the tokens in the document
while (true) {
// Obtain the next token
NextToken token = GetNextToken(pXML);
if (gcc_unlikely(token.type == eTokenError))
return false;
// Check the current status
switch (status) {
// If we are outside of a tag definition
case eOutsideTag:
// Check what type of token we obtained
switch (token.type) {
// If we have found text or quoted text
case eTokenText:
case eTokenQuotedText:
case eTokenEquals:
if (text == nullptr)
text = token.pStr;
break;
// If we found a start tag '<' and declarations '<?'
case eTokenTagStart:
case eTokenDeclaration:
// Cache whether this new element is a declaration or not
is_declaration = token.type == eTokenDeclaration;
// If we have node text then add this to the element
if (text != nullptr) {
size_t length = StripRight(text, token.pStr - text);
node.AddText(text, length);
text = nullptr;
}
// Find the name of the tag
token = GetNextToken(pXML);
// Return an error if we couldn't obtain the next token or
// it wasnt text
if (token.type != eTokenText) {
pXML->error = eXMLErrorMissingTagName;
return false;
}
// If the name of the new element differs from the name of
// the current element we need to add the new element to
// the current one and recurse
pNew = &node.AddChild(token.pStr, token.length,
is_declaration);
while (true) {
// Callself to process the new node. If we return
// FALSE this means we dont have any more
// processing to do...
if (!ParseXMLElement(*pNew, pXML)) {
return false;
} else {
// If the call to recurse this function
// evented in a end tag specified in XML then
// we need to unwind the calls to this
// function until we find the appropriate node
// (the element name and end tag name must
// match)
if (pXML->cbEndTag) {
// If we are back at the root node then we
// have an unmatched end tag
if (node.GetName() == nullptr) {
pXML->error = eXMLErrorUnmatchedEndTag;
return false;
}
//.........这里部分代码省略.........
示例5: InitFromXMLNode
void GaugePanel::InitFromXMLNode(XMLNode gaugeNode)
{
Check(gaugeNode.IsValid() && gaugeNode.GetName() == "Panel");
// Create gauges as described by the XML file
XMLNode::NodeList nodeList = gaugeNode.GetChildList("Gauge");
XMLNode::NodeList::iterator iter;
for (iter = nodeList.begin(); iter != nodeList.end(); ++iter)
{
Gauge *pGauge = GaugeFactory::CreateGaugeInstance(*iter);
if (pGauge != NULL) {
pGauge->SetParentRenderObject(this);
AddGauge(pGauge);
}
}
double scale = globals->m_PrefManager->GetPrefD("DefaultPanelScale");
double zoom = globals->m_PrefManager->GetPrefD("Zoom");
double x, y; // temp variables
// Set the units per pixel
if (gaugeNode.HasChild("UnitsPerPixel"))
{
SetUnitsPerPixel(gaugeNode.GetChild("UnitsPerPixel").GetTextAsDouble());
}
else
{
SetUnitsPerPixel(globals->m_PrefManager->GetPrefD("UnitsPerPixel"));
}
// Set the scale
if (gaugeNode.HasChild("Scale"))
{
gaugeNode.GetChild("Scale").GetTextAsCoord(x, y);
SetScale(x * zoom * scale, y * zoom * scale);
}
else
{
SetScale(zoom * scale, zoom * scale);
}
// Set the position
if (gaugeNode.HasChild("Position"))
{
gaugeNode.GetChild("Position").GetTextAsCoord(x, y);
SetPosition(x * zoom, y * zoom);
}
else
{
SetPosition(0.0, 0.0);
}
// Set the size
if (gaugeNode.HasChild("Size"))
{
gaugeNode.GetChild("Size").GetTextAsCoord(x, y);
SetSize(x, y);
}
else
{
SetSize(0.0, 0.0);
}
// Set the gauge outline
if (gaugeNode.HasChild("Outline"))
{
SetPanelOutline(gaugeNode.GetChild("Outline").GetTextAsBool());
}
}
示例6: Initlize
//----------------------------------------------------------------------------
bool FontBitmapImpl::Initlize (int fontWidth, int fontHeight,
const char *fontFilename, CharCodingType codingType, unsigned int fontExtStyle)
{
Font::Initlize(fontWidth, fontHeight, fontFilename, codingType, fontExtStyle);
mFontFilename = fontFilename;
if (CCT_UTF8 == codingType)
{
mCharCodingObj = new0 CharCodingUTF8();
}
else if (CCT_GBK == codingType)
{
mCharCodingObj = new0 CharCodingGBK();
}
mGlyphMap = this;
std::string outPath;
std::string outBaseFilename;
StringHelp::SplitFilename(fontFilename, outPath, outBaseFilename);
int bufferSize = 0;
char *buffer = 0;
if (PX2_RM.LoadBuffer(fontFilename, bufferSize, buffer))
{
XMLData data;
if (data.LoadBuffer(buffer, bufferSize))
{
float imageWidth = 0.0f;
float imageHeight = 0.0f;
XMLNode rootNode = data.GetRootNode();
XMLNode child = rootNode.IterateChild();
while (!child.IsNull())
{
const std::string &nodeName = child.GetName();
if ("image" == nodeName)
{
const char *text = child.GetText();
std::string imagePath = outPath + text;
mFontTex = DynamicCast<Texture2D>(PX2_RM.BlockLoad(imagePath));
if (mFontTex)
{
imageWidth = (float)mFontTex->GetWidth();
imageHeight = (float)mFontTex->GetHeight();
}
}
else if ("symbol" == nodeName)
{
std::string ch = child.GetChild("char").GetText();
int x = StringHelp::StringToInt(child.GetChild("x").GetText());
int y = StringHelp::StringToInt(child.GetChild("y").GetText());
int width = StringHelp::StringToInt(child.GetChild("width").GetText());
int height = StringHelp::StringToInt(child.GetChild("height").GetText());
unsigned int unicode = mCharCodingObj->ToUnicode((const unsigned char*)ch.c_str());
BitmapFontGlyph glyph;
glyph.X = x;
glyph.Y = y;
glyph.numWidth = width;
glyph.numHeight = height;
float u0 = (float)x/imageWidth;
float v0 = 1.0f-(float)(y+height)/imageHeight;
float u1 = (x+width)/imageWidth;
float v1 = v0 + (float)height/imageHeight;
glyph.RectUV = Rectf(u0, v0, u1, v1);
mMapGlyph[unicode] = glyph;
}
child = rootNode.IterateChild(child);
}
}
}
return true;
}
示例7: _Parse
XMLNode* XMLParser::_Parse(wchar_t* buf)
{
std::wstring token;
eCurState state = NONE;
attrMap attributeMap;
std::wstring attrKey;
XMLNode* curNode = new XMLNode;
while( _mParsingIndex < _mBufSize )
{
switch( buf[_mParsingIndex] )
{
case L'<':
if( state == ELEMENT ) // After element, It could be either closing node or new child node
{
if( _IsTokenTab(token) ) // At first, delete the all gap (similar to trim function)
{
token.clear();
}
if( buf[_mParsingIndex+1] == L'/' ) // In case of closing the node
{
curNode->SetElement( token );
token.clear();
state = CLOSING_NODE;
++_mParsingIndex;
}
else // In case of new child node
{
curNode->AddChild( _Parse(buf) );
}
}
else // In case of new node
{
++_mParsingIndex;
if( buf[_mParsingIndex] == L'?' || buf[_mParsingIndex] == L'!') // if new node is about xml information
{
_GetTokenWith(buf, L'>');
}
else // Read the new node's name
{
token += buf[_mParsingIndex];
state = OPENING_NODE;
}
}
break;
case L'>':
switch( state )
{
case ATTR_VALUE: // In case that new node's attr setting is all set
curNode->SetAttrMap(attributeMap);
attributeMap.clear();
state = ELEMENT;
break;
case CLOSING_NODE: // In case that making node is all set
if( curNode->GetName().compare(token) != 0 )
{
delete curNode;
wprintf(L"XML ERROR ( closing element's name isn't correct [%s] ) - line %d", curNode->GetName().c_str(), _mLine );
return nullptr;
}
return curNode;
case OPENING_NODE: // In case that new node's name setting is all set
curNode->SetName( token );
token.clear();
state = ELEMENT;
break;
default:
std::wcerr<<L"SWITCH_DEFAULT : "<<__FILE__<<L" "<<__LINE__<<std::endl;
return nullptr;
}
break;
case L' ':
switch( state )
{
case OPENING_NODE: // After setting the name of new node
curNode->SetName( token );
token.clear();
state = ATTR_VALUE;
break;
case ELEMENT : // if ' ' is used for element, then just use that
token += L' ';
break;
//.........这里部分代码省略.........