本文整理汇总了C++中NodePtr::createEmptyChild方法的典型用法代码示例。如果您正苦于以下问题:C++ NodePtr::createEmptyChild方法的具体用法?C++ NodePtr::createEmptyChild怎么用?C++ NodePtr::createEmptyChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodePtr
的用法示例。
在下文中一共展示了NodePtr::createEmptyChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
bool VariantStreamHandler::write(const Variant& v, const NodePtr& node, bool writeType)
{
// Variant only accepts binary/text streams for streamin/out, so we get to do this fun little stream dance.
ResizingMemoryStream s;
TextStream ts(s);
ts << v;
// Get the type to be used - leave it null if we shouldn't write the type, setValueRawData won't write a type
const char* nodeTypeName = nullptr;
size_t nodeTypeSize = 0;
if (writeType)
{
nodeTypeName = variantName_;
nodeTypeSize = strlen(nodeTypeName);
}
// ResizingMemoryStream is not guaranteed to be null terminated.
node->setValueRawData(s.buffer().c_str(), s.buffer().size(), nodeTypeName, nodeTypeSize);
node->setHandlerName(handlerName_);
auto variantTypeName = this->getReservedNames().variantInternalType;
auto typeNode = node->createEmptyChild(variantTypeName, strlen(variantTypeName));
const char* internalTypeName = v.type()->typeId().getName();
typeNode->setValueString(internalTypeName, strlen(internalTypeName));
return true;
}
示例2: write
bool CollectionHandler::write(const Variant& v, const NodePtr& node, bool writeType)
{
node->setHandlerName(handlerName_);
if (writeType)
{
node->setType(collectionName_, strlen(collectionName_));
}
bool success = false;
Collection c;
if (!v.tryCast<Collection>(c))
{
return false;
}
if (c.empty())
{
return true;
}
// Check that the key isn't a collection, since we can't serialize those.
if (c.begin().key().canCast<Collection>())
{
return false;
}
// Find and hold on to our handlers
std::shared_ptr<SerializationHandler> keyHandler = nullptr;
std::shared_ptr<SerializationHandler> valueHandler = nullptr;
const MetaType* keyMetaType = MetaType::find(c.keyType().getName());
const MetaType* valueMetaType = MetaType::find(c.valueType().getName());
// If a type in the collection is Variant, then the handler can vary, so leave it as nullptr.
if (keyMetaType != MetaType::get<Variant>())
{
keyHandler = handlerManager_.findHandlerWrite(c.begin().key());
}
if (valueMetaType != MetaType::get<Variant>())
{
valueHandler = handlerManager_.findHandlerWrite(c.begin().value());
}
// Create a base node for all the elements in the collection.
auto baseNode = node->createEmptyChild(collectionBaseNodeName_, strlen(collectionBaseNodeName_));
// Iterate through all the objects in the collection
for (auto iter = c.begin(); iter != c.end(); ++iter)
{
// Write the key, if it exists
Variant key = iter.key();
if (!key.isVoid())
{
// Create the key node
std::unique_ptr<SerializationNode> keyNode;
if (keyHandler.get() == nullptr)
{
// Variant type, go through the entire system
keyNode = baseNode->createChildVariant(keyName_, strlen(keyName_), key);
}
else
{
// Non-Variant type, use our handler
keyNode = baseNode->createEmptyChild(keyName_, strlen(keyName_));
if (!keyHandler->write(key, keyNode, false))
{
return false;
}
}
if (keyNode == nullptr)
{
return false;
}
// Write the value
Variant value = iter.value();
if (!value.isVoid())
{
// Create the value node
std::unique_ptr<SerializationNode> valueNode;
if (valueHandler.get() == nullptr)
{
// Variant type, go through the entire system
valueNode = keyNode->createChildVariant(valueName_, strlen(valueName_), value);
}
else
{
// Non-Variant type, use our handler
valueNode = keyNode->createEmptyChild(valueName_, strlen(valueName_));
if (!valueHandler->write(value, valueNode, false))
{
return false;
}
}
if (valueNode == nullptr)
{
return false;
}
}
else
{
//.........这里部分代码省略.........