From c18c848179e10ab770a4c11c2b1a16985bdea70d Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 6 Oct 2023 16:39:53 -0400 Subject: [PATCH] tidy: c++ indentation --- include/reflect/TaggedPtr.hpp | 182 +++++++++++++++++----------------- 1 file changed, 90 insertions(+), 92 deletions(-) diff --git a/include/reflect/TaggedPtr.hpp b/include/reflect/TaggedPtr.hpp index 653c8ad7..610cb00f 100644 --- a/include/reflect/TaggedPtr.hpp +++ b/include/reflect/TaggedPtr.hpp @@ -7,119 +7,117 @@ #include namespace xo { -namespace reflect { - class TaggedRcptr; /* see [reflect/TaggedRcptr.hpp] */ + namespace reflect { + class TaggedRcptr; /* see [reflect/TaggedRcptr.hpp] */ - class TaggedPtr { - public: - TaggedPtr(TypeDescr td, void * x) : td_{td}, address_{x} {} + class TaggedPtr { + public: + TaggedPtr(TypeDescr td, void * x) : td_{td}, address_{x} {} - static TaggedPtr universal_null() { return TaggedPtr(nullptr, nullptr); } + static TaggedPtr universal_null() { return TaggedPtr(nullptr, nullptr); } - /* would be clean to put make() here; - * however it leads to cyclic #include paths, - * so put it elsewhere - */ + /* would be clean to put make() here; + * however it leads to cyclic #include paths, + * so put it elsewhere + */ #ifdef NOT_USING - template - static TaggedPtr make(T * x) { return TaggedPtr(Reflect::require(), x); } + template + static TaggedPtr make(T * x) { return TaggedPtr(Reflect::require(), x); } #endif - /* visit an object tree. calls preorder_visit_fn() on tp, - * and all objects reachable directly-or-indirectly from tp. - * will call preorder_visit_fn() multiple times if there are multiple paths - * to a node. - * - * require: no cycles in object graph -- undefined behavior if a cycle is present - */ - template - static void visit_tree_preorder(TaggedPtr tp, Fn && preorder_visit_fn) { - using std::uint32_t; + /* visit an object tree. calls preorder_visit_fn() on tp, + * and all objects reachable directly-or-indirectly from tp. + * will call preorder_visit_fn() multiple times if there are multiple paths + * to a node. + * + * require: no cycles in object graph -- undefined behavior if a cycle is present + */ + template + static void visit_tree_preorder(TaggedPtr tp, Fn && preorder_visit_fn) { + using std::uint32_t; - preorder_visit_fn(tp); + preorder_visit_fn(tp); - for(uint32_t i = 0, n = tp.n_child(); i < n; ++i) { - visit_tree_preorder(tp.get_child(i), preorder_visit_fn); - } - } /*visit_tree_preorder*/ - - /* visit object graph. calls preorder_visit_fn() on tp in depth-first - * order. detects and silently prunes duplicate/cyclic references. - */ - template - static void visit_graph(TaggedPtr tp, Fn && visit_fn) { - std::unordered_set visited_set; + for(uint32_t i = 0, n = tp.n_child(); i < n; ++i) { + visit_tree_preorder(tp.get_child(i), preorder_visit_fn); + } + } /*visit_tree_preorder*/ - visit_graph_aux(tp, visit_fn, &visited_set); - } /*visit_graph*/ + /* visit object graph. calls preorder_visit_fn() on tp in depth-first + * order. detects and silently prunes duplicate/cyclic references. + */ + template + static void visit_graph(TaggedPtr tp, Fn && visit_fn) { + std::unordered_set visited_set; - TypeDescr td() const { return td_; } - void * address() const { return address_; } - - void assign_td(TypeDescr x) { td_ = x; } - void assign_address(void * x) { address_ = x; } + visit_graph_aux(tp, visit_fn, &visited_set); + } /*visit_graph*/ - bool is_universal_null() const { return (td_ == nullptr) && (address_ == nullptr); } - bool is_vector() const { return td_ && td_->is_vector(); } - bool is_struct() const { return td_ && td_->is_struct(); } + TypeDescr td() const { return td_; } + void * address() const { return address_; } + + void assign_td(TypeDescr x) { td_ = x; } + void assign_address(void * x) { address_ = x; } + + bool is_universal_null() const { return (td_ == nullptr) && (address_ == nullptr); } + bool is_vector() const { return td_ && td_->is_vector(); } + bool is_struct() const { return td_ && td_->is_struct(); } - /* returns pointer-to-T, if in fact this tagged pointer is understood - * to refer to a T-instance; otherwise nullptr - */ - template - T * recover_native() const { return this->td_->recover_native(this->address_); } + /* returns pointer-to-T, if in fact this tagged pointer is understood + * to refer to a T-instance; otherwise nullptr + */ + template + T * recover_native() const { return this->td_->recover_native(this->address_); } - uint32_t n_child() const { - return this->td_->n_child(this->address_); - } /*n_child*/ + uint32_t n_child() const { + return this->td_->n_child(this->address_); + } /*n_child*/ - TaggedPtr get_child(uint32_t i) const { - return this->td_->child_tp(i, this->address_); - } /*get_child*/ + TaggedPtr get_child(uint32_t i) const { + return this->td_->child_tp(i, this->address_); + } /*get_child*/ - /* require: - * - .is_struct() is true - */ - std::string const & struct_member_name(uint32_t i) const { - return this->td_->struct_member_name(i); - } + /* require: + * - .is_struct() is true + */ + std::string const & struct_member_name(uint32_t i) const { + return this->td_->struct_member_name(i); + } - private: - template - static void visit_graph_aux(TaggedPtr tp, - Fn && visit_fn, - std::unordered_set * p_visited_set) - { - if (tp.address() == nullptr) - return; - - if (p_visited_set->find(tp.address()) == p_visited_set->end()) { - p_visited_set->insert(tp.address()); + private: + template + static void visit_graph_aux(TaggedPtr tp, + Fn && visit_fn, + std::unordered_set * p_visited_set) + { + if (tp.address() == nullptr) + return; - visit_fn(tp); - - for (uint32_t i = 0, n = tp.n_child(); i < n; ++i) { - visit_graph_aux(tp.get_child(i), visit_fn, p_visited_set); - } - } - } /*visit_graph_aux*/ + if (p_visited_set->find(tp.address()) == p_visited_set->end()) { + p_visited_set->insert(tp.address()); - private: - friend class TaggedRcptr; + visit_fn(tp); - private: - /* describes the actual type stored at *address. - * can be null if .address is null - */ - TypeDescr td_; - /* address with type information preserved at runtime */ - void * address_; - }; /*TaggedPtr*/ + for (uint32_t i = 0, n = tp.n_child(); i < n; ++i) { + visit_graph_aux(tp.get_child(i), visit_fn, p_visited_set); + } + } + } /*visit_graph_aux*/ -} /*namespace reflect*/ + private: + friend class TaggedRcptr; + + private: + /* describes the actual type stored at *address. + * can be null if .address is null + */ + TypeDescr td_; + /* address with type information preserved at runtime */ + void * address_; + }; /*TaggedPtr*/ + + } /*namespace reflect*/ } /*namespace xo*/ /* end TaggedPtr.hpp */ - -