Skip to content

Commit ac294f3

Browse files
author
Huang-Ming Huang
committed
Fix Issue #63
1 parent 3d14612 commit ac294f3

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

src/mfast/xml_parser/field_builder.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ class template_not_found_error : public fast_dynamic_error {
2828
}
2929
};
3030

31+
#ifndef NDEBUG
32+
33+
void print_node(const XMLElement *element, int indent)
34+
{
35+
for (int i = 0; i < indent; ++i)
36+
std::cout << " ";
37+
std::cout << "node " << element->Name() ;
38+
const XMLAttribute *attr = element->FirstAttribute();
39+
while (attr) {
40+
std::cout << " " << attr->Name() << "=" << attr->Value();
41+
attr = attr->Next();
42+
}
43+
std::cout << "\n";
44+
45+
const XMLElement *elem = element->FirstChildElement();
46+
while (elem){
47+
print_node(elem, indent+4);
48+
elem = elem->NextSiblingElement();
49+
}
50+
}
51+
52+
#endif
53+
3154
const char *field_builder::name() const { return name_; }
3255

3356
std::size_t field_builder::num_instructions() const {
@@ -525,7 +548,11 @@ struct tag_value;
525548
typedef boost::error_info<tag_value, std::string> value_info;
526549

527550
void field_builder::visit(const enum_field_instruction *inst, void *) {
528-
field_op fop(inst, content_element_, alloc());
551+
552+
const XMLElement *element = &this->element_;
553+
if (!field_op::find_field_op_element(*element))
554+
element = content_element_;
555+
field_op fop(inst, element, alloc());
529556

530557
const char **enum_element_names = inst->elements();
531558
uint64_t num_elements = inst->num_elements();

src/mfast/xml_parser/field_op.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void field_op::set_init_value(const char *init_value_str,
105105
}
106106

107107
const XMLElement *
108-
field_op::find_field_op_element(const XMLElement &element) const {
108+
field_op::find_field_op_element(const XMLElement &element) {
109109
static const char *field_op_names[] = {"constant", "default", "copy",
110110
"increment", "delta", "tail"};
111111

src/mfast/xml_parser/field_op.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class field_op {
6161

6262
arena_allocator &alloc() { return *alloc_; }
6363

64+
static const XMLElement *find_field_op_element(const XMLElement &element);
65+
6466
private:
6567
void set_init_value(const char *init_value_str,
6668
const int32_field_instruction *) {
@@ -118,7 +120,6 @@ class field_op {
118120
void set_init_value(const char *init_value_str,
119121
const byte_vector_field_instruction *);
120122

121-
const XMLElement *find_field_op_element(const XMLElement &element) const;
122123

123124
void parse_field_op(const XMLElement &field_op_element,
124125
arena_allocator &alloc);

tests/composite_type_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ TEST_CASE("test the operations of complex group_mref", "[test_complex_group]")
166166
person_mref.set_firstName().as("John");
167167
person_mref.set_lastName().as("Doe");
168168

169+
// testing enum field operator
170+
REQUIRE(person_mref.get_discrete().instruction()->field_operator() == mfast::operator_copy);
171+
169172
// testing the default value
170173
REQUIRE(person_mref.get_gender().is_female());
171174

tests/test4.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
<element name="One" value="1"/>
5151
<element name="Three" value="3"/>
5252
<element name="Five" value="5"/>
53-
<copy/>
5453
</enum>
5554
</define>
5655
<define name="Salary">
@@ -105,6 +104,7 @@
105104
<boolean name="married"/>
106105
<field name="discrete">
107106
<type name="DiscreteEnum"/>
107+
<copy/>
108108
</field>
109109
<field name="salary">
110110
<type name="Salary"/>

0 commit comments

Comments
 (0)