summaryrefslogtreecommitdiff
path: root/ACE/contrib/utility/Example/Introspection/InheritanceTree
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/contrib/utility/Example/Introspection/InheritanceTree')
-rw-r--r--ACE/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.cpp104
-rw-r--r--ACE/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.hpp61
-rw-r--r--ACE/contrib/utility/Example/Introspection/InheritanceTree/Makefile22
-rw-r--r--ACE/contrib/utility/Example/Introspection/InheritanceTree/inheritance_tree.cpp65
4 files changed, 252 insertions, 0 deletions
diff --git a/ACE/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.cpp b/ACE/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.cpp
new file mode 100644
index 00000000000..0dbc616483e
--- /dev/null
+++ b/ACE/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.cpp
@@ -0,0 +1,104 @@
+// file : Hierarchy.cpp
+// author : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license : http://kolpackov.net/license.html
+
+#include "Hierarchy.hpp"
+
+// A
+//
+//
+
+using Introspection::Object;
+using Introspection::Access;
+
+namespace
+{
+ TypeInfo
+ a_init_ ()
+ {
+ TypeInfo ti (typeid (A));
+ ti.add_base (Access::PUBLIC, true, Object::static_type_info ());
+ return ti;
+ }
+
+ TypeInfo a_ (a_init_ ());
+}
+
+TypeInfo const& A::
+static_type_info ()
+{
+ return a_;
+}
+
+// B
+//
+//
+
+namespace
+{
+ TypeInfo
+ b_init_ ()
+ {
+ TypeInfo ti (typeid (B));
+ ti.add_base (Access::PUBLIC, false, A::static_type_info ());
+ return ti;
+ }
+
+ TypeInfo b_ (b_init_ ());
+}
+
+TypeInfo const& B::
+static_type_info ()
+{
+ return b_;
+}
+
+// C
+//
+//
+
+namespace
+{
+ TypeInfo
+ c_init_ ()
+ {
+ TypeInfo ti (typeid (C));
+ ti.add_base (Access::PUBLIC, true, A::static_type_info ());
+ return ti;
+ }
+
+ TypeInfo c_ (c_init_ ());
+}
+
+TypeInfo const& C::
+static_type_info ()
+{
+ return c_;
+}
+
+
+// D
+//
+//
+
+namespace
+{
+ TypeInfo
+ d_init_ ()
+ {
+ TypeInfo ti (typeid (D));
+ ti.add_base (Access::PUBLIC, true, B::static_type_info ());
+ ti.add_base (Access::PUBLIC, false, C::static_type_info ());
+ return ti;
+ }
+
+ TypeInfo d_ (d_init_ ());
+}
+
+TypeInfo const& D::
+static_type_info ()
+{
+ return d_;
+}
+//$Id$
diff --git a/ACE/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.hpp b/ACE/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.hpp
new file mode 100644
index 00000000000..213e0593f6b
--- /dev/null
+++ b/ACE/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.hpp
@@ -0,0 +1,61 @@
+// file : Example/Introspection/InheritanceTree/Hierarchy.hpp
+// author : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license : http://kolpackov.net/license.html
+
+#ifndef HIERARCHY_HPP
+#define HIERARCHY_HPP
+
+#include "Utility/Introspection/Introspection.hpp"
+
+namespace Introspection = Utility::Introspection;
+
+using Introspection::TypeInfo;
+using Introspection::TypeId;
+
+struct A : virtual Introspection::Object
+{
+ A ()
+ {
+ type_info (static_type_info ());
+ }
+
+ static TypeInfo const&
+ static_type_info ();
+};
+
+struct B : virtual A
+{
+ B ()
+ {
+ type_info (static_type_info ());
+ }
+
+ static TypeInfo const&
+ static_type_info ();
+};
+
+struct C : virtual A
+{
+ C ()
+ {
+ type_info (static_type_info ());
+ }
+
+ static TypeInfo const&
+ static_type_info ();
+};
+
+struct D : virtual B, C
+{
+ D ()
+ {
+ type_info (static_type_info ());
+ }
+
+ static TypeInfo const&
+ static_type_info ();
+};
+
+#endif // HIERARCHY_HPP
+//$Id$
diff --git a/ACE/contrib/utility/Example/Introspection/InheritanceTree/Makefile b/ACE/contrib/utility/Example/Introspection/InheritanceTree/Makefile
new file mode 100644
index 00000000000..9b839c2111f
--- /dev/null
+++ b/ACE/contrib/utility/Example/Introspection/InheritanceTree/Makefile
@@ -0,0 +1,22 @@
+# file : Example/Introspection/InheritanceTree/Makefile
+# author : Boris Kolpackov <boris@kolpackov.net>
+# copyright : Copyright (c) 2002-2003 Boris Kolpackov
+# license : http://kolpackov.net/license.html
+
+root := ../../..
+
+include $(root)/BuildRules/Bootstrap.rules
+
+$(call include, $(root)/BuildRules/Executable.pre.rules)
+
+
+cxx_translation_units := Hierarchy.cpp inheritance_tree.cpp
+
+module_base := inheritance_tree
+
+CXX_PREPROCESS_FLAGS += -I $(root)
+
+CXX_LINK_LIBS += -L$(root)/Utility/Introspection -lIntrospection
+
+$(call include, $(root)/BuildRules/Executable.post.rules)
+# $Id$
diff --git a/ACE/contrib/utility/Example/Introspection/InheritanceTree/inheritance_tree.cpp b/ACE/contrib/utility/Example/Introspection/InheritanceTree/inheritance_tree.cpp
new file mode 100644
index 00000000000..61f68ab6aa5
--- /dev/null
+++ b/ACE/contrib/utility/Example/Introspection/InheritanceTree/inheritance_tree.cpp
@@ -0,0 +1,65 @@
+// file : Example/Introspection/InheritanceTree/inheritance_tree.cpp
+// author : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license : http://kolpackov.net/license.html
+
+// Note: This example is by no means complete. In fact properly printing
+// arbitrary C++ inheritance tree is a non-trivial task. If you would like
+// to improve this example please feel free to send your results back ;-).
+
+/* FUZZ: disable check_for_improper_main_declaration */
+
+#include "Hierarchy.hpp"
+
+#include <set>
+#include <iostream>
+
+using std::endl;
+
+typedef
+std::set<TypeId>
+TypeIdSet;
+
+void
+print_inheritance_tree_core (std::ostream& os,
+ TypeInfo const& ti,
+ TypeIdSet& set)
+{
+ bool nl = false;
+
+ for (TypeInfo::BaseIterator i = ti.begin_base ();
+ i != ti.end_base ();
+ i++)
+ {
+ TypeId tid (i->type_info ().type_id ());
+
+ if (set.find (tid) != set.end ()) continue;
+
+ nl = true;
+ set.insert (tid);
+ print_inheritance_tree_core (os, i->type_info (), set);
+ }
+
+ if (nl) os << endl;
+
+ os << ti.type_id () << " ";
+}
+
+void
+print_inheritance_tree (std::ostream& os, TypeInfo const& ti)
+{
+ TypeIdSet set;
+ print_inheritance_tree_core (os, ti, set);
+ os << endl;
+}
+
+int
+main ()
+{
+ B* b = new D;
+
+ print_inheritance_tree (std::cout, b->type_info ());
+
+ delete b;
+}
+//$Id$