本文整理汇总了C++中MeiDocument::setRootElement方法的典型用法代码示例。如果您正苦于以下问题:C++ MeiDocument::setRootElement方法的具体用法?C++ MeiDocument::setRootElement怎么用?C++ MeiDocument::setRootElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeiDocument
的用法示例。
在下文中一共展示了MeiDocument::setRootElement方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MeiDocument
TEST(TestMeiDocument, RootElement) {
MeiDocument *doc = new MeiDocument();
Mei *m = new Mei();
doc->setRootElement(m);
ASSERT_EQ(m, doc->getRootElement());
}
示例2: MeiElement
TEST(TestMeiElement, GetPositionInDocument) {
MeiElement* m = new MeiElement("mei");
MeiElement *m1 = new MeiElement("music");
string musicId = m1->getId();
MeiElement *b1 = new MeiElement("body");
MeiElement *s1 = new MeiElement("staff");
MeiElement *n1 = new MeiElement("note");
string nId = n1->getId();
MeiElement *n2 = new MeiElement("note");
MeiElement *n3 = new MeiElement("note");
MeiElement *n4 = new MeiElement("note");
string n4Id = n4->getId();
m->addChild(m1);
m1->addChild(b1);
b1->addChild(s1);
s1->addChild(n1);
s1->addChild(n2);
s1->addChild(n3);
MeiDocument* doc = new MeiDocument();
doc->setRootElement(m);
ASSERT_EQ(4, n1->getPositionInDocument());
ASSERT_EQ(-1, n4->getPositionInDocument());
}
示例3: Mei
TEST(TestMeiDocument, FlattenedDocTree) {
Mei *mei = new Mei();
Music *mus = new Music();
Body *body = new Body();
Staff *staff = new Staff();
Staff *s2 = new Staff();
Note *n1 = new Note();
Note *n2 = new Note();
Note *n3 = new Note();
MeiDocument *doc = new MeiDocument();
mei->addChild(mus);
// empty since mei not added as document root yet
ASSERT_TRUE(doc->getFlattenedTree().empty());
doc->setRootElement(mei);
ASSERT_EQ(2, doc->getFlattenedTree().size());
mus->addChild(body);
body->addChild(staff);
body->addChild(s2);
staff->addChild(n1);
staff->addChild(n2);
s2->addChild(n3);
doc->lookBack(n2, "mei");
ASSERT_EQ(8, doc->getFlattenedTree().size());
staff->removeChild(n2);
ASSERT_EQ(7, doc->getFlattenedTree().size());
ASSERT_EQ(s2, doc->getFlattenedTree()[5]);
staff->removeChildrenWithName("note");
ASSERT_EQ(6, doc->getFlattenedTree().size());
body->deleteAllChildren();
ASSERT_EQ(3, doc->getFlattenedTree().size());
std::vector<MeiElement*> newChildren;
Staff *newStaff1 = new Staff();
Staff *newStaff2 = new Staff();
newChildren.push_back(newStaff1);
newChildren.push_back(newStaff2);
body->setChildren(newChildren);
ASSERT_EQ(5, doc->getFlattenedTree().size());
// check contents
MeiElement* elements[] = { mei, mus, body, newStaff1, newStaff2 };
std::vector<MeiElement*> rightOrder (elements, elements + sizeof(elements) / sizeof(MeiElement));
for (int i = 0; i < rightOrder.size(); i++) {
// check don't overshoot memory allocation
ASSERT_LT(i, doc->getFlattenedTree().size());
ASSERT_EQ(rightOrder[i], doc->getFlattenedTree()[i]);
}
}
示例4: MeiDocument
TEST(TestMeiDocument, SetsDefaultNamespace) {
MeiDocument *doc = new MeiDocument();
MeiElement *root = new MeiElement("mei");
doc->setRootElement(root);
ASSERT_TRUE(root->hasAttribute("xmlns"));
ASSERT_EQ(root->getAttribute("xmlns")->getValue(), MEI_NS);
}
示例5: init
void XmlImportImpl::init() {
// get mei version from document
xmlAttrPtr meiversAttr = xmlHasProp(this->rootXmlNode, (const xmlChar*)"meiversion");
string meiVersion = string((const char*)meiversAttr->children->content);
MeiDocument *doc = new MeiDocument(meiVersion);
this->meiDocument = doc;
this->rootMeiElement = this->xmlNodeToMeiElement(this->rootXmlNode);
doc->setRootElement(this->rootMeiElement);
}
示例6: MeiDocument
TEST(TestMeiElement, TestRemoveManyChildren) {
MeiDocument *doc = new MeiDocument();
MeiElement *mei = new MeiElement("mei");
MeiElement *sd1 = new MeiElement("staffDef");
MeiElement *sd2 = new MeiElement("staffDef");
MeiElement *sd3 = new MeiElement("staffDef");
MeiElement *sd4 = new MeiElement("staffDef");
MeiElement *sd5 = new MeiElement("staffDef");
MeiElement *sd6 = new MeiElement("staffDef");
doc->setRootElement(mei);
MeiElement *music = new mei::MeiElement("music");
MeiElement *scoreDef = new mei::MeiElement("scoreDef");
mei->addChild(music);
music->addChild(scoreDef);
scoreDef->addChild(sd1);
scoreDef->addChild(sd2);
scoreDef->addChild(sd3);
scoreDef->addChild(sd4);
scoreDef->addChild(sd5);
scoreDef->addChild(sd6);
sd1->addAttribute("n", "1");
sd2->addAttribute("n", "2");
sd3->addAttribute("n", "3");
sd4->addAttribute("n", "4");
sd5->addAttribute("n", "5");
sd6->addAttribute("n", "6");
vector<MeiElement*> scoreDefs = doc->getRootElement()->getDescendantsByName("scoreDef");
vector<MeiElement*> staffDefs = doc->getRootElement()->getDescendantsByName("staffDef");
for (vector<MeiElement*>::iterator iter = staffDefs.begin(); iter != staffDefs.end(); ++iter) {
if ((*iter)->getAttribute("n")->getValue() == "3" || (*iter)->getAttribute("n")->getValue() == "6") {
(*iter)->getParent()->removeChild((*iter));
}
}
ASSERT_EQ(4, music->getDescendantsByName("staffDef").size());
}