本文整理汇总了C++中Iterator_t类的典型用法代码示例。如果您正苦于以下问题:C++ Iterator_t类的具体用法?C++ Iterator_t怎么用?C++ Iterator_t使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Iterator_t类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNameAndEmailAddress
// helper function for retrieving the name and email address from an item
static void
getNameAndEmailAddress(
Item& aEmailItem,
String& aName,
String& aMailbox,
String& aHost)
{
Iterator_t lChildren = aEmailItem.getChildren();
lChildren->open();
Item lChild;
// name might not exist -> empty string by default
aName = "";
while (lChildren->next(lChild)) {
if (lChild.getNodeKind() != store::StoreConsts::elementNode) {
continue;
}
String lNodeName;
getNodeName(lChild, lNodeName);
if (lNodeName == "name") {
aName = lChild.getStringValue();
} else {
String lEmail = lChild.getStringValue();
int lIndexOfAt = lEmail.find('@');
aMailbox = lEmail.substr(0, lIndexOfAt).c_str();
aHost = lEmail.substr(lIndexOfAt + 1, lEmail.length() - lIndexOfAt - 1).c_str();
}
}
}
示例2: while
void
CClientMimeHandler::begin(const Item& aMimeItem)
{
Iterator_t lChildIter;
//initialize ENVELOPE
theEnvelope = mail_newenvelope ();
//initialize BODY
theBody = mail_newbody ();
mail_initbody(theBody);
//set theMessageItem
lChildIter = aMimeItem.getChildren();
lChildIter->open();
// read envelope and body elements but skip non-element nodes
while (lChildIter->next(theEnvelopeItem)) {
if (theEnvelopeItem.getNodeKind() == store::StoreConsts::elementNode) {
break;
}
}
while (lChildIter->next(theBodyItem)) {
if (theBodyItem.getNodeKind() == store::StoreConsts::elementNode) {
break;
}
}
lChildIter->close();
}
示例3: while
void
GraphvizFunction::printGraph(
ItemFactory* aFactory,
const Item& in, std::fstream& os)
{
// create helper qnames for comparison
Item lNodeQName = aFactory->createQName("", "", "node");
Item lEdgeQName = aFactory->createQName("", "", "edge");
Item lRelQName = aFactory->createQName("", "", "rel");
// print the graph with all its children
Item lGraphId;
if (!getAttribute(aFactory, "id", in, lGraphId)) {
GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: edge does not have an 'id' attribute");
}
os << "digraph \"" << lGraphId.getStringValue() << "\" {" << std::endl;
// visit nodes and edges (TODO add rel elements)
Iterator_t lChildren = in.getChildren();
lChildren->open();
Item item;
while (lChildren->next(item)) {
Item lNodeName;
item.getNodeName(lNodeName);
if (lNodeName.getLocalName() == lNodeQName.getLocalName()) {
visitNode(aFactory, item, os);
} else if (lNodeName.getLocalName() == lEdgeQName.getLocalName()) {
visitEdge(aFactory, item, os);
}
}
os << "}" << std::endl;
} /* GraphvizFunction::printGraph */
示例4: xmldatamanager_example_5
bool
xmldatamanager_example_5(Zorba* aZorba, XmlDataManager* aDataManager)
{
try {
std::stringstream lStream;
lStream
<< "<book><title>XQuery From The Experts</title></book>"
<< "<book><title>XQuery Kick Start</title></book>"
<< "<book><title>Querying XML</title></book>";
XmlDataManager::ParseOptions lOptions;
lOptions.setExternalEntityProcessing(true);
ItemSequence_t lSeq = aDataManager->parseXML(lStream, lOptions);
Iterator_t lIter = lSeq->getIterator();
lIter->open();
Item lItem;
while (lIter->next(lItem)) {
std::cout << "element " << lItem.getStringValue() << std::endl;
}
} catch (ZorbaException& e) {
std::cerr << e << std::endl;
return false;
}
return true;
}
示例5: test_serialization_error
// test for bug #3085093 "ZorbaError not caught in SerializerImpl::serialize"
bool
test_serialization_error(Zorba* aZorba)
{
XQuery_t lQuery = aZorba->compileQuery("<a a='1'/>/@a");
Zorba_SerializerOptions_t lOptions;
Serializer_t lSerializer = Serializer::createSerializer(lOptions);
Iterator_t lIterator = lQuery->iterator();
try {
lIterator->open();
Item lItem;
while ( lIterator->next(lItem) ) {
// we have to wrap the item in a Serializable object
SingletonItemSequence lSequence(lItem);
lSerializer->serialize(&lSequence, std::cout);
}
lIterator->close();
} catch (ZorbaException& e) {
std::cerr << e << std::endl;
lIterator->close();
return true;
}
return false;
}
示例6: example_1
/**
* Test accessing a JSONArray's members
*/
bool
example_1(Zorba* aZorba)
{
Iterator_t lIterator;
XQuery_t lQuery = aZorba->compileQuery("[ 1, 2, 3 ]");
lIterator = lQuery->iterator();
lIterator->open();
Item lItem;
lIterator->next(lItem);
// Ensure we got a JSON array
if (!lItem.isJSONItem() ||
lItem.getJSONItemKind() != store::StoreConsts::jsonArray) {
std::cerr << "Item is not JSON Array!" << std::endl;
return false;
}
// Ensure array has 3 integer members
uint64_t lSize = lItem.getArraySize();
if (lSize != 3) {
std::cerr << lSize << " array members returned, expecting 3" << std::endl;
return false;
}
for(uint64_t i = 1; i <= lSize; ++i)
{
Item lMember = lItem.getArrayValue(i);
// This will throw an exception if the item isn't an integer
std::cout << lMember.getLongValue() << std::endl;
}
lIterator->close();
return true;
}
示例7: if
void
CClientMimeHandler::body()
{
theBody->type = TYPEOTHER;
Iterator_t lChildIter;
Item lChild;
String lNodeName;
lChildIter = theBodyItem.getChildren();
lChildIter->open();
while (lChildIter->next(lChild)) {
if (lChild.getNodeKind() != store::StoreConsts::elementNode) {
continue;
}
getNodeName(lChild, lNodeName);
if (lNodeName == "content") {
parse_content(theBody, lChild);
}
else if (lNodeName == "multipart") {
parse_multipart(theBody, lChild);
}
}
lChildIter->close();
}
示例8: cxx_api_changes_test4
bool
cxx_api_changes_test4(Zorba* aZorba)
{
try
{
std::ifstream lIn("cxx_api_ch4.xq");
assert(lIn.good());
StaticContext_t lStaticContext = aZorba->createStaticContext();
std::vector<String> lModulePaths;
lModulePaths.push_back(zorba::CMAKE_BINARY_DIR+"/TEST_URI_PATH/");
lStaticContext->setModulePaths(lModulePaths);
XQuery_t lQuery = aZorba->compileQuery(lIn, lStaticContext);
std::vector<Item> lVars;
Iterator_t varsIte;
lQuery->getExternalVariables(varsIte);
varsIte->open();
Item temp;
while(varsIte->next(temp))
lVars.push_back(temp);
varsIte->close();
if (lVars.size() != 3)
return false;
std::ostringstream lOut;
std::vector<Item>::const_iterator lIte = lVars.begin();
std::vector<Item>::const_iterator lEnd = lVars.end();
for (; lIte != lEnd; ++lIte)
{
lOut << lIte->getStringValue() << " ";
}
std::string out = lOut.str();
if (out != "testGetExtVarA:ext a testGetExtVarB:ext " &&
out != "testGetExtVarB:ext a testGetExtVarA:ext " &&
out != "a testGetExtVarA:ext testGetExtVarB:ext " &&
out != "a testGetExtVarB:ext testGetExtVarA:ext " &&
out != "testGetExtVarA:ext testGetExtVarB:ext a " &&
out != "testGetExtVarB:ext testGetExtVarA:ext a ")
return false;
}
catch (XQueryException& qe)
{
std::cerr << qe << std::endl;
return false;
}
catch (ZorbaException& e)
{
std::cerr << e << std::endl;
return false;
}
return true;
}
示例9: cxx_api_changes_test5
bool
cxx_api_changes_test5(Zorba* aZorba)
{
try
{
std::string lIn = "declare variable $a external; 1+1";
XQuery_t lQuery = aZorba->compileQuery(lIn);
std::vector<Item> lVars;
Iterator_t varsIte;
lQuery->getExternalVariables(varsIte);
varsIte->open();
Item temp;
while(varsIte->next(temp))
lVars.push_back(temp);
varsIte->close();
std::vector<Item>::const_iterator lIte = lVars.begin();
std::vector<Item>::const_iterator lEnd = lVars.end();
Item item = aZorba->getItemFactory()->createInt(4);
bool isBound1;
bool isBound2;
for(; lIte != lEnd; ++lIte)
{
Item qname = *lIte;
isBound1 = lQuery->getDynamicContext()->isBoundExternalVariable(qname.getNamespace(), qname.getLocalName());
Item value = aZorba->getItemFactory()->createString("foo");
lQuery->getDynamicContext()->setVariable(qname.getStringValue(), value);
isBound2 = lQuery->getDynamicContext()->isBoundExternalVariable(qname.getNamespace(), qname.getLocalName());
}
if (!isBound1 && isBound2)
return true;
}
catch (XQueryException& qe)
{
std::cerr << qe << std::endl;
return false;
}
catch (ZorbaException& e)
{
std::cerr << e << std::endl;
return false;
}
return true;
}
示例10:
Item
JdbcModule::getItemArg(const ExternalFunction::Arguments_t& args, int index) {
Item item;
if (index < (int)args.size()) {
Iterator_t lIter = args[index]->getIterator();
lIter->open();
lIter->next(item);
lIter->close();
}
return item;
}
示例11: catch
void
SerializerImpl::serialize(Iterator_t aIterator, std::ostream& aOs) const
{
try {
aIterator->open();
theInternalSerializer.serialize(Unmarshaller::getInternalIterator(aIterator), aOs);
aIterator->close();
} catch (ZorbaException const &e) {
ZorbaImpl::notifyError(theDiagnosticHandler, e);
}
}
示例12: cxx_api_changes_test3
bool
cxx_api_changes_test3(Zorba* aZorba)
{
try
{
//tests the use of getExternalVariables
std::ifstream lIn("cxx_api_ch3.xq");
assert(lIn.good());
XQuery_t lQuery = aZorba->compileQuery(lIn);
std::vector<Item> lVars;
Iterator_t varsIte;
lQuery->getExternalVariables(varsIte);
varsIte->open();
Item temp;
while(varsIte->next(temp))
lVars.push_back(temp);
varsIte->close();
if (lVars.size() != 2)
{
std::cout << "Expected 2 variables but got " << lVars.size() << std::endl;
return false;
}
std::vector<Item>::iterator lIte = lVars.begin();
std::vector<Item>::iterator lEnd = lVars.end();
for (; lIte != lEnd; ++lIte)
{
String name = lIte->getStringValue();
if (name != "a" && name != "b")
return false;
}
}
catch (XQueryException& qe)
{
std::cerr << qe << std::endl;
return false;
}
catch (ZorbaException& e)
{
std::cerr << e << std::endl;
return false;
}
return true;
}
示例13: allowed
void
GraphvizFunction::gxl2dot(
ItemFactory* aFactory,
const Item& in, std::fstream& os)
{
Item lGXLQName = aFactory->createQName("", "", "gxl");
Item lGraphQName = aFactory->createQName("", "", "graph");
if (!in.isNode()) {
GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: item is not a node");
}
Item lNodeName;
in.getNodeName(lNodeName);
if (lNodeName.getLocalName() != lGXLQName.getLocalName()) {
Item lNodeName;
in.getNodeName(lNodeName);
std::ostringstream lErrorMsg;
lErrorMsg << "GXL parse error: only element with name "
<< lGXLQName.getStringValue() << " allowed (got " << lNodeName.getStringValue()
<< ").";
GraphvizFunction::throwErrorWithQName(aFactory, "IM003", lErrorMsg.str());
}
Iterator_t lGraphs = in.getChildren();
lGraphs->open();
Item lGraph;
while(lGraphs->next(lGraph)) {
if (!lGraph.isNode()) {
GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: item is not a node");
}
lGraph.getNodeName(lNodeName);
if (lNodeName.getLocalName() != lGraphQName.getLocalName()) {
std::ostringstream lErrorMsg;
Item lNodeName;
lGraph.getNodeName(lNodeName);
lErrorMsg << "GXL parse error: only elements with name "
<< lGraphQName.getStringValue() << " allowed (got "
<< lNodeName.getLocalName() << ").";
GraphvizFunction::throwErrorWithQName(aFactory, "IM003", lErrorMsg.str());
}
printGraph(aFactory, lGraph, os);
}
} /* GraphvizFunction::gxl2dot */
示例14: evaluate
virtual ItemSequence_t
evaluate(const ExternalFunction::Arguments_t& args) const
{
iv_t vec;
for(int i = 0; i < 2; ++i) {
Item lItem;
Iterator_t iter = args[i]->getIterator();
iter->open();
while(iter->next(lItem)) {
vec.push_back(lItem);
}
iter->close();
}
// transfer ownership of the IteratorBackedItemSequence to Zorba (using a unique_ptr)
return ItemSequence_t(new IteratorBackedItemSequence(vec));
}
示例15: evaluate
ItemSequence_t evaluate(const ExternalFunction::Arguments_t& args) const
{
Item item;
int64_t sum1 = 0;
int64_t sum2 = 0;
Iterator_t iter = args[0]->getIterator();
iter->open();
while (iter->next(item))
sum1 += item.getLongValue();
iter->close();
//iter = args[0]->getIterator();
iter->open();
while (iter->next(item))
sum2 += item.getLongValue();
iter->close();
if (sum1 != sum2)
{
std::cerr << "sum1 = " << sum1 << " sum2 = " << sum2 << std::endl;
throw std::exception();
}
return ItemSequence_t(new EmptySequence());
}