From 6766f35338fafca445faf3c8a271ef558d6ec963 Mon Sep 17 00:00:00 2001 From: halex2005 Date: Tue, 14 Apr 2015 00:56:23 +0500 Subject: add align each attribute on new line support with format_indent_attribute --- src/pugixml.hpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/pugixml.hpp') diff --git a/src/pugixml.hpp b/src/pugixml.hpp index d59f864..36ed955 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -203,9 +203,12 @@ namespace pugi // Open file using text mode in xml_document::save_file. This enables special character (i.e. new-line) conversions on some systems. This flag is off by default. const unsigned int format_save_file_text = 0x20; + // Set each attribute to new line + const unsigned int format_each_attribute_on_new_line = 0x40; // The default set of formatting flags. // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none. const unsigned int format_default = format_indent; + const unsigned int format_indent_attributes = format_indent | format_each_attribute_on_new_line; // Forward declarations struct xml_attribute_struct; -- cgit v1.2.3 From 2a3435274f0d7d0e3ccb4417e143e5957e820332 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 13 Apr 2015 21:21:26 -0700 Subject: Refactor format_indent_attributes implementation Fix code style and revert redundant parameters/whitespace changes. Also remove format_each_attribute_on_new_line - we're only introducing one extra formatting flag. The flag implies format_indent but does not include its bitmask. Also add a few more tests. Fixes #14. --- src/pugixml.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/pugixml.hpp') diff --git a/src/pugixml.hpp b/src/pugixml.hpp index 36ed955..02ca86b 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -203,13 +203,13 @@ namespace pugi // Open file using text mode in xml_document::save_file. This enables special character (i.e. new-line) conversions on some systems. This flag is off by default. const unsigned int format_save_file_text = 0x20; - // Set each attribute to new line - const unsigned int format_each_attribute_on_new_line = 0x40; + // Write every attribute on a new line with appropriate indentation. This flag is off by default. + const unsigned int format_indent_attributes = 0x40; + // The default set of formatting flags. // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none. const unsigned int format_default = format_indent; - const unsigned int format_indent_attributes = format_indent | format_each_attribute_on_new_line; - + // Forward declarations struct xml_attribute_struct; struct xml_node_struct; -- cgit v1.2.3 From 5158ee903be463c189a80715f92235ceb04871a7 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 14 Apr 2015 19:19:13 -0700 Subject: Fix xpath_node_set assignment to provide strong exception guarantee Since the type of the set was updated before assignment, assigning in out-of-memory condition could change the type to not match the content. --- src/pugixml.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pugixml.hpp') diff --git a/src/pugixml.hpp b/src/pugixml.hpp index 02ca86b..b56f66a 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -1286,7 +1286,7 @@ namespace pugi xpath_node* _begin; xpath_node* _end; - void _assign(const_iterator begin, const_iterator end); + void _assign(const_iterator begin, const_iterator end, type_t type); }; #endif -- cgit v1.2.3 From 8c8940430ac0d0f82add6fb028ffe9712c9669e8 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 15 Apr 2015 08:32:22 -0700 Subject: Minor xpath_variable refactoring The type of the variable is now initialized correctly in the ctor, so that there is no interim invalid state. --- src/pugixml.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pugixml.hpp') diff --git a/src/pugixml.hpp b/src/pugixml.hpp index b56f66a..a7154f1 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -1043,7 +1043,7 @@ namespace pugi xpath_value_type _type; xpath_variable* _next; - xpath_variable(); + xpath_variable(xpath_value_type type); // Non-copyable semantics xpath_variable(const xpath_variable&); -- cgit v1.2.3 From cbf3807ad4e93441d4a4324d1c21099ca644fac7 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 15 Apr 2015 23:22:31 -0700 Subject: Implement copy ctor/assignment for xpath_variable_set xpath_variable_set is essentially an associative container; it's about time it became copyable. Implementation is slightly tricky due to out of memory handling. Both copy ctor and assignment operator have strong exception guarantee (even if exceptions are disabled! which translates to "roll back on allocation errors"). --- src/pugixml.hpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/pugixml.hpp') diff --git a/src/pugixml.hpp b/src/pugixml.hpp index a7154f1..b8b8946 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -1075,17 +1075,22 @@ namespace pugi private: xpath_variable* _data[64]; - // Non-copyable semantics - xpath_variable_set(const xpath_variable_set&); - xpath_variable_set& operator=(const xpath_variable_set&); + void _assign(const xpath_variable_set& rhs); + void _swap(xpath_variable_set& rhs); + + xpath_variable* _find(const char_t* name) const; - xpath_variable* find(const char_t* name) const; + static bool _clone(xpath_variable* var, xpath_variable** out_result); public: // Default constructor/destructor xpath_variable_set(); ~xpath_variable_set(); + // Copy constructor/assignment operator + xpath_variable_set(const xpath_variable_set& rhs); + xpath_variable_set& operator=(const xpath_variable_set& rhs); + // Add a new variable or get the existing one, if the types match xpath_variable* add(const char_t* name, xpath_value_type type); -- cgit v1.2.3 From 83b894b8f17e8c09eb21675983be0656301d2d99 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 21 Apr 2015 19:42:31 -0700 Subject: XPath: Implement move semantics support xpath_query, xpath_node_set and xpath_variable_set are now moveable. This is a nice performance optimization for variable/node sets, and enables storing xpath_query in containers without using pointers (it's only possible now since the query is not copyable). --- src/pugixml.hpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/pugixml.hpp') diff --git a/src/pugixml.hpp b/src/pugixml.hpp index b8b8946..0f79fb7 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -65,7 +65,7 @@ // If the platform is known to have long long support, enable long long functions #ifndef PUGIXML_HAS_LONG_LONG -# if defined(__cplusplus) && __cplusplus >= 201103 +# if __cplusplus >= 201103 # define PUGIXML_HAS_LONG_LONG # elif defined(_MSC_VER) && _MSC_VER >= 1400 # define PUGIXML_HAS_LONG_LONG @@ -1081,6 +1081,7 @@ namespace pugi xpath_variable* _find(const char_t* name) const; static bool _clone(xpath_variable* var, xpath_variable** out_result); + static void _destroy(xpath_variable* var); public: // Default constructor/destructor @@ -1091,6 +1092,12 @@ namespace pugi xpath_variable_set(const xpath_variable_set& rhs); xpath_variable_set& operator=(const xpath_variable_set& rhs); + #if __cplusplus >= 201103 + // Move semantics support + xpath_variable_set(xpath_variable_set&& rhs); + xpath_variable_set& operator=(xpath_variable_set&& rhs); + #endif + // Add a new variable or get the existing one, if the types match xpath_variable* add(const char_t* name, xpath_value_type type); @@ -1123,9 +1130,18 @@ namespace pugi // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on compilation errors. explicit xpath_query(const char_t* query, xpath_variable_set* variables = 0); + // Constructor + xpath_query(); + // Destructor ~xpath_query(); + #if __cplusplus >= 201103 + // Move semantics support + xpath_query(xpath_query&& rhs); + xpath_query& operator=(xpath_query&& rhs); + #endif + // Get query expression return type xpath_value_type return_type() const; @@ -1261,6 +1277,12 @@ namespace pugi xpath_node_set(const xpath_node_set& ns); xpath_node_set& operator=(const xpath_node_set& ns); + #if __cplusplus >= 201103 + // Move semantics support + xpath_node_set(xpath_node_set&& rhs); + xpath_node_set& operator=(xpath_node_set&& rhs); + #endif + // Get collection type type_t type() const; @@ -1292,6 +1314,7 @@ namespace pugi xpath_node* _end; void _assign(const_iterator begin, const_iterator end, type_t type); + void _move(xpath_node_set& rhs); }; #endif -- cgit v1.2.3