From 711701c42d16c84440b025ef6488785cbbe0036b Mon Sep 17 00:00:00 2001 From: turkaye Date: Tue, 24 May 2005 04:33:13 +0000 Subject: ChangeLogTag: Mon May 23 23:11:14 2005 Emre Turkay --- ChangeLog | 6 + contrib/utility/BuildRules/Archive.gcc.post.rules | 47 ++++ contrib/utility/BuildRules/Archive.gcc.pre.rules | 28 +++ contrib/utility/BuildRules/Archive.post.rules | 7 + contrib/utility/BuildRules/Archive.pre.rules | 7 + contrib/utility/BuildRules/Bootstrap.rules | 95 +++++++ .../utility/BuildRules/Documentation.post.rules | 35 +++ contrib/utility/BuildRules/Documentation.pre.rules | 18 ++ .../utility/BuildRules/Executable.gcc.post.rules | 46 ++++ .../utility/BuildRules/Executable.gcc.pre.rules | 26 ++ .../BuildRules/Executable.generic.post.rules | 55 +++++ .../BuildRules/Executable.generic.pre.rules | 26 ++ contrib/utility/BuildRules/Executable.post.rules | 8 + contrib/utility/BuildRules/Executable.pre.rules | 8 + contrib/utility/BuildRules/Object.gcc.post.rules | 38 +++ contrib/utility/BuildRules/Object.gcc.pre.rules | 22 ++ contrib/utility/BuildRules/Object.post.rules | 7 + contrib/utility/BuildRules/Object.pre.rules | 7 + contrib/utility/BuildRules/Recursion.post.rules | 37 +++ contrib/utility/BuildRules/Recursion.pre.rules | 13 + contrib/utility/BuildRules/Shared.gcc.post.rules | 43 ++++ contrib/utility/BuildRules/Shared.gcc.pre.rules | 26 ++ .../utility/BuildRules/Shared.generic.post.rules | 51 ++++ .../utility/BuildRules/Shared.generic.pre.rules | 26 ++ contrib/utility/BuildRules/Shared.post.rules | 7 + contrib/utility/BuildRules/Shared.pre.rules | 7 + contrib/utility/BuildRules/Thoughts | 55 +++++ contrib/utility/Documentation/Build.xhtml | 58 +++++ .../utility/Documentation/CommandLine/News.xhtml | 31 +++ .../Documentation/CommandLine/Terminology.xhtml | 272 +++++++++++++++++++++ contrib/utility/Documentation/CommandLine/Thoughts | 8 + .../utility/Documentation/CommandLine/index.xhtml | 39 +++ .../utility/Documentation/ExH/Compound.hpp.html | 50 ++++ contrib/utility/Documentation/ExH/Example/Makefile | 26 ++ .../Documentation/ExH/Example/bad_cast.cpp.html | 63 +++++ .../Documentation/ExH/Example/compound.cpp.html | 153 ++++++++++++ .../Documentation/ExH/Example/hello_world.cpp.html | 152 ++++++++++++ .../ExH/Example/logic_to_system.cpp.html | 69 ++++++ .../ExH/Logic/DescriptiveException.hpp.html | 61 +++++ .../Documentation/ExH/Logic/Exception.hpp.html | 43 ++++ contrib/utility/Documentation/ExH/Logic/Makefile | 20 ++ contrib/utility/Documentation/ExH/Makefile | 16 ++ .../Documentation/ExH/Makefile.documentation | 20 ++ contrib/utility/Documentation/ExH/News.xhtml | 47 ++++ .../ExH/System/DescriptiveException.hpp.html | 64 +++++ .../Documentation/ExH/System/Exception.hpp.html | 32 +++ contrib/utility/Documentation/ExH/System/Makefile | 20 ++ contrib/utility/Documentation/ExH/index.xhtml | 60 +++++ contrib/utility/Documentation/Hetero/News.xhtml | 31 +++ contrib/utility/Documentation/Hetero/index.xhtml | 62 +++++ .../utility/Documentation/Introspection/News.xhtml | 38 +++ .../Documentation/Introspection/index.xhtml | 42 ++++ contrib/utility/Documentation/Makefile | 16 ++ contrib/utility/Documentation/News.xhtml | 72 ++++++ .../ReferenceCounting/DefaultImpl.hpp.html | 93 +++++++ .../ReferenceCounting/Interface.hpp.html | 82 +++++++ .../Documentation/ReferenceCounting/Makefile | 22 ++ .../Documentation/ReferenceCounting/News.xhtml | 90 +++++++ .../ReferenceCounting/SmartPtr.hpp.html | 103 ++++++++ .../ReferenceCounting/StrictPtr.hpp.html | 107 ++++++++ .../Documentation/ReferenceCounting/index.xhtml | 50 ++++ contrib/utility/Documentation/ReleaseProcess | 13 + contrib/utility/Documentation/Style/CXX.css | 9 + contrib/utility/Documentation/Style/CXX_Blue.css | 25 ++ contrib/utility/Documentation/Style/Default.css | 45 ++++ contrib/utility/Documentation/Synch/Makefile | 16 ++ contrib/utility/Documentation/Synch/News.xhtml | 36 +++ .../utility/Documentation/Synch/Policy/Makefile | 20 ++ .../Documentation/Synch/Policy/Null.hpp.html | 59 +++++ contrib/utility/Documentation/Synch/index.xhtml | 48 ++++ contrib/utility/Documentation/TODO | 53 ++++ contrib/utility/Documentation/Template.xhtml | 33 +++ .../utility/Documentation/Thoughts/Enum/EnumCount | 95 +++++++ .../utility/Documentation/Thoughts/Enum/EnumCount2 | 17 ++ .../utility/Documentation/Thoughts/Enum/EnumInfo | 45 ++++ contrib/utility/Documentation/index.xhtml | 81 ++++++ .../utility/Example/CommandLine/Foo/command.cpp | 86 +++++++ contrib/utility/Example/CommandLine/Foo/foo.cpp | 183 ++++++++++++++ contrib/utility/Example/ExH/BadCast/Makefile | 24 ++ contrib/utility/Example/ExH/BadCast/bad_cast.cpp | 52 ++++ contrib/utility/Example/ExH/Compound/Makefile | 24 ++ contrib/utility/Example/ExH/Compound/compound.cpp | 142 +++++++++++ contrib/utility/Example/ExH/HelloWorld/Makefile | 24 ++ .../utility/Example/ExH/HelloWorld/hello_world.cpp | 141 +++++++++++ contrib/utility/Example/ExH/LogicToSystem/Makefile | 24 ++ .../Example/ExH/LogicToSystem/logic_to_system.cpp | 58 +++++ contrib/utility/Example/ExH/Makefile | 16 ++ contrib/utility/Example/Hetero/Container/Makefile | 24 ++ .../utility/Example/Hetero/Container/container.cpp | 110 +++++++++ contrib/utility/Example/Hetero/Makefile | 16 ++ .../Introspection/InheritanceTree/Hierarchy.cpp | 104 ++++++++ .../Introspection/InheritanceTree/Hierarchy.hpp | 61 +++++ .../Example/Introspection/InheritanceTree/Makefile | 22 ++ .../InheritanceTree/inheritance_tree.cpp | 64 +++++ contrib/utility/Example/Introspection/Makefile | 16 ++ .../Example/Introspection/Traversal/Makefile | 22 ++ .../Example/Introspection/Traversal/SyntaxTree.cpp | 119 +++++++++ .../Example/Introspection/Traversal/SyntaxTree.hpp | 95 +++++++ .../Example/Introspection/Traversal/Traversal.cpp | 105 ++++++++ .../Example/Introspection/Traversal/Traversal.hpp | 157 ++++++++++++ .../Example/Introspection/Traversal/driver.cpp | 91 +++++++ contrib/utility/Example/Makefile | 16 ++ contrib/utility/Makefile | 18 ++ contrib/utility/Test/ExH/Compound/Makefile | 24 ++ contrib/utility/Test/ExH/Compound/compound.cpp | 115 +++++++++ contrib/utility/Test/ExH/Converter/Makefile | 24 ++ contrib/utility/Test/ExH/Converter/converter.cpp | 48 ++++ contrib/utility/Test/ExH/Inline/Makefile | 24 ++ contrib/utility/Test/ExH/Inline/inline.cpp | 18 ++ contrib/utility/Test/ExH/Inline/unit.cpp | 8 + .../Test/ExH/Logic/DescriptiveException/Makefile | 24 ++ .../DescriptiveException/descriptive_exception.cpp | 108 ++++++++ contrib/utility/Test/ExH/Logic/Makefile | 16 ++ contrib/utility/Test/ExH/Makefile | 16 ++ .../Test/ExH/System/DescriptiveException/Makefile | 24 ++ .../DescriptiveException/descriptive_exception.cpp | 107 ++++++++ contrib/utility/Test/ExH/System/Makefile | 16 ++ contrib/utility/Test/Introspection/Inline/Makefile | 24 ++ .../utility/Test/Introspection/Inline/inline.cpp | 18 ++ contrib/utility/Test/Introspection/Inline/unit.cpp | 8 + contrib/utility/Test/Introspection/Makefile | 16 ++ contrib/utility/Test/Makefile | 18 ++ .../Test/ReferenceCounting/DefaultImpl/Makefile | 24 ++ .../ReferenceCounting/DefaultImpl/default_impl.cpp | 132 ++++++++++ .../utility/Test/ReferenceCounting/Inline/Makefile | 24 ++ .../Test/ReferenceCounting/Inline/inline.cpp | 16 ++ .../utility/Test/ReferenceCounting/Inline/unit.cpp | 8 + .../Test/ReferenceCounting/Interface/Makefile | 24 ++ .../Test/ReferenceCounting/Interface/interface.cpp | 104 ++++++++ contrib/utility/Test/ReferenceCounting/Makefile | 16 ++ .../Test/ReferenceCounting/SmartPtr/Makefile | 24 ++ .../Test/ReferenceCounting/SmartPtr/smart_ptr.cpp | 220 +++++++++++++++++ .../Test/ReferenceCounting/StrictPtr/Makefile | 24 ++ .../ReferenceCounting/StrictPtr/strict_ptr.cpp | 218 +++++++++++++++++ contrib/utility/Test/Synch/Inline/Makefile | 24 ++ contrib/utility/Test/Synch/Inline/inline.cpp | 18 ++ contrib/utility/Test/Synch/Inline/unit.cpp | 8 + contrib/utility/Test/Synch/Makefile | 16 ++ contrib/utility/Utility/ExH/Compound.hpp | 47 ++++ contrib/utility/Utility/ExH/Compound.tpp | 71 ++++++ contrib/utility/Utility/ExH/Converter.hpp | 24 ++ contrib/utility/Utility/ExH/Converter.tpp | 19 ++ contrib/utility/Utility/ExH/ExH.hpp | 22 ++ .../Utility/ExH/Logic/DescriptiveException.hpp | 63 +++++ .../Utility/ExH/Logic/DescriptiveException.ipp | 104 ++++++++ .../Utility/ExH/Logic/DescriptiveException.tpp | 23 ++ contrib/utility/Utility/ExH/Logic/Exception.hpp | 40 +++ contrib/utility/Utility/ExH/Logic/Exception.ipp | 20 ++ .../utility/Utility/ExH/StringStreamConverter.hpp | 26 ++ .../utility/Utility/ExH/StringStreamConverter.ipp | 18 ++ .../Utility/ExH/System/DescriptiveException.hpp | 63 +++++ .../Utility/ExH/System/DescriptiveException.ipp | 90 +++++++ .../Utility/ExH/System/DescriptiveException.tpp | 23 ++ contrib/utility/Utility/ExH/System/Exception.hpp | 29 +++ contrib/utility/Utility/Hetero/Container.hpp | 182 ++++++++++++++ contrib/utility/Utility/Hetero/Shell.hpp | 86 +++++++ contrib/utility/Utility/Hetero/TypeList.hpp | 46 ++++ contrib/utility/Utility/Hetero/TypedContainer.hpp | 57 +++++ contrib/utility/Utility/Hetero/Vector.hpp | 47 ++++ .../Utility/Introspection/Introspection.hpp | 14 ++ contrib/utility/Utility/Introspection/Makefile | 19 ++ contrib/utility/Utility/Introspection/Object.cpp | 24 ++ contrib/utility/Utility/Introspection/Object.hpp | 47 ++++ contrib/utility/Utility/Introspection/Object.ipp | 48 ++++ contrib/utility/Utility/Introspection/TypeId.cpp | 21 ++ contrib/utility/Utility/Introspection/TypeId.hpp | 47 ++++ contrib/utility/Utility/Introspection/TypeId.ipp | 37 +++ contrib/utility/Utility/Introspection/TypeId.tpp | 18 ++ contrib/utility/Utility/Introspection/TypeInfo.hpp | 104 ++++++++ contrib/utility/Utility/Introspection/TypeInfo.ipp | 77 ++++++ contrib/utility/Utility/Makefile | 16 ++ .../Utility/ReferenceCounting/DefaultImpl.hpp | 96 ++++++++ .../Utility/ReferenceCounting/DefaultImpl.ipp | 105 ++++++++ .../Utility/ReferenceCounting/ExternalLockImpl.hpp | 60 +++++ .../Utility/ReferenceCounting/ExternalLockImpl.ipp | 122 +++++++++ .../Utility/ReferenceCounting/Interface.hpp | 84 +++++++ .../Utility/ReferenceCounting/Interface.ipp | 22 ++ .../Utility/ReferenceCounting/Interface.tpp | 20 ++ .../ReferenceCounting/ReferenceCounting.hpp | 16 ++ .../utility/Utility/ReferenceCounting/SmartPtr.hpp | 103 ++++++++ .../utility/Utility/ReferenceCounting/SmartPtr.tpp | 170 +++++++++++++ .../Utility/ReferenceCounting/StrictPtr.hpp | 108 ++++++++ .../Utility/ReferenceCounting/StrictPtr.tpp | 167 +++++++++++++ contrib/utility/Utility/Synch/Policy/Null.hpp | 54 ++++ contrib/utility/Utility/Synch/Policy/Null.ipp | 20 ++ contrib/utility/Vault/StringConverter.hpp | 27 ++ contrib/utility/Vault/StringConverter.ipp | 18 ++ contrib/utility/Vault/hetero/map | 13 + contrib/utility/Vault/hetero/map.hpp | 249 +++++++++++++++++++ contrib/utility/Vault/hetero/map.tpp | 12 + contrib/utility/Version | 3 + contrib/utility/license.html | 79 ++++++ 192 files changed, 9948 insertions(+) create mode 100644 contrib/utility/BuildRules/Archive.gcc.post.rules create mode 100644 contrib/utility/BuildRules/Archive.gcc.pre.rules create mode 100644 contrib/utility/BuildRules/Archive.post.rules create mode 100644 contrib/utility/BuildRules/Archive.pre.rules create mode 100644 contrib/utility/BuildRules/Bootstrap.rules create mode 100644 contrib/utility/BuildRules/Documentation.post.rules create mode 100644 contrib/utility/BuildRules/Documentation.pre.rules create mode 100644 contrib/utility/BuildRules/Executable.gcc.post.rules create mode 100644 contrib/utility/BuildRules/Executable.gcc.pre.rules create mode 100644 contrib/utility/BuildRules/Executable.generic.post.rules create mode 100644 contrib/utility/BuildRules/Executable.generic.pre.rules create mode 100644 contrib/utility/BuildRules/Executable.post.rules create mode 100644 contrib/utility/BuildRules/Executable.pre.rules create mode 100644 contrib/utility/BuildRules/Object.gcc.post.rules create mode 100644 contrib/utility/BuildRules/Object.gcc.pre.rules create mode 100644 contrib/utility/BuildRules/Object.post.rules create mode 100644 contrib/utility/BuildRules/Object.pre.rules create mode 100644 contrib/utility/BuildRules/Recursion.post.rules create mode 100644 contrib/utility/BuildRules/Recursion.pre.rules create mode 100644 contrib/utility/BuildRules/Shared.gcc.post.rules create mode 100644 contrib/utility/BuildRules/Shared.gcc.pre.rules create mode 100644 contrib/utility/BuildRules/Shared.generic.post.rules create mode 100644 contrib/utility/BuildRules/Shared.generic.pre.rules create mode 100644 contrib/utility/BuildRules/Shared.post.rules create mode 100644 contrib/utility/BuildRules/Shared.pre.rules create mode 100644 contrib/utility/BuildRules/Thoughts create mode 100644 contrib/utility/Documentation/Build.xhtml create mode 100644 contrib/utility/Documentation/CommandLine/News.xhtml create mode 100644 contrib/utility/Documentation/CommandLine/Terminology.xhtml create mode 100644 contrib/utility/Documentation/CommandLine/Thoughts create mode 100644 contrib/utility/Documentation/CommandLine/index.xhtml create mode 100644 contrib/utility/Documentation/ExH/Compound.hpp.html create mode 100644 contrib/utility/Documentation/ExH/Example/Makefile create mode 100644 contrib/utility/Documentation/ExH/Example/bad_cast.cpp.html create mode 100644 contrib/utility/Documentation/ExH/Example/compound.cpp.html create mode 100644 contrib/utility/Documentation/ExH/Example/hello_world.cpp.html create mode 100644 contrib/utility/Documentation/ExH/Example/logic_to_system.cpp.html create mode 100644 contrib/utility/Documentation/ExH/Logic/DescriptiveException.hpp.html create mode 100644 contrib/utility/Documentation/ExH/Logic/Exception.hpp.html create mode 100644 contrib/utility/Documentation/ExH/Logic/Makefile create mode 100644 contrib/utility/Documentation/ExH/Makefile create mode 100644 contrib/utility/Documentation/ExH/Makefile.documentation create mode 100644 contrib/utility/Documentation/ExH/News.xhtml create mode 100644 contrib/utility/Documentation/ExH/System/DescriptiveException.hpp.html create mode 100644 contrib/utility/Documentation/ExH/System/Exception.hpp.html create mode 100644 contrib/utility/Documentation/ExH/System/Makefile create mode 100644 contrib/utility/Documentation/ExH/index.xhtml create mode 100644 contrib/utility/Documentation/Hetero/News.xhtml create mode 100644 contrib/utility/Documentation/Hetero/index.xhtml create mode 100644 contrib/utility/Documentation/Introspection/News.xhtml create mode 100644 contrib/utility/Documentation/Introspection/index.xhtml create mode 100644 contrib/utility/Documentation/Makefile create mode 100644 contrib/utility/Documentation/News.xhtml create mode 100644 contrib/utility/Documentation/ReferenceCounting/DefaultImpl.hpp.html create mode 100644 contrib/utility/Documentation/ReferenceCounting/Interface.hpp.html create mode 100644 contrib/utility/Documentation/ReferenceCounting/Makefile create mode 100644 contrib/utility/Documentation/ReferenceCounting/News.xhtml create mode 100644 contrib/utility/Documentation/ReferenceCounting/SmartPtr.hpp.html create mode 100644 contrib/utility/Documentation/ReferenceCounting/StrictPtr.hpp.html create mode 100644 contrib/utility/Documentation/ReferenceCounting/index.xhtml create mode 100644 contrib/utility/Documentation/ReleaseProcess create mode 100644 contrib/utility/Documentation/Style/CXX.css create mode 100644 contrib/utility/Documentation/Style/CXX_Blue.css create mode 100644 contrib/utility/Documentation/Style/Default.css create mode 100644 contrib/utility/Documentation/Synch/Makefile create mode 100644 contrib/utility/Documentation/Synch/News.xhtml create mode 100644 contrib/utility/Documentation/Synch/Policy/Makefile create mode 100644 contrib/utility/Documentation/Synch/Policy/Null.hpp.html create mode 100644 contrib/utility/Documentation/Synch/index.xhtml create mode 100644 contrib/utility/Documentation/TODO create mode 100644 contrib/utility/Documentation/Template.xhtml create mode 100644 contrib/utility/Documentation/Thoughts/Enum/EnumCount create mode 100644 contrib/utility/Documentation/Thoughts/Enum/EnumCount2 create mode 100644 contrib/utility/Documentation/Thoughts/Enum/EnumInfo create mode 100644 contrib/utility/Documentation/index.xhtml create mode 100644 contrib/utility/Example/CommandLine/Foo/command.cpp create mode 100644 contrib/utility/Example/CommandLine/Foo/foo.cpp create mode 100644 contrib/utility/Example/ExH/BadCast/Makefile create mode 100644 contrib/utility/Example/ExH/BadCast/bad_cast.cpp create mode 100644 contrib/utility/Example/ExH/Compound/Makefile create mode 100644 contrib/utility/Example/ExH/Compound/compound.cpp create mode 100644 contrib/utility/Example/ExH/HelloWorld/Makefile create mode 100644 contrib/utility/Example/ExH/HelloWorld/hello_world.cpp create mode 100644 contrib/utility/Example/ExH/LogicToSystem/Makefile create mode 100644 contrib/utility/Example/ExH/LogicToSystem/logic_to_system.cpp create mode 100644 contrib/utility/Example/ExH/Makefile create mode 100644 contrib/utility/Example/Hetero/Container/Makefile create mode 100644 contrib/utility/Example/Hetero/Container/container.cpp create mode 100644 contrib/utility/Example/Hetero/Makefile create mode 100644 contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.cpp create mode 100644 contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.hpp create mode 100644 contrib/utility/Example/Introspection/InheritanceTree/Makefile create mode 100644 contrib/utility/Example/Introspection/InheritanceTree/inheritance_tree.cpp create mode 100644 contrib/utility/Example/Introspection/Makefile create mode 100644 contrib/utility/Example/Introspection/Traversal/Makefile create mode 100644 contrib/utility/Example/Introspection/Traversal/SyntaxTree.cpp create mode 100644 contrib/utility/Example/Introspection/Traversal/SyntaxTree.hpp create mode 100644 contrib/utility/Example/Introspection/Traversal/Traversal.cpp create mode 100644 contrib/utility/Example/Introspection/Traversal/Traversal.hpp create mode 100644 contrib/utility/Example/Introspection/Traversal/driver.cpp create mode 100644 contrib/utility/Example/Makefile create mode 100644 contrib/utility/Makefile create mode 100644 contrib/utility/Test/ExH/Compound/Makefile create mode 100644 contrib/utility/Test/ExH/Compound/compound.cpp create mode 100644 contrib/utility/Test/ExH/Converter/Makefile create mode 100644 contrib/utility/Test/ExH/Converter/converter.cpp create mode 100644 contrib/utility/Test/ExH/Inline/Makefile create mode 100644 contrib/utility/Test/ExH/Inline/inline.cpp create mode 100644 contrib/utility/Test/ExH/Inline/unit.cpp create mode 100644 contrib/utility/Test/ExH/Logic/DescriptiveException/Makefile create mode 100644 contrib/utility/Test/ExH/Logic/DescriptiveException/descriptive_exception.cpp create mode 100644 contrib/utility/Test/ExH/Logic/Makefile create mode 100644 contrib/utility/Test/ExH/Makefile create mode 100644 contrib/utility/Test/ExH/System/DescriptiveException/Makefile create mode 100644 contrib/utility/Test/ExH/System/DescriptiveException/descriptive_exception.cpp create mode 100644 contrib/utility/Test/ExH/System/Makefile create mode 100644 contrib/utility/Test/Introspection/Inline/Makefile create mode 100644 contrib/utility/Test/Introspection/Inline/inline.cpp create mode 100644 contrib/utility/Test/Introspection/Inline/unit.cpp create mode 100644 contrib/utility/Test/Introspection/Makefile create mode 100644 contrib/utility/Test/Makefile create mode 100644 contrib/utility/Test/ReferenceCounting/DefaultImpl/Makefile create mode 100644 contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp create mode 100644 contrib/utility/Test/ReferenceCounting/Inline/Makefile create mode 100644 contrib/utility/Test/ReferenceCounting/Inline/inline.cpp create mode 100644 contrib/utility/Test/ReferenceCounting/Inline/unit.cpp create mode 100644 contrib/utility/Test/ReferenceCounting/Interface/Makefile create mode 100644 contrib/utility/Test/ReferenceCounting/Interface/interface.cpp create mode 100644 contrib/utility/Test/ReferenceCounting/Makefile create mode 100644 contrib/utility/Test/ReferenceCounting/SmartPtr/Makefile create mode 100644 contrib/utility/Test/ReferenceCounting/SmartPtr/smart_ptr.cpp create mode 100644 contrib/utility/Test/ReferenceCounting/StrictPtr/Makefile create mode 100644 contrib/utility/Test/ReferenceCounting/StrictPtr/strict_ptr.cpp create mode 100644 contrib/utility/Test/Synch/Inline/Makefile create mode 100644 contrib/utility/Test/Synch/Inline/inline.cpp create mode 100644 contrib/utility/Test/Synch/Inline/unit.cpp create mode 100644 contrib/utility/Test/Synch/Makefile create mode 100644 contrib/utility/Utility/ExH/Compound.hpp create mode 100644 contrib/utility/Utility/ExH/Compound.tpp create mode 100644 contrib/utility/Utility/ExH/Converter.hpp create mode 100644 contrib/utility/Utility/ExH/Converter.tpp create mode 100644 contrib/utility/Utility/ExH/ExH.hpp create mode 100644 contrib/utility/Utility/ExH/Logic/DescriptiveException.hpp create mode 100644 contrib/utility/Utility/ExH/Logic/DescriptiveException.ipp create mode 100644 contrib/utility/Utility/ExH/Logic/DescriptiveException.tpp create mode 100644 contrib/utility/Utility/ExH/Logic/Exception.hpp create mode 100644 contrib/utility/Utility/ExH/Logic/Exception.ipp create mode 100644 contrib/utility/Utility/ExH/StringStreamConverter.hpp create mode 100644 contrib/utility/Utility/ExH/StringStreamConverter.ipp create mode 100644 contrib/utility/Utility/ExH/System/DescriptiveException.hpp create mode 100644 contrib/utility/Utility/ExH/System/DescriptiveException.ipp create mode 100644 contrib/utility/Utility/ExH/System/DescriptiveException.tpp create mode 100644 contrib/utility/Utility/ExH/System/Exception.hpp create mode 100644 contrib/utility/Utility/Hetero/Container.hpp create mode 100644 contrib/utility/Utility/Hetero/Shell.hpp create mode 100644 contrib/utility/Utility/Hetero/TypeList.hpp create mode 100644 contrib/utility/Utility/Hetero/TypedContainer.hpp create mode 100644 contrib/utility/Utility/Hetero/Vector.hpp create mode 100644 contrib/utility/Utility/Introspection/Introspection.hpp create mode 100644 contrib/utility/Utility/Introspection/Makefile create mode 100644 contrib/utility/Utility/Introspection/Object.cpp create mode 100644 contrib/utility/Utility/Introspection/Object.hpp create mode 100644 contrib/utility/Utility/Introspection/Object.ipp create mode 100644 contrib/utility/Utility/Introspection/TypeId.cpp create mode 100644 contrib/utility/Utility/Introspection/TypeId.hpp create mode 100644 contrib/utility/Utility/Introspection/TypeId.ipp create mode 100644 contrib/utility/Utility/Introspection/TypeId.tpp create mode 100644 contrib/utility/Utility/Introspection/TypeInfo.hpp create mode 100644 contrib/utility/Utility/Introspection/TypeInfo.ipp create mode 100644 contrib/utility/Utility/Makefile create mode 100644 contrib/utility/Utility/ReferenceCounting/DefaultImpl.hpp create mode 100644 contrib/utility/Utility/ReferenceCounting/DefaultImpl.ipp create mode 100644 contrib/utility/Utility/ReferenceCounting/ExternalLockImpl.hpp create mode 100644 contrib/utility/Utility/ReferenceCounting/ExternalLockImpl.ipp create mode 100644 contrib/utility/Utility/ReferenceCounting/Interface.hpp create mode 100644 contrib/utility/Utility/ReferenceCounting/Interface.ipp create mode 100644 contrib/utility/Utility/ReferenceCounting/Interface.tpp create mode 100644 contrib/utility/Utility/ReferenceCounting/ReferenceCounting.hpp create mode 100644 contrib/utility/Utility/ReferenceCounting/SmartPtr.hpp create mode 100644 contrib/utility/Utility/ReferenceCounting/SmartPtr.tpp create mode 100644 contrib/utility/Utility/ReferenceCounting/StrictPtr.hpp create mode 100644 contrib/utility/Utility/ReferenceCounting/StrictPtr.tpp create mode 100644 contrib/utility/Utility/Synch/Policy/Null.hpp create mode 100644 contrib/utility/Utility/Synch/Policy/Null.ipp create mode 100644 contrib/utility/Vault/StringConverter.hpp create mode 100644 contrib/utility/Vault/StringConverter.ipp create mode 100644 contrib/utility/Vault/hetero/map create mode 100644 contrib/utility/Vault/hetero/map.hpp create mode 100644 contrib/utility/Vault/hetero/map.tpp create mode 100644 contrib/utility/Version create mode 100644 contrib/utility/license.html diff --git a/ChangeLog b/ChangeLog index bfe21d21780..56c85f5a0f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon May 23 23:11:14 2005 Emre Turkay + + * contrib/utility/*: + + Added the utility library. + Mon May 23 16:38:13 2005 Steve Huston * examples/Reactor/Proactor/post_completions.cpp: Made use of the diff --git a/contrib/utility/BuildRules/Archive.gcc.post.rules b/contrib/utility/BuildRules/Archive.gcc.post.rules new file mode 100644 index 00000000000..11b052d5200 --- /dev/null +++ b/contrib/utility/BuildRules/Archive.gcc.post.rules @@ -0,0 +1,47 @@ +# file : BuildRules/Archive.gcc.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + + +# +# Note: normally you wouldn't want to change anything below. +# + +FULL_MODULE_PREFIX := $(MODULE_PREFIX)$(module_prefix) +FULL_MODULE_SUFFIX := $(module_suffix)$(MODULE_SUFFIX) +MODULE := $(FULL_MODULE_PREFIX)$(module_base)$(FULL_MODULE_SUFFIX) + +# +# Pattern rules catalog. +# { + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -MD -MP -MT $(@:.o=.d) -MF $(@:.o=.d) -c $< -o $@ + +# } + +# Defines the rule to build module from tarnslated c++ translation units. +$(MODULE) : $(cxx_translation_units:.cpp=.o) $(translated_units) + $(AR) $(AR_FLAGS) $@ $^ + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + -rm -f $(MODULE) + + +# Include dependencies for c++ translation units. +# @@ empty-check should be done in all cases. +## +ifneq ($(strip $(cxx_translation_units)),) +-include $(cxx_translation_units:.cpp=.d) +endif + + +# The following catch-all rule will skip unknown targets +%:: ;@: +# $Id$ diff --git a/contrib/utility/BuildRules/Archive.gcc.pre.rules b/contrib/utility/BuildRules/Archive.gcc.pre.rules new file mode 100644 index 00000000000..fbeb0329055 --- /dev/null +++ b/contrib/utility/BuildRules/Archive.gcc.pre.rules @@ -0,0 +1,28 @@ +# file : BuildRules/Archive.gcc.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ +CXX_DEP ?= $(CXX) -M + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -Wall +CXX_LINK_FLAGS := +CXX_LINK_LIBS := + +AR ?= ar +AR_FLAGS := -rc + +MODULE_PREFIX := lib +MODULE_SUFFIX := .a +# $Id$ diff --git a/contrib/utility/BuildRules/Archive.post.rules b/contrib/utility/BuildRules/Archive.post.rules new file mode 100644 index 00000000000..ffd1dc833f0 --- /dev/null +++ b/contrib/utility/BuildRules/Archive.post.rules @@ -0,0 +1,7 @@ +# file : BuildRules/Archive.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +$(call include, $(dir $(MAKEFILE))/Archive.gcc.post.rules) +# $Id$ diff --git a/contrib/utility/BuildRules/Archive.pre.rules b/contrib/utility/BuildRules/Archive.pre.rules new file mode 100644 index 00000000000..7547d7176f6 --- /dev/null +++ b/contrib/utility/BuildRules/Archive.pre.rules @@ -0,0 +1,7 @@ +# file : BuildRules/Archive.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +$(call include, $(dir $(MAKEFILE))/Archive.gcc.pre.rules) +# $Id$ diff --git a/contrib/utility/BuildRules/Bootstrap.rules b/contrib/utility/BuildRules/Bootstrap.rules new file mode 100644 index 00000000000..32d28e12038 --- /dev/null +++ b/contrib/utility/BuildRules/Bootstrap.rules @@ -0,0 +1,95 @@ +# file : BuildRules/Bootstrap.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# basics +# +# + +define set +$(eval $1 := $(strip $2)) +endef + +define get +$(value $(strip $1)) +endef + +define sub +$(shell expr $1 - $2) +endef + +define add +$(shell expr $1 + $2) +endef + +# stack +# +# + +define push +$(eval $1 +=$(strip $2)) +endef + +define pop +$(eval $1 :=$(wordlist 1,$(call sub, $(words $(value $(strip $1))), 1),$(value $(strip $1)))) +endef + +define top +$(word $(words $(value $(strip $1))),$(value $(strip $1))) +endef + +# local +# +# + +define path_to_id +$(subst /,_,$(subst .,_,$(strip $1))) +endef + +MAKEFILE := $(word $(call sub,$(words $(MAKEFILE_LIST)),1),$(MAKEFILE_LIST)) +INCLUSION_ID := $(call path_to_id,$(MAKEFILE)) + +define get_inclusion_id +$(INCLUSION_ID) +endef + +define local_set +$(eval $(strip $(call get_inclusion_id))_$1 := $(strip $2)) +endef + +define local_get +$($(strip $(call get_inclusion_id))_$1) +endef + +define local_origin +$(origin $(strip $(call get_inclusion_id))_$1) +endef + + +define _get_inclusion_count +$(if $(call local_get,INCLUSION_COUNT),$(call local_get,INCLUSION_COUNT),0) +endef + +define _set_inclusion_count +$(call local_set,INCLUSION_COUNT,$1) +endef + +# include +# +# + +define include +$(strip + $(eval $(call push, include_stack, $(MAKEFILE))) \ + $(eval MAKEFILE :=$(strip $1)) \ + $(eval $(call push, inclusion_id_stack, $(INCLUSION_ID))) \ + $(eval $(call _set_inclusion_count,$(call add,$(call _get_inclusion_count),1))) \ + $(eval INCLUSION_ID :=$(INCLUSION_ID)_$(call local_get,INCLUSION_COUNT)_$(call path_to_id,$1)) \ + $(eval include $1) \ + $(eval INCLUSION_ID :=$(call top, inclusion_id_stack)) \ + $(eval $(call pop, inclusion_id_stack)) \ + $(eval MAKEFILE :=$(call top, include_stack)) \ + $(eval $(call pop, include_stack))) +endef +# $Id$ diff --git a/contrib/utility/BuildRules/Documentation.post.rules b/contrib/utility/BuildRules/Documentation.post.rules new file mode 100644 index 00000000000..33fd0c2942f --- /dev/null +++ b/contrib/utility/BuildRules/Documentation.post.rules @@ -0,0 +1,35 @@ +# file : BuildRules/Documentation.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# +# Note: normally you wouldn't want to change anything below. +# + +# +# Pattern rules catalog. +# { + +# Defined pattern rule to build .hpp.html from .hpp +%.html : % + $(DOC) $(DOC_FLAGS) -o $@ $< + +# } + +# The following rule will inhibit treatment of documentation as +# default target. +.PHONY : all +all: ;@: + +.PHONY : documentation +documentation : $(patsubst %,%.html,$(doc_translation_units)) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(patsubst %,%.html,$(doc_translation_units)) + +# The following catch-all rule will skip unknown targets +%:: ;@: +# $Id$ diff --git a/contrib/utility/BuildRules/Documentation.pre.rules b/contrib/utility/BuildRules/Documentation.pre.rules new file mode 100644 index 00000000000..33161d03d40 --- /dev/null +++ b/contrib/utility/BuildRules/Documentation.pre.rules @@ -0,0 +1,18 @@ +# file : BuildRules/Documentation.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +DOC ?= cpp_to_html +CXX_FLAGS := + +# $Id$ diff --git a/contrib/utility/BuildRules/Executable.gcc.post.rules b/contrib/utility/BuildRules/Executable.gcc.post.rules new file mode 100644 index 00000000000..6587cbf0757 --- /dev/null +++ b/contrib/utility/BuildRules/Executable.gcc.post.rules @@ -0,0 +1,46 @@ +# file : BuildRules/Executable.gcc.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# +# Note: normally you wouldn't want to change anything below. +# + +FULL_MODULE_PREFIX := $(MODULE_PREFIX)$(module_prefix) +FULL_MODULE_SUFFIX := $(module_suffix)$(MODULE_SUFFIX) +MODULE := $(FULL_MODULE_PREFIX)$(module_base)$(FULL_MODULE_SUFFIX) + +# +# Pattern rules catalog. +# { + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -MD -MP -MT $(@:.o=.d) -MF $(@:.o=.d) -c $< -o $@ + +# } + +# Defines the rule to build module from tarnslated c++ translation units. +$(MODULE) : $(cxx_translation_units:.cpp=.o) $(translated_units) + $(CXX) $(CXX_LINK_FLAGS) -o $@ $^ $(CXX_LINK_LIBS) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + -rm -f $(MODULE) + + +# Define a phony target to invoke the test driver. +.PHONY : test +test : $(MODULE) + ./$(MODULE) + +# Include dependencies for c++ translation units. +-include $(cxx_translation_units:.cpp=.d) + +# The following catch-all rule will skip unknown targets +%:: ;@: +# $Id$ diff --git a/contrib/utility/BuildRules/Executable.gcc.pre.rules b/contrib/utility/BuildRules/Executable.gcc.pre.rules new file mode 100644 index 00000000000..f7a0798c824 --- /dev/null +++ b/contrib/utility/BuildRules/Executable.gcc.pre.rules @@ -0,0 +1,26 @@ +# file : BuildRules/Executable.gcc.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -Wall +CXX_LINK_FLAGS := +CXX_LINK_LIBS := + + +MODULE_PREFIX := +MODULE_SUFFIX := + +# $Id$ diff --git a/contrib/utility/BuildRules/Executable.generic.post.rules b/contrib/utility/BuildRules/Executable.generic.post.rules new file mode 100644 index 00000000000..26fa9b3b515 --- /dev/null +++ b/contrib/utility/BuildRules/Executable.generic.post.rules @@ -0,0 +1,55 @@ +# file : BuildRules/Executable.generic.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# +# Note: normally you wouldn't want to change anything below. +# + +FULL_MODULE_PREFIX := $(MODULE_PREFIX)$(module_prefix) +FULL_MODULE_SUFFIX := $(module_suffix)$(MODULE_SUFFIX) +MODULE := $(FULL_MODULE_PREFIX)$(module_base)$(FULL_MODULE_SUFFIX) + +# +# Pattern rules catalog. +# { + +# Defines pattern rule to build .d from .cpp +%.d: %.cpp + set -e; $(CXX_DEP) $(CXX_PREPROCESS_FLAGS) $< \ + | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \ + [ -s $@ ] || rm -f $@ + + + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -c $< -o $@ + +# } + +# Defines the rule to build module from tarnslated c++ translation units. +$(MODULE) : $(cxx_translation_units:.cpp=.o) + $(CXX) $(CXX_LINK_FLAGS) -o $@ $^ $(CXX_LINK_LIBS) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + -rm -f $(MODULE) + + +# Define a phony target to invoke the test driver. +.PHONY : test +test : $(MODULE) + ./$(MODULE) + +# Include dependencies for c++ translation units. +# Optimization: if we are cleaning there is no reason to calculate +# dependencies because they will be removed a second later. +ifneq ($(MAKECMDGOALS),clean) + include $(cxx_translation_units:.cpp=.d) +endif +# $Id$ diff --git a/contrib/utility/BuildRules/Executable.generic.pre.rules b/contrib/utility/BuildRules/Executable.generic.pre.rules new file mode 100644 index 00000000000..995dabeebda --- /dev/null +++ b/contrib/utility/BuildRules/Executable.generic.pre.rules @@ -0,0 +1,26 @@ +# file : BuildRules/Executable.generic.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ +CXX_DEP ?= $(CXX) -M + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -Wall +CXX_LINK_FLAGS := +CXX_LINK_LIBS := + + +MODULE_PREFIX := +MODULE_SUFFIX := +# $Id$ diff --git a/contrib/utility/BuildRules/Executable.post.rules b/contrib/utility/BuildRules/Executable.post.rules new file mode 100644 index 00000000000..da146baf162 --- /dev/null +++ b/contrib/utility/BuildRules/Executable.post.rules @@ -0,0 +1,8 @@ +# file : BuildRules/Executable.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +$(call include, $(dir $(MAKEFILE))/Executable.gcc.post.rules) + +# $Id$ diff --git a/contrib/utility/BuildRules/Executable.pre.rules b/contrib/utility/BuildRules/Executable.pre.rules new file mode 100644 index 00000000000..10a1796450b --- /dev/null +++ b/contrib/utility/BuildRules/Executable.pre.rules @@ -0,0 +1,8 @@ +# file : BuildRules/Executable.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +$(call include, $(dir $(MAKEFILE))/Executable.gcc.pre.rules) + +# $Id$ diff --git a/contrib/utility/BuildRules/Object.gcc.post.rules b/contrib/utility/BuildRules/Object.gcc.post.rules new file mode 100644 index 00000000000..a58c2369435 --- /dev/null +++ b/contrib/utility/BuildRules/Object.gcc.post.rules @@ -0,0 +1,38 @@ +# file : BuildRules/Object.gcc.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + + +# +# Note: normally you wouldn't want to change anything below. +# + +# +# Pattern rules catalog. +# { + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -MD -MP -MT $(@:.o=.d) -MF $(@:.o=.d) -c $< -o $@ + +# } + +# Defines the rule to build object files from c++ translation units. +.PHONY : object +object : $(cxx_translation_units:.cpp=.o) + +# Defines a phony target to clean all that's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + + +# Include dependencies for c++ translation units. +-include $(cxx_translation_units:.cpp=.d) + + +# The following catch-all rule will skip unknown targets +%:: ;@: +# $Id$ diff --git a/contrib/utility/BuildRules/Object.gcc.pre.rules b/contrib/utility/BuildRules/Object.gcc.pre.rules new file mode 100644 index 00000000000..8b8d5527abd --- /dev/null +++ b/contrib/utility/BuildRules/Object.gcc.pre.rules @@ -0,0 +1,22 @@ +# file : BuildRules/Object.gcc.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ +CXX_DEP ?= $(CXX) -M + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -Wall +CXX_LINK_FLAGS := +CXX_LINK_LIBS := +# $Id$ diff --git a/contrib/utility/BuildRules/Object.post.rules b/contrib/utility/BuildRules/Object.post.rules new file mode 100644 index 00000000000..383f759a25a --- /dev/null +++ b/contrib/utility/BuildRules/Object.post.rules @@ -0,0 +1,7 @@ +# file : BuildRules/Object.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +$(call include, $(dir $(MAKEFILE))/Object.gcc.post.rules) +# $Id$ diff --git a/contrib/utility/BuildRules/Object.pre.rules b/contrib/utility/BuildRules/Object.pre.rules new file mode 100644 index 00000000000..54c75e0643d --- /dev/null +++ b/contrib/utility/BuildRules/Object.pre.rules @@ -0,0 +1,7 @@ +# file : BuildRules/Object.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +$(call include, $(dir $(MAKEFILE))/Object.gcc.pre.rules) +# $Id$ diff --git a/contrib/utility/BuildRules/Recursion.post.rules b/contrib/utility/BuildRules/Recursion.post.rules new file mode 100644 index 00000000000..e842f0f4b67 --- /dev/null +++ b/contrib/utility/BuildRules/Recursion.post.rules @@ -0,0 +1,37 @@ +# file : BuildRules/Recursion.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +.PHONY: $(target_directory_list) $(target_makefile_list) + +_submodules:: $(target_directory_list) $(target_makefile_list) + +ifneq ($(strip $(target_directory_list)),) +$(target_directory_list): + $(MAKE) -C $@ -f $(default_makefile_name) $(MAKECMDGOALS) +endif + +ifneq ($(strip $(target_makefile_list)),) +$(target_makefile_list): + $(MAKE) --no-print-directory -f $@ $(MAKECMDGOALS) +endif + +# These rules keep make from trying to use the match-anything rule below to +# rebuild the makefiles. +# +ifneq ($(strip $(default_makefile_name)),) +$(default_makefile_name) : ; +endif + +%.mk :: ; +%.rules :: ; + + +# Anything we don't know how to build will use this rule. The command is a +# do-nothing command, but the prerequisites ensure that the appropriate +# recursive invocations of make will occur. +# +% :: $(target_directory_list) $(target_makefile_list) ; + +# $Id$ diff --git a/contrib/utility/BuildRules/Recursion.pre.rules b/contrib/utility/BuildRules/Recursion.pre.rules new file mode 100644 index 00000000000..1f03311fbc8 --- /dev/null +++ b/contrib/utility/BuildRules/Recursion.pre.rules @@ -0,0 +1,13 @@ +# file : BuildRules/Recursion.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +.SUFFIXES: + +.PHONY: _submodules + +_submodules:: + +default_makefile_name := Makefile +# $Id$ diff --git a/contrib/utility/BuildRules/Shared.gcc.post.rules b/contrib/utility/BuildRules/Shared.gcc.post.rules new file mode 100644 index 00000000000..641f79dfc1d --- /dev/null +++ b/contrib/utility/BuildRules/Shared.gcc.post.rules @@ -0,0 +1,43 @@ +# file : BuildRules/Shared.gcc.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + + +# +# Note: normally you wouldn't want to change anything below. +# + +FULL_MODULE_PREFIX := $(MODULE_PREFIX)$(module_prefix) +FULL_MODULE_SUFFIX := $(module_suffix)$(MODULE_SUFFIX) +MODULE := $(FULL_MODULE_PREFIX)$(module_base)$(FULL_MODULE_SUFFIX) + +# +# Pattern rules catalog. +# { + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -MD -MP -MT $(@:.o=.d) -MF $(@:.o=.d) -c $< -o $@ + +# } + +# Defines the rule to build module from tarnslated c++ translation units. +$(MODULE) : $(cxx_translation_units:.cpp=.o) $(translated_units) + $(CXX) $(CXX_LINK_FLAGS) -o $@ $^ $(CXX_LINK_LIBS) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + -rm -f $(MODULE) + + +# Include dependencies for c++ translation units. +-include $(cxx_translation_units:.cpp=.d) + + +# The following catch-all rule will skip unknown targets +%:: ;@: +# $Id$ diff --git a/contrib/utility/BuildRules/Shared.gcc.pre.rules b/contrib/utility/BuildRules/Shared.gcc.pre.rules new file mode 100644 index 00000000000..d32c42f5260 --- /dev/null +++ b/contrib/utility/BuildRules/Shared.gcc.pre.rules @@ -0,0 +1,26 @@ +# file : BuildRules/Shared.gcc.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ +CXX_DEP ?= $(CXX) -M + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -fPIC -Wall +CXX_LINK_FLAGS := -shared +CXX_LINK_LIBS := + + +MODULE_PREFIX := lib +MODULE_SUFFIX := .so +# $Id$ diff --git a/contrib/utility/BuildRules/Shared.generic.post.rules b/contrib/utility/BuildRules/Shared.generic.post.rules new file mode 100644 index 00000000000..19315b5d7ec --- /dev/null +++ b/contrib/utility/BuildRules/Shared.generic.post.rules @@ -0,0 +1,51 @@ +# file : BuildRules/Shared.generic.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + + +# +# Note: normally you wouldn't want to change anything below. +# + +FULL_MODULE_PREFIX := $(MODULE_PREFIX)$(module_prefix) +FULL_MODULE_SUFFIX := $(module_suffix)$(MODULE_SUFFIX) +MODULE := $(FULL_MODULE_PREFIX)$(module_base)$(FULL_MODULE_SUFFIX) + +# +# Pattern rules catalog. +# { + +# Defines pattern rule to build .d from .cpp +%.d: %.cpp + set -e; $(CXX_DEP) $(CXX_PREPROCESS_FLAGS) $< \ + | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \ + [ -s $@ ] || rm -f $@ + + + +# Defined pattern rule to build .o from .cpp +%.o : %.cpp + $(CXX) $(CXX_PREPROCESS_FLAGS) $(CXX_COMPILE_FLAGS) -c $< -o $@ + +# } + +# Defines the rule to build module from tarnslated c++ translation units. +$(MODULE) : $(cxx_translation_units:.cpp=.o) + $(CXX) $(CXX_LINK_FLAGS) -o $@ $^ $(CXX_LINK_LIBS) + +# Defines a phony target to clean all what's been generated +.PHONY : clean +clean : + -rm -f $(cxx_translation_units:.cpp=.o) + -rm -f $(cxx_translation_units:.cpp=.d) + -rm -f $(MODULE) + + +# Include dependencies for c++ translation units. +# Optimization: if we are cleaning there is no reason to calculate +# dependencies because they will be removed a second later. +ifneq ($(MAKECMDGOALS),clean) + include $(cxx_translation_units:.cpp=.d) +endif +# $Id$ diff --git a/contrib/utility/BuildRules/Shared.generic.pre.rules b/contrib/utility/BuildRules/Shared.generic.pre.rules new file mode 100644 index 00000000000..77b2a055956 --- /dev/null +++ b/contrib/utility/BuildRules/Shared.generic.pre.rules @@ -0,0 +1,26 @@ +# file : BuildRules/Shared.generic.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +# Forces make to delete targets whos rebuild commands failed but +# updated the target. +.DELETE_ON_ERROR: + +# Empties the suffix list for which old-fassion implicit rules would +# be used. The net effect is that all predefined implicit rules are +# disabled now. +.SUFFIXES: + +CXX ?= g++ + +CXX_PREPROCESS_FLAGS := +CXX_COMPILE_FLAGS := -fPIC -Wall +CXX_LINK_FLAGS := -shared +CXX_LINK_LIBS := + + +MODULE_PREFIX := lib +MODULE_SUFFIX := .so + +# $Id$ diff --git a/contrib/utility/BuildRules/Shared.post.rules b/contrib/utility/BuildRules/Shared.post.rules new file mode 100644 index 00000000000..1f098c99b7b --- /dev/null +++ b/contrib/utility/BuildRules/Shared.post.rules @@ -0,0 +1,7 @@ +# file : BuildRules/Shared.post.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +$(call include, $(dir $(MAKEFILE))/Shared.gcc.post.rules) +# $Id$ diff --git a/contrib/utility/BuildRules/Shared.pre.rules b/contrib/utility/BuildRules/Shared.pre.rules new file mode 100644 index 00000000000..9ebbeb534dd --- /dev/null +++ b/contrib/utility/BuildRules/Shared.pre.rules @@ -0,0 +1,7 @@ +# file : BuildRules/Shared.pre.rules +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +$(call include, $(dir $(MAKEFILE))/Shared.gcc.pre.rules) +# $Id$ diff --git a/contrib/utility/BuildRules/Thoughts b/contrib/utility/BuildRules/Thoughts new file mode 100644 index 00000000000..486a44f108b --- /dev/null +++ b/contrib/utility/BuildRules/Thoughts @@ -0,0 +1,55 @@ + +Makefile variable naming style. + +* Each target is usually invoking one or more commands of the following type: + + (1) translator which translates target's prerequsites to target(s) + + (2) arbitrary command which doesn't create target (aka PHONY targets) + +Examples of type (1) are: + + - translation of c++ source to object code + + - translation of object code to executable/shared + +Examples of type (2) are: + + - test: terget + + - clean: target + + +Some properties of these types of targets: + + (1) - usually implemented as an implicit rule + + - sometimes the same program is used as two separate translators + (e.g. CXX is used as a compiler and as a linker) + + + + (2) - seldom (never?) implemented as an implicit rule + + + +Approach #1 + +For type (1) name is derived from the translator's name e.g. + +CXX_COMPILE_FLAGS +CXX_PREPROCESS_FLAGS +CXX_LINK_FLAGS +CXX_LINK_LIBS + +CC_ +LD_ + + +For type (2) name is derived from the target's name e.g. + +TEST_FLAGS +CLEAN_FLAGS +INSTALL_FLAGS + +$Id$ diff --git a/contrib/utility/Documentation/Build.xhtml b/contrib/utility/Documentation/Build.xhtml new file mode 100644 index 00000000000..97e759bdeb7 --- /dev/null +++ b/contrib/utility/Documentation/Build.xhtml @@ -0,0 +1,58 @@ + + + + + + + + + Building Utility Library + + + + + + + + + + + + +

Introduction

+ +

Utility Library mostly consists of a header-only sub-libraries +(the only exception is Introspection Library) so you don't need to +build anything to start using it. However you may want to build +examples or libraries that require compilation. This section describes +how to do that.

+ +

Prerequisites

+ +

To build libraries or examples you will need GNU make and a C++ +compiler with good support of ISO C++ standard.

+ +

Utility Library building environment requires latest features of +GNU make so you have the following options (in the order of increasing +complexity):

+ +
    +
  • Use GNU make 3.81 or later (not available at the time this is written).
  • +
  • Use GNU make 3.80 with patches for bug +1516 +and +1517. +
  • +
  • Use GNU make from CVS.
  • +
+ + + + diff --git a/contrib/utility/Documentation/CommandLine/News.xhtml b/contrib/utility/Documentation/CommandLine/News.xhtml new file mode 100644 index 00000000000..31738f2150d --- /dev/null +++ b/contrib/utility/Documentation/CommandLine/News.xhtml @@ -0,0 +1,31 @@ + + + + + + + + + Command Line Processing Library News + + + + + + + + + + + + + + + diff --git a/contrib/utility/Documentation/CommandLine/Terminology.xhtml b/contrib/utility/Documentation/CommandLine/Terminology.xhtml new file mode 100644 index 00000000000..6c250f1fa70 --- /dev/null +++ b/contrib/utility/Documentation/CommandLine/Terminology.xhtml @@ -0,0 +1,272 @@ + + + + + + + + + Command Line Processing Model and Terminology + + + + + + + + + + + + + + +

Introduction

+ +

+Command line is probably the most universal way of passing information from +caller to the program. Concept of a command line is part of most operating +systems and programming languages including C and C++. However model and +terminology for command line processing vary greatly among different +systems.

+ +

+Single UNIX Specification contains + +Utility Argument Syntax Conventions and Guidelines which document basic +terminology for command line processing. Single UNIX Specification model is +a "common denominator" for different UNIX implementations. It is somewhat +minimal and targets system utilities rather than a wide spectrum of +applications. Another de-facto command line processing model is + GNU Standard for Command +Line Interfaces which generally encourages conformance to the Single UNIX +Specification but adds few extensions and uses different terminology.

+ +

+The idea behind this document is to establish terminology and complete model +for command line processing. Terms translation between this document, Single +UNIX Specification and GNU Standard for Command Line Interfaces is provided +in Appendix A.

+ + +

Model and Terminology

+ +

+Command line is an array of character strings and not just +a string with spaces between words as some people tend to think.

+ +

+Each string in a command line array is referred to as argument +. First argument usually contains a string that refers to an executable. +

+ +

+Interpretation of arguments is completely up to a program logic however +conventions exist that vary among different systems. Usually groups of +arguments are translated into a higher-level objects such as commands, +options, and operands. These objects form a model for command line processing. +All of them are defined below.

+ + +

+Command is usually a word, or a single letter that represents +a command to the program logic. Neither Single UNIX Specification nor GNU +Standard for Command Line Interfaces has the notion of a command. Other terms +for command include action and function. Command is usually +(but not necessarily) the first argument after executable name. Here are few +examples:

+ +

tar x

+ +

+Here we have a one letter command 'x' (extract). In GNU tar +manual it is called functional letter.

+ +

tar xvf

+ +

+Here we have three commands encoded as a single letter each. Actually +semantically only 'x' is a command while 'v' +(verbose) and 'f' (read from a file) are options.

+ +

openssl req

+ +

+Here we have a word command 'req' (operations with certificate +requests).

+ +

cvs checkout foo

+ +

+Here we have a word command 'checkout' and command operand +foo.

+ + +

tar --help

+ +

+Even though '--help' is usually considered to be an option +semantically it is a command.

+ + +

+Option consists of option name and optionally +one or more option values. Options are usually optional. +Non-optional options are usually better represented by commands or operands. +

+ +

Option name usually takes up one argument. Option names usually start with +a prefix (e.g. '--compile-only', '-c' or '/c' +). This helps distinguish them from commands and operands. Option name +may have aliases (e.g. for option name '--output-dir' there could +be an '-o' alias).

+ +

+Option without a value is alway optional and represents an option with implied +binary value (e.g. {0, 1} or {false, true} etc.). Such option is sometimes +called flag.

+ +

+Option can be associated with a program or a command. Thus the concept of +option can be further refined to program option and +command option. Program option alters behavior of the program as a +whole while command option is only affecting particular command.

+ + +

Following are some examples:

+ +

g++ -o hello.o hello.cpp

+ +

+Here we have an option with name '-o' which has a value +'hello.o'. 'hello.cpp' is an operand.

+ + +

ls -l

+ +

Here we have a flag with name '-l'.

+ +

+foo --bar=a,b,c
+foo -b "a,b,c"
+foo /baz a b c +

+ +

+Here we have a more elaborate example of a multi-format option. It has +a name '--bar' and two aliases: '-b' and +'/baz'. It also has three values (in our case they are +'a', 'b', and 'c').

+ +

cvs -z 6 checkout -P foo

+ +

+Here we have a program option with name '-z' and value +'6' (set compression level to be 6). 'checkout' +is a command. -P is a command flag (prune empty directories). +'foo' is a command operand.

+ +

+operand usually represents an input value or a parameter. +Operands can be mandatory or optional. Interpretation of operands is usually +application-specific.

+ +

+Same as with option the concept of operand can be further refined to +program operand and command operand.

+ +

Appendix A: Terms Translation

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TermSingle UNIX SpecificationGNU
command linecommand linecommand line
argumentargumentargument
command----
option--option
option nameoptionname
option valueoption-argument--
program option----
command option----
operandoperandargument
program operand----
command operand----
+ + + + diff --git a/contrib/utility/Documentation/CommandLine/Thoughts b/contrib/utility/Documentation/CommandLine/Thoughts new file mode 100644 index 00000000000..a10675f5945 --- /dev/null +++ b/contrib/utility/Documentation/CommandLine/Thoughts @@ -0,0 +1,8 @@ + +@@ I should not assume that Utility::CommandLine is the only mechanism + used to parse command line. Application developer may be using + different components that employ different command line parsers. + Thus it seem to me that I should use argv/argc as input/output + format. + +$Id$ diff --git a/contrib/utility/Documentation/CommandLine/index.xhtml b/contrib/utility/Documentation/CommandLine/index.xhtml new file mode 100644 index 00000000000..7caf91689aa --- /dev/null +++ b/contrib/utility/Documentation/CommandLine/index.xhtml @@ -0,0 +1,39 @@ + + + + + + + + + Command Line Processing Library + + + + + + + + + + + + +

Introduction

+ +

+Command Line Processing library is in early development stage. You may want +to take a look at Command Line Processing Model +and Terminology page. +

+ + + + diff --git a/contrib/utility/Documentation/ExH/Compound.hpp.html b/contrib/utility/Documentation/ExH/Compound.hpp.html new file mode 100644 index 00000000000..b8996f89552 --- /dev/null +++ b/contrib/utility/Documentation/ExH/Compound.hpp.html @@ -0,0 +1,50 @@ + + + + +Compound.hpp + + +
+// file      : Utility/ExH/Compound.hpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+namespace Utility
+{
+  namespace ExH
+  {
+    template <typename Type, typename Base>
+    class Compound : public virtual Base
+    {
+    public:
+      explicit
+      Compound (char const* description) throw ();
+
+      explicit
+      Compound (std::string const& description) throw ();
+
+      template <typename T>
+      explicit
+      Compound (T const& description) throw ();
+
+      Compound (Compound const& src) throw ();
+
+      virtual
+      ~Compound () throw ();
+
+    public:
+      Compound&
+      operator= (Compound const& src) throw ();
+
+    protected:
+      Compound () throw ();
+    };
+  }
+}
+
+
+ + + diff --git a/contrib/utility/Documentation/ExH/Example/Makefile b/contrib/utility/Documentation/ExH/Example/Makefile new file mode 100644 index 00000000000..e0188a81fbf --- /dev/null +++ b/contrib/utility/Documentation/ExH/Example/Makefile @@ -0,0 +1,26 @@ +# file : Documentation/ExH/Example/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Documentation.pre.rules) + +vpath %.cpp $(root)/Example/ExH/BadCast +vpath %.cpp $(root)/Example/ExH/Compound +vpath %.cpp $(root)/Example/ExH/HelloWorld +vpath %.cpp $(root)/Example/ExH/LogicToSystem + +doc_translation_units := bad_cast.cpp \ + compound.cpp \ + hello_world.cpp \ + logic_to_system.cpp + +DOC_FLAGS := -css $(root)/Documentation/Style/CXX.css + +$(call include, $(root)/BuildRules/Documentation.post.rules) + +# $Id$ diff --git a/contrib/utility/Documentation/ExH/Example/bad_cast.cpp.html b/contrib/utility/Documentation/ExH/Example/bad_cast.cpp.html new file mode 100644 index 00000000000..ba5044e358a --- /dev/null +++ b/contrib/utility/Documentation/ExH/Example/bad_cast.cpp.html @@ -0,0 +1,63 @@ + + + + +bad_cast.cpp + + +
+// file      : Example/ExH/BadCast/bad_cast.cpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+#include "Utility/ExH/System/Exception.hpp"
+
+#include <iostream>
+
+using std::cerr;
+using std::endl;
+
+
+struct A
+{
+  virtual
+  ~A() {}
+};
+
+struct B
+{
+  void
+  foo () {}
+};
+
+void
+foo () throw (Utility::ExH::System::Exception)
+{
+  A a;
+
+  A& ar (a);
+
+  B& br (dynamic_cast<B&> (ar));
+
+  br.foo ();
+}
+
+int
+main ()
+{
+  try
+  {
+    foo ();
+  }
+  catch (Utility::ExH::System::Exception const& ex)
+  {
+    cerr << "Caught Utility::ExH::System::Exception: "
+         << ex.what ()
+         << endl;
+  }
+}
+
+ + + diff --git a/contrib/utility/Documentation/ExH/Example/compound.cpp.html b/contrib/utility/Documentation/ExH/Example/compound.cpp.html new file mode 100644 index 00000000000..40ecf71eee9 --- /dev/null +++ b/contrib/utility/Documentation/ExH/Example/compound.cpp.html @@ -0,0 +1,153 @@ + + + + +compound.cpp + + +
+// file      : Example/ExH/Compound/compound.cpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+#include "Utility/ExH/Compound.hpp"
+#include "Utility/ExH/System/Exception.hpp"
+#include "Utility/ExH/Logic/DescriptiveException.hpp"
+
+// Include some helper converters to allow exception initialization
+// with std::ostringstream
+
+#include "Utility/ExH/StringStreamConverter.hpp"
+
+#include <iostream>
+
+using std::cerr;
+using std::endl;
+using std::string;
+using std::ostringstream;
+
+using namespace Utility::ExH;
+
+// Here are our components
+
+class Base
+{
+public:
+
+  //
+  // Exception definitions.
+  //
+
+  // Base logic exception class for component.
+  class Exception_ {};
+  typedef
+  Compound <Exception_, Logic::DescriptiveException>
+  Exception;
+
+  class InvalidArgument_ {};
+  typedef
+  Compound <InvalidArgument_, Exception>
+  InvalidArgument;
+
+  class NotInitialized_ {};
+  typedef
+  Compound <NotInitialized_, Exception>
+  NotInitialized;
+
+public:
+
+  void
+  foo (char const* str) throw (InvalidArgument, NotInitialized)
+  {
+    // This is just an example.
+
+    if (str == 0)
+    {
+      throw InvalidArgument ("Base::foo: first parameter is zero.");
+    }
+    else
+    {
+      ostringstream ostr;
+      ostr << "Base::foo [this = " << this << "]: object is not initialized.";
+
+      throw NotInitialized (ostr);
+    }
+  }
+
+
+  // We don't know what implementation may decide to throw so
+  // we allow to throw System exception and any logic exception
+  // derived from Base::Exception
+  virtual void
+  vfoo () throw (Exception, System::Exception) = 0;
+};
+
+class Derived : public Base
+{
+public:
+
+  // Define some Derived-specific logic exception.
+  class NotImplemented_ {};
+  typedef
+  Compound <NotImplemented_, Exception>
+  NotImplemented;
+
+public:
+  virtual void
+  vfoo () throw (NotImplemented, System::Exception)
+  {
+    std::string str ("Derived::vfoo: not implemented yet.");
+    throw NotImplemented (str);
+  }
+};
+
+int
+main ()
+{
+  try
+  {
+
+    Derived d;
+    Base* pb (&d);
+
+    // We can use generic handler.
+    try
+    {
+      pb->vfoo ();
+    }
+    catch (Base::Exception const& ex)
+    {
+      cerr << "Caught Base::Exception: " << ex.what () << endl;
+    }
+
+
+    // Or use more precise control.
+    try
+    {
+      pb->foo ("hello");
+    }
+    catch (Base::NotInitialized const& ex)
+    {
+      cerr << "Caught Base::NotInitialized: " << ex.what () << endl;
+    }
+
+    // Or use application-level handler.
+    pb->foo (0);
+
+  }
+  catch (Logic::Exception const& ex)
+  {
+    cerr << "Caught Logic::Exception: " << ex.what () << endl;
+  }
+  catch (...)
+  {
+    cerr << "Caught unknown exception using catch-all handler" << endl;
+    return -1;
+  }
+
+}
+
+ + + diff --git a/contrib/utility/Documentation/ExH/Example/hello_world.cpp.html b/contrib/utility/Documentation/ExH/Example/hello_world.cpp.html new file mode 100644 index 00000000000..3d2497f325e --- /dev/null +++ b/contrib/utility/Documentation/ExH/Example/hello_world.cpp.html @@ -0,0 +1,152 @@ + + + + +hello_world.cpp + + +
+// file      : Example/ExH/HelloWorld/hello_world.cpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+#include <cstdlib> // for std::abort ()
+
+#include <string>
+#include <iostream>
+
+#include "Utility/ExH/System/Exception.hpp"
+#include "Utility/ExH/Logic/Exception.hpp"
+
+using std::cerr;
+using std::cout;
+using std::endl;
+
+using namespace Utility;
+
+class Application
+{
+public:
+  class Exception : public ExH::Logic::Exception {};
+
+  // Hint: you may want to try again...
+  class FeelingDizzy  : public Exception {};
+
+  class InvalidArg : public Exception {};
+
+public:
+  Application () throw (ExH::System::Exception)
+      : // The std::string c-tor may throw any kind of exceptions besides
+        // quite possible std::bad_alloc.
+        greeting_ ("Hello, world!")
+  {
+  }
+
+  Application (char const * greeting) throw (InvalidArg,
+                                             ExH::System::Exception)
+      : greeting_ (greeting == 0 ? "" : greeting)
+  {
+    if (greeting == 0) throw InvalidArg ();
+  }
+
+public:
+
+  void
+  run () throw (FeelingDizzy, ExH::System::Exception)
+  {
+    static unsigned int dizzy_count (0);
+
+    if (dizzy_count++ < 5) throw FeelingDizzy ();
+
+    // The next line can throw full bucket of exceptions
+    // not to mention ios_base::failure.
+    cout << greeting_.c_str () << endl;
+  }
+
+private:
+
+  std::string  greeting_;
+};
+
+
+
+int
+main ()
+{
+  // This is a catch-all layer that should be in use only
+  // if we are really in trouble.
+  try
+  {
+    // This is a catch-system layer. Here we will catch exceptions like
+    // bad_alloc, etc. If we get here it means that nobody wanted/managed
+    // to recover from this kind of errors.
+    try
+    {
+      // This is a catch-logic layer. If we get here it usually
+      // indicates an application logic error.
+      try
+      {
+
+        // Ok, here we go about our application logic.
+        try
+        {
+          for (int i = 0; i < 10; i++)
+          {
+            try
+            {
+              Application app ("Hi dude!");
+              app.run ();
+              break;
+            }
+            catch (Application::FeelingDizzy const& )
+            {
+              if (i == 9)
+              {
+                cerr << "Given up!" << endl;
+                return -1;
+              }
+              else
+              {
+                cerr << "Application is feeling dizzy. Trying again..."
+                     << endl;
+              }
+            }
+          }
+        }
+        catch (Application::InvalidArg const& )
+        {
+          cerr << "Cought Application::InvalidArg : ...hmm... strange!"
+               << endl;
+          return -1;
+        }
+      }
+      catch (ExH::Logic::Exception const& e)
+      {
+        cerr << "Caught Logic::Exception : " << e.what () << endl;
+        return -1;
+      }
+    }
+    catch (const ExH::System::Exception& e)
+    {
+      cerr << "Caught System::Exception : " << e.what () << endl;
+      return -1;
+    }
+    catch (...)
+    {
+      cerr << "Caught unknown exception using catch-all handler. " << endl;
+      return -1;
+    }
+  }
+  catch (...)
+  {
+    // We get here in cases of some hard failure. For example when handling
+    // exception, operator << throws another exception. Usually application
+    // cannot handle such failures itself so we just propagate it futher.
+    std::abort ();
+  }
+}
+
+ + + diff --git a/contrib/utility/Documentation/ExH/Example/logic_to_system.cpp.html b/contrib/utility/Documentation/ExH/Example/logic_to_system.cpp.html new file mode 100644 index 00000000000..d29794d4c2c --- /dev/null +++ b/contrib/utility/Documentation/ExH/Example/logic_to_system.cpp.html @@ -0,0 +1,69 @@ + + + + +logic_to_system.cpp + + +
+// file      : Example/ExH/LogicToSystem/logic_to_system.cpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+#include "Utility/ExH/System/Exception.hpp"
+#include "Utility/ExH/Logic/Exception.hpp"
+
+#include <iostream>
+
+using std::cerr;
+using std::endl;
+
+
+struct SubsystemA
+{
+  class Exception : public Utility::ExH::Logic::Exception {};
+
+  void
+  foo () throw (Exception)
+  {
+    throw Exception ();
+  }
+};
+
+
+struct SubsystemB
+{
+  void
+  foo () throw (Utility::ExH::System::Exception)
+  {
+    SubsystemA a;
+    a.foo ();
+
+    // Here SubsystemB is using SunsystemA but cannot (forgot, doesnt't
+    // want to, doesn't know how to, etc - pick your favorite) handle
+    // exception thrown by SubsystemA. As a result exception is
+    // 'converted' to System::Exception.
+  }
+};
+
+
+int
+main ()
+{
+  try
+  {
+    SubsystemB b;
+    b.foo ();
+  }
+  catch (Utility::ExH::System::Exception const& ex)
+  {
+    cerr << "Caught Utility::ExH::System::Exception: "
+         << ex.what ()
+         << endl;
+  }
+}
+
+ + + diff --git a/contrib/utility/Documentation/ExH/Logic/DescriptiveException.hpp.html b/contrib/utility/Documentation/ExH/Logic/DescriptiveException.hpp.html new file mode 100644 index 00000000000..b54dbd30936 --- /dev/null +++ b/contrib/utility/Documentation/ExH/Logic/DescriptiveException.hpp.html @@ -0,0 +1,61 @@ + + + + +DescriptiveException.hpp + + +
+// file      : Utility/ExH/Logic/DescriptiveException.hpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+namespace Utility
+{
+  namespace ExH
+  {
+    namespace Logic
+    {
+      class DescriptiveException : public virtual Exception
+      {
+      public:
+        explicit
+        DescriptiveException (char const* description) throw ();
+
+        explicit
+        DescriptiveException (std::string const& description) throw ();
+
+        template <typename T>
+        explicit
+        DescriptiveException (T const& description) throw ();
+
+        DescriptiveException (DescriptiveException const& src) throw ();
+
+        virtual
+        ~DescriptiveException () throw ();
+
+        DescriptiveException&
+        operator= (DescriptiveException const& src) throw ();
+
+      protected:
+        DescriptiveException () throw ();
+
+        void
+        init (char const* description) throw ();
+
+      public:
+        virtual char const*
+        what () const throw ();
+
+      private:
+        std::auto_ptr<std::string> description_;
+      };
+    }
+  }
+}
+
+
+ + + diff --git a/contrib/utility/Documentation/ExH/Logic/Exception.hpp.html b/contrib/utility/Documentation/ExH/Logic/Exception.hpp.html new file mode 100644 index 00000000000..5b4b56aa46d --- /dev/null +++ b/contrib/utility/Documentation/ExH/Logic/Exception.hpp.html @@ -0,0 +1,43 @@ + + + + +Exception.hpp + + +
+// file      : Utility/ExH/Logic/Exception.hpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+namespace Utility
+{
+  namespace ExH
+  {
+    namespace Logic
+    {
+
+      // Logic::Exception inherits from System::Exception for the
+      // following reason. Semantically for some part of the
+      // system particular instance of Logic::Exception may seem as
+      // opaque System::Exception and the only way to handle it would
+      // be to propagate it further. In other words Logic::Exception
+      // can be seemlesly "converted" to System::Exception if there is
+      // no part of the system interested in handling it.
+      //
+
+      class Exception : public virtual System::Exception
+      {
+      public:
+        virtual
+        ~Exception () throw ();
+      };
+    }
+  }
+}
+
+
+ + + diff --git a/contrib/utility/Documentation/ExH/Logic/Makefile b/contrib/utility/Documentation/ExH/Logic/Makefile new file mode 100644 index 00000000000..d2d48d406bf --- /dev/null +++ b/contrib/utility/Documentation/ExH/Logic/Makefile @@ -0,0 +1,20 @@ +# file : Documentation/ExH/Logic/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Documentation.pre.rules) + +vpath %.hpp $(root)/Utility/ExH/Logic + +doc_translation_units := Exception.hpp DescriptiveException.hpp + +DOC_FLAGS := --strip-preprocessor -css $(root)/Documentation/Style/CXX.css + +$(call include, $(root)/BuildRules/Documentation.post.rules) + +# $Id$ diff --git a/contrib/utility/Documentation/ExH/Makefile b/contrib/utility/Documentation/ExH/Makefile new file mode 100644 index 00000000000..c4a5bc5f6c0 --- /dev/null +++ b/contrib/utility/Documentation/ExH/Makefile @@ -0,0 +1,16 @@ +# file : Documentation/ExH/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := Makefile.documentation +target_directory_list := Logic System Example + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Documentation/ExH/Makefile.documentation b/contrib/utility/Documentation/ExH/Makefile.documentation new file mode 100644 index 00000000000..3ebf1511555 --- /dev/null +++ b/contrib/utility/Documentation/ExH/Makefile.documentation @@ -0,0 +1,20 @@ +# file : Documentation/ExH/Make.doc.mk +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Documentation.pre.rules) + +vpath %.hpp $(root)/Utility/ExH + +doc_translation_units := Compound.hpp + +DOC_FLAGS := --strip-preprocessor -css $(root)/Documentation/Style/CXX.css + +$(call include, $(root)/BuildRules/Documentation.post.rules) + +# $Id$ diff --git a/contrib/utility/Documentation/ExH/News.xhtml b/contrib/utility/Documentation/ExH/News.xhtml new file mode 100644 index 00000000000..b86f821c992 --- /dev/null +++ b/contrib/utility/Documentation/ExH/News.xhtml @@ -0,0 +1,47 @@ + + + + + + + + + Exception Handling Library News + + + + + + + + + + + + +

1.2.0

+ +
    +
  • + Fixed incorrect initialization of DescriptiveException with + std::ostringstream object. Thanks to Karen Aroutiounov + <karen@ipmce.ru> for reporting this. +
  • +
+ +

1.1.0

+ +
    +
  • New regression test coverage.
  • +
+ + + + diff --git a/contrib/utility/Documentation/ExH/System/DescriptiveException.hpp.html b/contrib/utility/Documentation/ExH/System/DescriptiveException.hpp.html new file mode 100644 index 00000000000..fb6b35d4143 --- /dev/null +++ b/contrib/utility/Documentation/ExH/System/DescriptiveException.hpp.html @@ -0,0 +1,64 @@ + + + + +DescriptiveException.hpp + + +
+// file      : Utility/ExH/System/DescriptiveException.hpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+namespace Utility
+{
+  namespace ExH
+  {
+    namespace System
+    {
+      class DescriptiveException : public virtual Exception
+      {
+      public:
+        explicit
+        DescriptiveException (char const* description) throw ();
+
+        explicit
+        DescriptiveException (std::string const& description) throw ();
+
+        template <typename T>
+        explicit
+        DescriptiveException (T const& description) throw ();
+
+        DescriptiveException (DescriptiveException const& src) throw ();
+
+        virtual
+        ~DescriptiveException () throw ();
+
+        DescriptiveException&
+        operator= (DescriptiveException const& src) throw ();
+
+      protected:
+        DescriptiveException () throw ();
+
+        void
+        init (char const* description) throw ();
+
+      public:
+        virtual char const*
+        what () const throw ();
+
+      private:
+
+        static unsigned long const DESCRIPTION_SIZE = 256;
+
+        char description_ [DESCRIPTION_SIZE];
+      };
+    }
+  }
+}
+
+
+ + + diff --git a/contrib/utility/Documentation/ExH/System/Exception.hpp.html b/contrib/utility/Documentation/ExH/System/Exception.hpp.html new file mode 100644 index 00000000000..60d6bd733f5 --- /dev/null +++ b/contrib/utility/Documentation/ExH/System/Exception.hpp.html @@ -0,0 +1,32 @@ + + + + +Exception.hpp + + +
+// file      : Utility/ExH/System/Exception.hpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+namespace Utility
+{
+  namespace ExH
+  {
+    namespace System
+    {
+      // This is the only way to make predefined exceptions like
+      // std::bad_alloc, etc to appear in the right place of the hierarchy.
+      //
+
+      typedef std::exception Exception;
+    }
+  }
+}
+
+
+ + + diff --git a/contrib/utility/Documentation/ExH/System/Makefile b/contrib/utility/Documentation/ExH/System/Makefile new file mode 100644 index 00000000000..7c7bfbc8e8d --- /dev/null +++ b/contrib/utility/Documentation/ExH/System/Makefile @@ -0,0 +1,20 @@ +# file : Documentation/ExH/System/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Documentation.pre.rules) + +vpath %.hpp $(root)/Utility/ExH/System + +doc_translation_units := Exception.hpp DescriptiveException.hpp + +DOC_FLAGS := --strip-preprocessor -css $(root)/Documentation/Style/CXX.css + +$(call include, $(root)/BuildRules/Documentation.post.rules) + +# $Id$ diff --git a/contrib/utility/Documentation/ExH/index.xhtml b/contrib/utility/Documentation/ExH/index.xhtml new file mode 100644 index 00000000000..c2d40d9fbaa --- /dev/null +++ b/contrib/utility/Documentation/ExH/index.xhtml @@ -0,0 +1,60 @@ + + + + + + + + + Exception Handling Library + + + + + + + + + + + + +

Introduction

+ +

+Exception Handling library was designed to promote consistent usage of +exceptions and exception handling mechanisms throughout the project. +For a quick overview of the basic idea you may want to look at some +examples.

+ +

Examples

+ + + +

Definitions

+ +

Following are the definitions of the main blocks of the model:

+ + + + + + diff --git a/contrib/utility/Documentation/Hetero/News.xhtml b/contrib/utility/Documentation/Hetero/News.xhtml new file mode 100644 index 00000000000..b99645d704d --- /dev/null +++ b/contrib/utility/Documentation/Hetero/News.xhtml @@ -0,0 +1,31 @@ + + + + + + + + + Heterogeneous Container Library News + + + + + + + + + + + + + + + diff --git a/contrib/utility/Documentation/Hetero/index.xhtml b/contrib/utility/Documentation/Hetero/index.xhtml new file mode 100644 index 00000000000..d45a7b6e82d --- /dev/null +++ b/contrib/utility/Documentation/Hetero/index.xhtml @@ -0,0 +1,62 @@ + + + + + + + + + Heterogeneous Container Library + + + + + + + + + + + + +

Introduction

+ +

Have you ever wanted to write something like this:

+ +
+vector v;
+
+v.push_back (10);
+v.push_back (true);
+v.push_back ("hello");
+
+ +

Or maybe even something like this:

+ +
+template <typename T>
+void print (T const& t)
+{
+  cout << t << endl;
+}
+
+for (vector::const_iterator i = v.begin (); i != v.end (); i++)
+{
+  print (*i);
+}
+
+ +

If so then you may be interested in Heterogeneous Container Library. +It is still in active development but you can take a look for some +examples in Example/Hetero directory.

+ + + + diff --git a/contrib/utility/Documentation/Introspection/News.xhtml b/contrib/utility/Documentation/Introspection/News.xhtml new file mode 100644 index 00000000000..257c790766c --- /dev/null +++ b/contrib/utility/Documentation/Introspection/News.xhtml @@ -0,0 +1,38 @@ + + + + + + + + + Introspection Library News + + + + + + + + + + + + +

1.2.2

+
    +
  • + Removed no-throw specification from Introspection::Object::~Object(). +
  • +
+ + + + diff --git a/contrib/utility/Documentation/Introspection/index.xhtml b/contrib/utility/Documentation/Introspection/index.xhtml new file mode 100644 index 00000000000..462b2c87321 --- /dev/null +++ b/contrib/utility/Documentation/Introspection/index.xhtml @@ -0,0 +1,42 @@ + + + + + + + + + Introspection Library + + + + + + + + + + + + +

Introduction

+ +

+Sometimes there is a need to analyze object's type at runtime. ISO C++ +provides some capabilities for this kind of introspection however they +are limited to basic type information. Such information as type +inheritance graph is not accessible in standard C++. Introspection +Library provides a framework that enables discovery of type structure +at runtime. The library is still in development stage but a few meaningful +examples are available in Example/Introspection directory.

+ + + + diff --git a/contrib/utility/Documentation/Makefile b/contrib/utility/Documentation/Makefile new file mode 100644 index 00000000000..6a2caae9002 --- /dev/null +++ b/contrib/utility/Documentation/Makefile @@ -0,0 +1,16 @@ +# file : Documentation/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := .. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := ExH ReferenceCounting Synch + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Documentation/News.xhtml b/contrib/utility/Documentation/News.xhtml new file mode 100644 index 00000000000..b3ea1389e53 --- /dev/null +++ b/contrib/utility/Documentation/News.xhtml @@ -0,0 +1,72 @@ + + + + + + + + + Utility Library News + + + + + + + + + + + + +

Sub-Library News

+ + + +

1.2.2

+
    +
  • Bug fixes in build system.
  • +
+ + +

1.2.1

+
    +
  • + Documentation bug fixes. +
  • +
+ + +

1.2.0

+ + + +

1.1.0

+
    +
  • New directory structure.
  • +
  • New dependency generation mechanism.
  • +
  • Automatic documentation generation (make documentation).
  • +
+ + + + diff --git a/contrib/utility/Documentation/ReferenceCounting/DefaultImpl.hpp.html b/contrib/utility/Documentation/ReferenceCounting/DefaultImpl.hpp.html new file mode 100644 index 00000000000..86edcd70ec2 --- /dev/null +++ b/contrib/utility/Documentation/ReferenceCounting/DefaultImpl.hpp.html @@ -0,0 +1,93 @@ + + + + +DefaultImpl.hpp + + +
+// file      : Utility/ReferenceCounting/DefaultImpl.hpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+namespace Utility
+{
+  namespace ReferenceCounting
+  {
+    // Default reference counter implementation with parameterised
+    // synchronization policy. It is assumed that none of the SynchPolicy
+    // types throw any logic exceptions. If in fact they do then these
+    // exceptions won't be handled and will be automatically converted
+    // to system exceptions.
+
+    template <typename SynchPolicy = Utility::Synch::Policy::Null>
+    class DefaultImpl : public virtual Interface
+    {
+    public:
+      class InconsistentState_ {};
+      typedef
+      ExH::Compound<InconsistentState_, Exception>
+      InconsistentState;
+
+    public:
+      DefaultImpl () throw (SystemException);
+
+      virtual
+      ~DefaultImpl () throw ();
+
+    public:
+      virtual void
+      add_ref () const throw (Exception, SystemException);
+
+      virtual void
+      remove_ref () const throw ();
+
+      virtual count_t
+      refcount_value () const throw (Exception, SystemException);
+
+    protected:
+      virtual void
+      add_ref_i () const throw (Exception, SystemException);
+
+      virtual bool
+      remove_ref_i () const throw (Exception, SystemException);
+
+      virtual count_t
+      refcount_value_i () const throw (Exception, SystemException);
+
+      typename SynchPolicy::Mutex&
+      lock_i () const throw ();
+
+    protected:
+      typedef
+      typename SynchPolicy::Mutex
+      Mutex_;
+
+      typedef
+      typename SynchPolicy::ReadGuard
+      ReadGuard_;
+
+      typedef
+      typename SynchPolicy::WriteGuard
+      WriteGuard_;
+
+    protected:
+      mutable count_t ref_count_;
+
+    private:
+      mutable Mutex_  lock_;
+
+    private:
+      // Copy semanic is not supported.
+      DefaultImpl (DefaultImpl const&) throw ();
+      DefaultImpl&
+      operator= (DefaultImpl const&) throw ();
+    };
+  }
+}
+
+
+ + + diff --git a/contrib/utility/Documentation/ReferenceCounting/Interface.hpp.html b/contrib/utility/Documentation/ReferenceCounting/Interface.hpp.html new file mode 100644 index 00000000000..f81c1dc737c --- /dev/null +++ b/contrib/utility/Documentation/ReferenceCounting/Interface.hpp.html @@ -0,0 +1,82 @@ + + + + +Interface.hpp + + +
+// file      : Utility/ReferenceCounting/Interface.hpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+namespace Utility
+{
+  namespace ReferenceCounting
+  {
+    // Interface to a reference-countable object. Note that _remove_ref ()
+    // member function has a no-throw semantic. Even though it can lead to
+    // a diagnostic loss it was made no-throw because it has a destructor
+    // semantic.
+
+    class Interface
+    {
+    public:
+      typedef
+      unsigned long
+      count_t;
+
+      typedef
+      ExH::System::Exception
+      SystemException;
+
+      class Exception_ {};
+      typedef
+      ExH::Compound<Exception_, ExH::Logic::DescriptiveException>
+      Exception;
+
+    public:
+      virtual void
+      add_ref () const throw (Exception, SystemException) = 0;
+
+      virtual void
+      remove_ref () const throw () = 0;
+
+      virtual count_t
+      refcount_value () const throw (Exception, SystemException) = 0;
+
+    protected:
+      Interface () throw ();
+
+      virtual
+      ~Interface () throw ();
+
+    protected:
+      virtual void
+      add_ref_i () const throw (Exception, SystemException) = 0;
+
+      virtual bool
+      remove_ref_i () const throw (Exception, SystemException) = 0;
+
+      virtual count_t
+      refcount_value_i () const throw (Exception, SystemException) = 0;
+
+    private:
+      // Copy semanic is not supported.
+      Interface (Interface const&) throw ();
+      Interface&
+      operator= (Interface const&) throw ();
+    };
+
+    template <typename Type>
+    Type*
+    add_ref (Type* ptr)
+      throw (Interface::Exception, Interface::SystemException);
+  }
+}
+
+
+ + + diff --git a/contrib/utility/Documentation/ReferenceCounting/Makefile b/contrib/utility/Documentation/ReferenceCounting/Makefile new file mode 100644 index 00000000000..3202f185418 --- /dev/null +++ b/contrib/utility/Documentation/ReferenceCounting/Makefile @@ -0,0 +1,22 @@ +# file : Documentation/ReferenceCounting/Make.doc.mk +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Documentation.pre.rules) + +vpath %.hpp $(root)/Utility/ReferenceCounting + +doc_translation_units := DefaultImpl.hpp \ + Interface.hpp \ + SmartPtr.hpp \ + StrictPtr.hpp + +DOC_FLAGS := --strip-preprocessor -css $(root)/Documentation/Style/CXX.css + +$(call include, $(root)/BuildRules/Documentation.post.rules) +# $Id$ diff --git a/contrib/utility/Documentation/ReferenceCounting/News.xhtml b/contrib/utility/Documentation/ReferenceCounting/News.xhtml new file mode 100644 index 00000000000..472a97e9e66 --- /dev/null +++ b/contrib/utility/Documentation/ReferenceCounting/News.xhtml @@ -0,0 +1,90 @@ + + + + + + + + + Reference Counting Library News + + + + + + + + + + + + +

1.1.0

+ + + + + diff --git a/contrib/utility/Documentation/ReferenceCounting/SmartPtr.hpp.html b/contrib/utility/Documentation/ReferenceCounting/SmartPtr.hpp.html new file mode 100644 index 00000000000..a2ef9342441 --- /dev/null +++ b/contrib/utility/Documentation/ReferenceCounting/SmartPtr.hpp.html @@ -0,0 +1,103 @@ + + + + +SmartPtr.hpp + + +
+// file      : Utility/ReferenceCounting/SmartPtr.hpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+namespace Utility
+{
+  namespace ReferenceCounting
+  {
+    template <typename T>
+    class SmartPtr
+    {
+    public:
+      typedef
+      T
+      Type;
+
+      class NotInitialized_ {};
+      typedef
+      ExH::Compound<NotInitialized_, ExH::Logic::DescriptiveException>
+      NotInitialized;
+
+    public:
+      // c-tor's
+
+      SmartPtr () throw ();
+      SmartPtr (Type* ptr) throw ();
+      SmartPtr (SmartPtr<Type> const& s_ptr)
+        throw (Interface::Exception, Interface::SystemException);
+
+      template <typename Other>
+      SmartPtr (SmartPtr<Other> const& s_ptr)
+        throw (Interface::Exception, Interface::SystemException);
+
+      // d-tor
+
+      ~SmartPtr () throw ();
+
+      // assignment & copy-assignment operators
+
+      SmartPtr<Type>&
+      operator= (Type* ptr) throw ();
+
+      SmartPtr<Type>&
+      operator= (SmartPtr<Type> const& s_ptr)
+        throw (Interface::Exception, Interface::SystemException);
+
+      template <typename Other>
+      SmartPtr<Type>&
+      operator= (SmartPtr<Other> const& s_ptr)
+        throw (Interface::Exception, Interface::SystemException);
+
+      //conversions
+
+      operator Type* () const throw ();
+
+      // accessors
+
+      Type*
+      operator-> () const throw (NotInitialized);
+
+      Type*
+      in () const throw ();
+
+      Type*
+      retn() throw ();
+
+    private:
+      Type* ptr_;
+    };
+
+    // Specialization of add_ref function for SmartPtr<T>
+    template <typename T>
+    T*
+    add_ref (SmartPtr<T> const& ptr)
+      throw (Interface::Exception, Interface::SystemException);
+
+
+    // Dynamic type conversion function for SmartPtr's
+    template <typename D, typename S>
+    D*
+    smart_cast (SmartPtr<S> const& s)
+      throw (Interface::Exception, Interface::SystemException);
+
+    // Acquisition function
+    template <typename T>
+    SmartPtr<T>
+    acquire (T* ptr) throw (Interface::Exception, Interface::SystemException);
+  }
+}
+
+
+ + + diff --git a/contrib/utility/Documentation/ReferenceCounting/StrictPtr.hpp.html b/contrib/utility/Documentation/ReferenceCounting/StrictPtr.hpp.html new file mode 100644 index 00000000000..13211b6e3c7 --- /dev/null +++ b/contrib/utility/Documentation/ReferenceCounting/StrictPtr.hpp.html @@ -0,0 +1,107 @@ + + + + +StrictPtr.hpp + + +
+// file      : Utility/ReferenceCounting/StrictPtr.hpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+namespace Utility
+{
+  namespace ReferenceCounting
+  {
+    template <typename T>
+    class StrictPtr
+    {
+    public:
+      typedef
+      T
+      Type;
+
+      class NotInitialized_ {};
+      typedef
+      ExH::Compound<NotInitialized_, ExH::Logic::DescriptiveException>
+      NotInitialized;
+
+    public:
+      // c-tor's
+
+      StrictPtr () throw ();
+
+      explicit
+      StrictPtr (Type* ptr) throw ();
+
+      StrictPtr (StrictPtr<Type> const& s_ptr)
+        throw (Interface::Exception, Interface::SystemException);
+
+      template <typename Other>
+      StrictPtr (StrictPtr<Other> const& s_ptr)
+        throw (Interface::Exception, Interface::SystemException);
+      // d-tor
+
+      ~StrictPtr () throw ();
+
+      // assignment & copy-assignment operators
+
+      StrictPtr<Type>&
+      operator= (Type* ptr) throw ();
+
+      StrictPtr<Type>&
+      operator= (StrictPtr<Type> const& s_ptr)
+        throw (Interface::Exception, Interface::SystemException);
+
+      template <typename Other>
+      StrictPtr<Type>&
+      operator= (StrictPtr<Other> const& s_ptr)
+        throw (Interface::Exception, Interface::SystemException);
+
+      // conversions
+
+      // Note: implicit conversion (operator Type* ()) is not supported.
+
+      // comparison
+
+      bool
+      operator== (Type* other) const throw ();
+
+      bool
+      operator!= (Type* other) const throw ();
+
+      // accessors
+
+      Type*
+      operator-> () const throw (NotInitialized);
+
+      Type*
+      in () const throw ();
+
+      Type*
+      retn() throw ();
+
+    private:
+      Type* ptr_;
+    };
+
+    // Specialization of add_ref function for StrictPtr<T>
+    template <typename T>
+    T*
+    add_ref (StrictPtr<T> const& ptr)
+      throw (Interface::Exception, Interface::SystemException);
+
+    // Dynamic type conversion function for StrictPtr's
+    template <typename D, typename S>
+    StrictPtr<D>
+    strict_cast (StrictPtr<S> const& s)
+      throw (Interface::Exception, Interface::SystemException);
+  }
+}
+
+
+ + + diff --git a/contrib/utility/Documentation/ReferenceCounting/index.xhtml b/contrib/utility/Documentation/ReferenceCounting/index.xhtml new file mode 100644 index 00000000000..43ead969460 --- /dev/null +++ b/contrib/utility/Documentation/ReferenceCounting/index.xhtml @@ -0,0 +1,50 @@ + + + + + + + + + Reference Counting Library + + + + + + + + + + + + +

Introduction

+ +

Reference Counting Library provides basic building blocks for +reference-countable objects. Implementation is modeled after CORBA +IDL-to-C++ mapping's reference-countable objects and significantly +extended.

+ + +

Definitions

+ +

Below are the definitions of the key classes:

+ + + + + + diff --git a/contrib/utility/Documentation/ReleaseProcess b/contrib/utility/Documentation/ReleaseProcess new file mode 100644 index 00000000000..9b42a762902 --- /dev/null +++ b/contrib/utility/Documentation/ReleaseProcess @@ -0,0 +1,13 @@ +1) go thru '@@' in source code + +2) build & test with g++ and cxx + +3) update news pages + +4) spellcheck/tidy/validate all xhtml files + +5) copy Utility to Utility-x.y.z; make documentation + +6) go manually thru all documentation pages with lynx & gui ua + +$Id$ diff --git a/contrib/utility/Documentation/Style/CXX.css b/contrib/utility/Documentation/Style/CXX.css new file mode 100644 index 00000000000..49bf0f34e51 --- /dev/null +++ b/contrib/utility/Documentation/Style/CXX.css @@ -0,0 +1,9 @@ +pre { BORDER-RIGHT: gray 1pt solid; PADDING-RIGHT: 2pt; BORDER-TOP: gray 1pt solid; DISPLAY: block; PADDING-LEFT: 2pt; PADDING-BOTTOM: 2pt; MARGIN-LEFT: 32pt; BORDER-LEFT: gray 1pt solid; MARGIN-RIGHT: 32pt; PADDING-TOP: 2pt; BORDER-BOTTOM: gray 1pt solid; FONT-FAMILY: "Courier New", Courier, mono; background-color: #EEEEEE; font-size: small} +.keyword { color: #000099} +.identifier { } +.comment { color: #990000} +.special { color: #800040} +.preprocessor { color: #006600} +.string { color: #666666} +.number { color: #666666} +/* $Id$ */ diff --git a/contrib/utility/Documentation/Style/CXX_Blue.css b/contrib/utility/Documentation/Style/CXX_Blue.css new file mode 100644 index 00000000000..52b58d54119 --- /dev/null +++ b/contrib/utility/Documentation/Style/CXX_Blue.css @@ -0,0 +1,25 @@ +pre { + BORDER-RIGHT: gray 1pt solid; + PADDING-RIGHT: 2pt; + BORDER-TOP: gray 1pt solid; + DISPLAY: block; + PADDING-LEFT: 2pt; + PADDING-BOTTOM: 2pt; + MARGIN-LEFT: 32pt; + BORDER-LEFT: gray 1pt solid; + MARGIN-RIGHT: 32pt; + PADDING-TOP: 2pt; + BORDER-BOTTOM: gray 1pt solid; + FONT-FAMILY: "Courier New", Courier, mono; background-color: #191970; + font-size: small +} + +.keyword { font-weight: bold; color: #afeeee} +.identifier { color: #98fb98 } +.comment { color: #add8e6} +.special { color: #bebebe} +.preprocessor { color: #7fffd4} +.string { color: #87cefa} +.number { color: #bebebe} +.literal { color: #FF0000} +/* $Id$ */ diff --git a/contrib/utility/Documentation/Style/Default.css b/contrib/utility/Documentation/Style/Default.css new file mode 100644 index 00000000000..2c90197f340 --- /dev/null +++ b/contrib/utility/Documentation/Style/Default.css @@ -0,0 +1,45 @@ +body { + font-family : sans-serif; + + color : black; + background : white; + + max-width : 40em; + padding : 2em 2em 2em 3em; + margin : 0; +} + +h1, h2, h3, h4, h5, h6 { + font-family : sans-serif; + font-weight : 500; +} + +h1 { font-size : 170%; } +h2 { font-size : 145%; } +h3 { font-size : 125%; } +h4 { font-size : 110%; } +h5 { font-size : 106%; } +h6 { font-size : 100%; } + +p.indent { + margin-left : 1.5em; +} + +/* list of links */ + +ul.menu { + list-style-type : none; +} + +ul.menu li { + padding-top : 0.3em; + padding-bottom : 0.3em; +} + +/* */ + +ul.multiline li { + padding-top : 0.4em; + padding-bottom : 0.4em; +} +/* $Id$ */ diff --git a/contrib/utility/Documentation/Synch/Makefile b/contrib/utility/Documentation/Synch/Makefile new file mode 100644 index 00000000000..a35e28b530d --- /dev/null +++ b/contrib/utility/Documentation/Synch/Makefile @@ -0,0 +1,16 @@ +# file : Documentation/Synch/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := Policy + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Documentation/Synch/News.xhtml b/contrib/utility/Documentation/Synch/News.xhtml new file mode 100644 index 00000000000..f7bf4f01285 --- /dev/null +++ b/contrib/utility/Documentation/Synch/News.xhtml @@ -0,0 +1,36 @@ + + + + + + + + + Synchronization Library News + + + + + + + + + + + + +

1.1.0

+
    +
  • New regression test coverage.
  • +
+ + + + diff --git a/contrib/utility/Documentation/Synch/Policy/Makefile b/contrib/utility/Documentation/Synch/Policy/Makefile new file mode 100644 index 00000000000..175d207b06e --- /dev/null +++ b/contrib/utility/Documentation/Synch/Policy/Makefile @@ -0,0 +1,20 @@ +# file : Documentation/Synch/Policy/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Documentation.pre.rules) + +vpath %.hpp $(root)/Utility/Synch/Policy + +doc_translation_units := Null.hpp + +DOC_FLAGS := --strip-preprocessor -css $(root)/Documentation/Style/CXX.css + +$(call include, $(root)/BuildRules/Documentation.post.rules) + +# $Id$ diff --git a/contrib/utility/Documentation/Synch/Policy/Null.hpp.html b/contrib/utility/Documentation/Synch/Policy/Null.hpp.html new file mode 100644 index 00000000000..21173a5951b --- /dev/null +++ b/contrib/utility/Documentation/Synch/Policy/Null.hpp.html @@ -0,0 +1,59 @@ + + + + +Null.hpp + + +
+// file      : Utility/Synch/Policy/Null.hpp
+// author    : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license   : http://kolpackov.net/license.html
+
+namespace Utility
+{
+  namespace Synch
+  {
+    namespace Policy
+    {
+
+      class NullMutex
+      {
+      };
+
+      class NullGuard
+      {
+      public:
+        explicit
+        NullGuard (NullMutex&) throw ();
+
+      private:
+        NullGuard (NullGuard const&) throw ();
+
+        NullGuard&
+        operator= (NullGuard const&) throw ();
+      };
+
+      struct Null
+      {
+        typedef
+        NullMutex
+        Mutex;
+
+        typedef
+        NullGuard
+        ReadGuard;
+
+        typedef
+        NullGuard
+        WriteGuard;
+      };
+    }
+  }
+}
+
+
+ + + diff --git a/contrib/utility/Documentation/Synch/index.xhtml b/contrib/utility/Documentation/Synch/index.xhtml new file mode 100644 index 00000000000..dd4a685ccc0 --- /dev/null +++ b/contrib/utility/Documentation/Synch/index.xhtml @@ -0,0 +1,48 @@ + + + + + + + + + Synchronization Library + + + + + + + + + + + + +

Introduction

+ +

+Synchronization library provides a compile-time policy-based configurable +facility of selecting synchronization mechanisms. For now there is only +no-op synchronization policy provided which is suitable only for +single-threaded applications. However it shouldn't be difficult to provide +a wrapper policy for synchronization mechanisms used in a particular project. +

+ +

Definitions

+

Below are the definitions of the key classes:

+ + + + + + diff --git a/contrib/utility/Documentation/TODO b/contrib/utility/Documentation/TODO new file mode 100644 index 00000000000..984a0cddb56 --- /dev/null +++ b/contrib/utility/Documentation/TODO @@ -0,0 +1,53 @@ + +New features/changes +--------------------------------------------------------------------------- + +@@ DefaultImpl<> looks ugly. Is there a way to just write DefaultImpl + (or, perhaps some other name)? Maybe also rename Interface to Object + (will be consistent with Introspection::Object). + +@@ Abort facility + +@@ Maybe rename converter to convert + +@@ Maybe make reference counting object implement Introspection. However it + will introduce inter-library dependency. Nop, this is a bad idea. + +@@ Maybe move .hpp one level up to Utility/. + +@@ Go thru C++Templates chapter on RefCounting and SmartPointers and see if + anything can be applied? + +@@ Examples for many features are missing + +@@ Introspection::TypeInfo should use set instead of vector for bases. + + +Documentation +--------------------------------------------------------------------------- + +@@ code in
 does not look nice in lynx (see Hetero/index.html for example)
+
+
+Building environment
+---------------------------------------------------------------------------
+
+@@ Should probably make lib rules to build library when target is test (try to
+   run 'make clean && make test' from Utility root).
+
+@@ Makefile variable names inconsistency (e.g. cxx_translation_units and CXX_PREPROCESS_FLAGS)
+
+%% Rename Config to Build or rather BuildRules?
+
+@@ Compiler-specific stuff is left after make clean. Potentially dangerous 
+   idea would be to remove everything except known files
+
+@@ Multi-compiler configuration
+
+@@ Building library with sources in sub-directories.
+
+
+Pre-release fixes
+---------------------------------------------------------------------------
+
+$Id$
diff --git a/contrib/utility/Documentation/Template.xhtml b/contrib/utility/Documentation/Template.xhtml
new file mode 100644
index 00000000000..41c9857dabf
--- /dev/null
+++ b/contrib/utility/Documentation/Template.xhtml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+  @@
+
+  
+  
+  
+  
+
+  
+
+
+
+
+
+

@@

+ + + + diff --git a/contrib/utility/Documentation/Thoughts/Enum/EnumCount b/contrib/utility/Documentation/Thoughts/Enum/EnumCount new file mode 100644 index 00000000000..be8b252d4de --- /dev/null +++ b/contrib/utility/Documentation/Thoughts/Enum/EnumCount @@ -0,0 +1,95 @@ +From: Gianni Mariani +Date: 26 Jul 2003 04:52:43 GMT +Newsgroups: comp.lang.c++ +Subject: Re: enum count + +Clive wrote: +> If you have an enum, is there any way during execution to find the number of +> values in the enum? +> Say I have, +> +> enum great { five, ten, fifteen }; +> +> How could I get the number 3 from that? +> +> + +replace the enums with objects that report themselves to a registry. + + +I have done it in the past using a template ... + +templace +class ExposedEnum : public base +{ + public: + int enum_val; + ExposedEnum( int number ) + : enum_val( number ) + { + ExposedEnumRegister::Register( *this ); + } + + ExposedEnum( int number ) + : enum_val( ExposedEnumRegister::GetNextNumber() ) + { + ExposedEnumRegister::Register( *this ); + } + + + +// some more stuff ... + + operator int () const + { + return enum_val; + } + + explicit ExposedEnum( const ExposedEnum & foo ); +}; + + +template +class ExposedEnumRegister +{ + + static int GetNextNumber .... + + static void Register .... + + static int Count .... + +} + + +Now you can forward declare them... + +extern ExposedEnum< great > five; + +extern ExposedEnum< great > ten; + +extern ExposedEnum< great > fifteen; + + + + +In a cpp file you can instantiate them. + +ExposedEnum< great > five( 5 ); + +ExposedEnum< great > ten( 10 ); + +ExposedEnum< great > fifteen; + + +Now, if you want to know how many you have : + +ExposedEnumRegister< great >::Count(); + + + +Disclaimer - it's an outline only, yes it's incomplete. + +G + +$Id$ diff --git a/contrib/utility/Documentation/Thoughts/Enum/EnumCount2 b/contrib/utility/Documentation/Thoughts/Enum/EnumCount2 new file mode 100644 index 00000000000..d23e790b6d4 --- /dev/null +++ b/contrib/utility/Documentation/Thoughts/Enum/EnumCount2 @@ -0,0 +1,17 @@ +From: Alexander Terekhov +Date: Sat, 26 Jul 2003 19:17:52 +0200 +Newsgroups: comp.lang.c++ +Subject: Re: enum count + + +Steve Pinard wrote: +> +> Wouldn't that be nice? And wouldn't it be nice to be able to get the +> strings "five", "ten", and "fifteen" too? + +http://lcgapp.cern.ch/project/architecture/XTI_accu.pdf + +regards, +alexander. + +$Id$ diff --git a/contrib/utility/Documentation/Thoughts/Enum/EnumInfo b/contrib/utility/Documentation/Thoughts/Enum/EnumInfo new file mode 100644 index 00000000000..e59a27c0820 --- /dev/null +++ b/contrib/utility/Documentation/Thoughts/Enum/EnumInfo @@ -0,0 +1,45 @@ +From: "Klaus Eichner" +Date: Sat, 26 Jul 2003 14:53:23 +0100 +Newsgroups: comp.lang.c++ +Subject: Re: enum count + +"Clive" wrote in message +news:3f21e5cc$0$23611$5a62ac22@freenews.iinet.net.au... +> If you have an enum, is there any way during execution to find the number +of +> values in the enum? +> Say I have, +> +> enum great { five, ten, fifteen }; +> +> How could I get the number 3 from that? + +You could get the number 3 from 'great' with your own, user-defined +'Enum_Info' template: + +cout << "The number of values in enum great is " + << Enum_Info::number_of_elements + << endl; + +The 'Enum_Info' template is defined as follows. +Suppose you have the following enums: + +enum great { five, ten, fifteen }; +enum greater { none, one, fourtytwo, fourtythree, fourtyfour }; +enum even_greater { minusone, minustwo, minusthree, minusfour, minusfive, +minussix, minusseven }; + +You could build a template class 'Enum_Info' which uses specialisation to +register the number of elements in each enum + +template class Enum_Info { }; +template <> class Enum_Info { static const int number_of_elements = +3; }; +template <> class Enum_Info { static const int number_of_elements = +5; }; +template <> class Enum_Info { static const int +number_of_elements = 7; }; + + + +$Id$ diff --git a/contrib/utility/Documentation/index.xhtml b/contrib/utility/Documentation/index.xhtml new file mode 100644 index 00000000000..87e82d228dc --- /dev/null +++ b/contrib/utility/Documentation/index.xhtml @@ -0,0 +1,81 @@ + + + + + + + + + Utility Library + + + + + + + + + + + + +

Introduction

+

+Utility library is a place for generic C++ facilities that I found useful +in more than one project. + +Here you can download the + +latest version. + +Utility library is a + +non-copylefted free software with zlib-like +license. + +For changes and new features check out News section. +

+ +

Supported Platforms

+ +

+For the time being I test Utility library with at least GNU G++ on Linux and +Compaq (Digital) C++ (-std strict_ansi) on Tru64 UNIX. It also should compile +and work fine with any decent C++ compiler. Also note that I don't have any +plans to bloat source code in attempt to support broken compilers.

+ +

Building

+ +

+Utility library mostly consists of header-only sub-libraries so you don't +actually need to build anything to start using it. See +Building Utility Library section for more information.

+ +

Content

+ +

Utility Library consists of the following sub-libraries:

+ + + + + + diff --git a/contrib/utility/Example/CommandLine/Foo/command.cpp b/contrib/utility/Example/CommandLine/Foo/command.cpp new file mode 100644 index 00000000000..50b78a15350 --- /dev/null +++ b/contrib/utility/Example/CommandLine/Foo/command.cpp @@ -0,0 +1,86 @@ +#include +#include + +using std::cerr; +using std::endl; + +class Command +{ +public: + enum Value + { + HELP = 0, + VERSION, + DEFAULT + }; + + Command (Value v = Command::DEFAULT) + : v_ (v) + { + } + + operator Value () const + { + return v_; + } + + friend std::ostream& + operator<< (std::ostream& os, Command c); + + friend std::istream& + operator>> (std::istream& is, Command& c); + +private: + Value v_; + static char* labels_[]; +}; + +char* Command::labels_[] = {"help", "version", "default"}; + + +std::ostream& +operator<< (std::ostream& os, Command c) +{ + return os << Command::labels_[c.v_]; +} + +std::istream& +operator>> (std::istream& is, Command& c) +{ + std::string s; + is >> s; + if (is) + { + if (s == Command::labels_[Command::HELP]) c.v_ = Command::HELP; + else if (s == Command::labels_[Command::VERSION]) c.v_ = Command::VERSION; + else is.setstate (std::ios::failbit); + } + return is; +} + +int +main () +{ + Command c = Command::HELP; + + c = Command::DEFAULT; + + Command c1 (Command::HELP); + + c = c1; + + cerr << c << endl; + + switch (c) + { + case Command::HELP: + { + cerr << "iiihuuu!!!" << endl; + } + } + + std::cin >> c1; + if (std::cin) cerr << c1 << endl; + else cerr << "*failed" << endl; +} +//$Id$ diff --git a/contrib/utility/Example/CommandLine/Foo/foo.cpp b/contrib/utility/Example/CommandLine/Foo/foo.cpp new file mode 100644 index 00000000000..a389f8d822a --- /dev/null +++ b/contrib/utility/Example/CommandLine/Foo/foo.cpp @@ -0,0 +1,183 @@ +#include +#include +#include + + +namespace CommandLine +{ + struct Parser + { + }; +} + +using std::string; +using std::cerr; +using std::endl; + +using namespace CommandLine; + +class Command +{ +public: + enum Value + { + HELP, + VERSION, + DEFAULT + }; + + Command (Value v = Command::DEFAULT) + : v_ (v) + { + } + + operator Value () const + { + return v_; + } + +private: + Value v_; +}; + + +int +version (); + +int +help (int argc, char* argv[]); + +int +main (int argc, char* argv[]) +{ + + // Step 1: determine command + // + // * there is usually one command + // * command can be optional + // * command usually takes up one argument + // + + CommandParser cp; + + switch (cp.parse (argc, argv)) + { + case Command::VERSION: + { + return version (); + } + case Command::HELP: + { + return help (argc, argv); + } + } + + // Step 2: parse options + // + // * options are usually optional + // * options are usually position-independant + // * options usually do not repeat + // * options can take up more than one argument + // + + OptionMap om; + + CompositeParser op; + + op.add (OptionParser ("string", "--string", "-s")); + op.add (OptionParser ("number", "--number", "-n")); + + while (argc != 1 && !op.empty ()) + { + om.insert (op.parse (argc, argv)); + } + + // Step 3: parse operands + // + // * operands usually position-dependant + // * operand usually take up one argument + // + + OperandParser odp; + + string str = odp.parse (argc, argv); + + unsigned long num = 0; + + if (argc != 1) + { + OperandParser op; + num = op.parse (argc, argv); + } + + string s = om.count ("string") ? om["string"] : "default"; + unsigned long l = om["number"]; + + // om.at () + // om.get () + // om.resolve () + // om.option () + // om.value () + + cerr << "opreation settings are:" << endl << endl + << "option string : " << om.get ("string", "default") << endl + << "option number : " << om.get ("number", 10UL) << endl + << "operand string : " << str << endl + << "operand number : " << num << endl; +} + + +// +// +// +int +version () +{ + cerr << "foo 1.0" << endl; + return 0; +} + + +// +// +// +int +help (int argc, char* argv[]) +{ + Command subject; + + if (argc != 1) + { + OperandParser op; + subject = op.parse (argc, argv); + } + + switch (subject) + { + case Command::HELP: + { + cerr << "foo help []" << endl << endl + << "\t If is specified then print extended help" << endl + << "\t information for specified command. Otherwise print" << endl + << "\t general usage information." << endl; + break; + } + case Command::VERSION: + { + cerr << "foo version" << endl << endl + << "\t Print version information." << endl; + break; + } + default: + { + cerr << "foo version" << endl + << "foo help []" << endl + << "foo [-s|--string ] [-n|--number ] []" + << endl; + break; + } + } + + return 0; +} +//$Id$ diff --git a/contrib/utility/Example/ExH/BadCast/Makefile b/contrib/utility/Example/ExH/BadCast/Makefile new file mode 100644 index 00000000000..9963d9708a1 --- /dev/null +++ b/contrib/utility/Example/ExH/BadCast/Makefile @@ -0,0 +1,24 @@ +# file : Example/ExH/BadCast/Makefile +# author : Boris Kolpackov +# 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 := bad_cast.cpp + +module_base := bad_cast +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Example/ExH/BadCast/bad_cast.cpp b/contrib/utility/Example/ExH/BadCast/bad_cast.cpp new file mode 100644 index 00000000000..cb4a59e26a9 --- /dev/null +++ b/contrib/utility/Example/ExH/BadCast/bad_cast.cpp @@ -0,0 +1,52 @@ +// file : Example/ExH/BadCast/bad_cast.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/System/Exception.hpp" + +#include + +using std::cerr; +using std::endl; + + +struct A +{ + virtual + ~A() {} +}; + +struct B +{ + void + foo () {} +}; + +void +foo () throw (Utility::ExH::System::Exception) +{ + A a; + + A& ar (a); + + B& br (dynamic_cast (ar)); + + br.foo (); +} + +int +main () +{ + try + { + foo (); + } + catch (Utility::ExH::System::Exception const& ex) + { + cerr << "Caught Utility::ExH::System::Exception: " + << ex.what () + << endl; + } +} +//$Id$ diff --git a/contrib/utility/Example/ExH/Compound/Makefile b/contrib/utility/Example/ExH/Compound/Makefile new file mode 100644 index 00000000000..8bd588587d5 --- /dev/null +++ b/contrib/utility/Example/ExH/Compound/Makefile @@ -0,0 +1,24 @@ +# file : Example/ExH/Compound/Makefile +# author : Boris Kolpackov +# 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 := compound.cpp + +module_base := compound +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Example/ExH/Compound/compound.cpp b/contrib/utility/Example/ExH/Compound/compound.cpp new file mode 100644 index 00000000000..9e042ca9c1e --- /dev/null +++ b/contrib/utility/Example/ExH/Compound/compound.cpp @@ -0,0 +1,142 @@ +// file : Example/ExH/Compound/compound.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/Compound.hpp" +#include "Utility/ExH/System/Exception.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +// Include some helper converters to allow exception initialization +// with std::ostringstream + +#include "Utility/ExH/StringStreamConverter.hpp" + +#include + +using std::cerr; +using std::endl; +using std::string; +using std::ostringstream; + +using namespace Utility::ExH; + +// Here are our components + +class Base +{ +public: + + // + // Exception definitions. + // + + // Base logic exception class for component. + class Exception_ {}; + typedef + Compound + Exception; + + class InvalidArgument_ {}; + typedef + Compound + InvalidArgument; + + class NotInitialized_ {}; + typedef + Compound + NotInitialized; + +public: + + void + foo (char const* str) throw (InvalidArgument, NotInitialized) + { + // This is just an example. + + if (str == 0) + { + throw InvalidArgument ("Base::foo: first parameter is zero."); + } + else + { + ostringstream ostr; + ostr << "Base::foo [this = " << this << "]: object is not initialized."; + + throw NotInitialized (ostr); + } + } + + + // We don't know what implementation may decide to throw so + // we allow to throw System exception and any logic exception + // derived from Base::Exception + virtual void + vfoo () throw (Exception, System::Exception) = 0; +}; + +class Derived : public Base +{ +public: + + // Define some Derived-specific logic exception. + class NotImplemented_ {}; + typedef + Compound + NotImplemented; + +public: + virtual void + vfoo () throw (NotImplemented, System::Exception) + { + std::string str ("Derived::vfoo: not implemented yet."); + throw NotImplemented (str); + } +}; + +int +main () +{ + try + { + + Derived d; + Base* pb (&d); + + // We can use generic handler. + try + { + pb->vfoo (); + } + catch (Base::Exception const& ex) + { + cerr << "Caught Base::Exception: " << ex.what () << endl; + } + + + // Or use more precise control. + try + { + pb->foo ("hello"); + } + catch (Base::NotInitialized const& ex) + { + cerr << "Caught Base::NotInitialized: " << ex.what () << endl; + } + + // Or use application-level handler. + pb->foo (0); + + } + catch (Logic::Exception const& ex) + { + cerr << "Caught Logic::Exception: " << ex.what () << endl; + } + catch (...) + { + cerr << "Caught unknown exception using catch-all handler" << endl; + return -1; + } + +} +//$Id$ diff --git a/contrib/utility/Example/ExH/HelloWorld/Makefile b/contrib/utility/Example/ExH/HelloWorld/Makefile new file mode 100644 index 00000000000..93debef0e7c --- /dev/null +++ b/contrib/utility/Example/ExH/HelloWorld/Makefile @@ -0,0 +1,24 @@ +# file : Example/ExH/HelloWorld/Makefile +# author : Boris Kolpackov +# 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 := hello_world.cpp + +module_base := hello_world +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Example/ExH/HelloWorld/hello_world.cpp b/contrib/utility/Example/ExH/HelloWorld/hello_world.cpp new file mode 100644 index 00000000000..ee678ffa66f --- /dev/null +++ b/contrib/utility/Example/ExH/HelloWorld/hello_world.cpp @@ -0,0 +1,141 @@ +// file : Example/ExH/HelloWorld/hello_world.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include // for std::abort () + +#include +#include + +#include "Utility/ExH/System/Exception.hpp" +#include "Utility/ExH/Logic/Exception.hpp" + +using std::cerr; +using std::cout; +using std::endl; + +using namespace Utility; + +class Application +{ +public: + class Exception : public ExH::Logic::Exception {}; + + // Hint: you may want to try again... + class FeelingDizzy : public Exception {}; + + class InvalidArg : public Exception {}; + +public: + Application () throw (ExH::System::Exception) + : // The std::string c-tor may throw any kind of exceptions besides + // quite possible std::bad_alloc. + greeting_ ("Hello, world!") + { + } + + Application (char const * greeting) throw (InvalidArg, + ExH::System::Exception) + : greeting_ (greeting == 0 ? "" : greeting) + { + if (greeting == 0) throw InvalidArg (); + } + +public: + + void + run () throw (FeelingDizzy, ExH::System::Exception) + { + static unsigned int dizzy_count (0); + + if (dizzy_count++ < 5) throw FeelingDizzy (); + + // The next line can throw full bucket of exceptions + // not to mention ios_base::failure. + cout << greeting_.c_str () << endl; + } + +private: + + std::string greeting_; +}; + + + +int +main () +{ + // This is a catch-all layer that should be in use only + // if we are really in trouble. + try + { + // This is a catch-system layer. Here we will catch exceptions like + // bad_alloc, etc. If we get here it means that nobody wanted/managed + // to recover from this kind of errors. + try + { + // This is a catch-logic layer. If we get here it usually + // indicates an application logic error. + try + { + + // Ok, here we go about our application logic. + try + { + for (int i = 0; i < 10; i++) + { + try + { + Application app ("Hi dude!"); + app.run (); + break; + } + catch (Application::FeelingDizzy const& ) + { + if (i == 9) + { + cerr << "Given up!" << endl; + return -1; + } + else + { + cerr << "Application is feeling dizzy. Trying again..." + << endl; + } + } + } + } + catch (Application::InvalidArg const& ) + { + cerr << "Cought Application::InvalidArg : ...hmm... strange!" + << endl; + return -1; + } + } + catch (ExH::Logic::Exception const& e) + { + cerr << "Caught Logic::Exception : " << e.what () << endl; + return -1; + } + } + catch (const ExH::System::Exception& e) + { + cerr << "Caught System::Exception : " << e.what () << endl; + return -1; + } + catch (...) + { + cerr << "Caught unknown exception using catch-all handler. " << endl; + return -1; + } + } + catch (...) + { + // We get here in cases of some hard failure. For example when handling + // exception, operator << throws another exception. Usually application + // cannot handle such failures itself so we just propagate it futher. + std::abort (); + } +} +//$Id$ diff --git a/contrib/utility/Example/ExH/LogicToSystem/Makefile b/contrib/utility/Example/ExH/LogicToSystem/Makefile new file mode 100644 index 00000000000..789413c0a3c --- /dev/null +++ b/contrib/utility/Example/ExH/LogicToSystem/Makefile @@ -0,0 +1,24 @@ +# file : Example/ExH/LogicToSystem/Makefile +# author : Boris Kolpackov +# 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 := logic_to_system.cpp + +module_base := logic_to_system +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Example/ExH/LogicToSystem/logic_to_system.cpp b/contrib/utility/Example/ExH/LogicToSystem/logic_to_system.cpp new file mode 100644 index 00000000000..ba5944404f0 --- /dev/null +++ b/contrib/utility/Example/ExH/LogicToSystem/logic_to_system.cpp @@ -0,0 +1,58 @@ +// file : Example/ExH/LogicToSystem/logic_to_system.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/System/Exception.hpp" +#include "Utility/ExH/Logic/Exception.hpp" + +#include + +using std::cerr; +using std::endl; + + +struct SubsystemA +{ + class Exception : public Utility::ExH::Logic::Exception {}; + + void + foo () throw (Exception) + { + throw Exception (); + } +}; + + +struct SubsystemB +{ + void + foo () throw (Utility::ExH::System::Exception) + { + SubsystemA a; + a.foo (); + + // Here SubsystemB is using SunsystemA but cannot (forgot, doesnt't + // want to, doesn't know how to, etc - pick your favorite) handle + // exception thrown by SubsystemA. As a result exception is + // 'converted' to System::Exception. + } +}; + + +int +main () +{ + try + { + SubsystemB b; + b.foo (); + } + catch (Utility::ExH::System::Exception const& ex) + { + cerr << "Caught Utility::ExH::System::Exception: " + << ex.what () + << endl; + } +} +//$Id$ diff --git a/contrib/utility/Example/ExH/Makefile b/contrib/utility/Example/ExH/Makefile new file mode 100644 index 00000000000..99eb95cf62f --- /dev/null +++ b/contrib/utility/Example/ExH/Makefile @@ -0,0 +1,16 @@ +# file : Example/ExH/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := BadCast Compound HelloWorld LogicToSystem + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Example/Hetero/Container/Makefile b/contrib/utility/Example/Hetero/Container/Makefile new file mode 100644 index 00000000000..29135f54046 --- /dev/null +++ b/contrib/utility/Example/Hetero/Container/Makefile @@ -0,0 +1,24 @@ +# file : Example/Hetero/Container/Makefile +# author : Boris Kolpackov +# 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 := container.cpp + +module_base := container +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Example/Hetero/Container/container.cpp b/contrib/utility/Example/Hetero/Container/container.cpp new file mode 100644 index 00000000000..f6ba5560dda --- /dev/null +++ b/contrib/utility/Example/Hetero/Container/container.cpp @@ -0,0 +1,110 @@ +// file : Example/Hetero/Container/container.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/Hetero/Container.hpp" +#include "Utility/Hetero/TypedContainer.hpp" +#include "Utility/Hetero/Vector.hpp" +#include "Utility/Hetero/Shell.hpp" + +#include +#include +#include + +using std::string; + +using std::cout; +using std::cerr; +using std::endl; + +namespace Hetero = Utility::Hetero; + +using Hetero::Container; +using Hetero::TypedContainer; +using Hetero::TypeList; +using Hetero::Shell; + + +struct PrintCore +{ + typedef void RetType; + + template + void + operator() (T const& t) + { + cout << t << endl; + } +}; + +typedef Shell Print; + +void +print (bool b) +{ + cout << (b ? "T" : "NIL") << endl; +} + +int +main () +{ + try + { + Container a (10L); + Container b (true); + Container c (string ("hello")); + + string s = c + string (" world"); + + long l = a + 20L; + + cout << s << "; " << l << endl; + + print (b); + + // + // + // + + typedef + TypedContainer > + MyContainer; + + MyContainer x (true); + MyContainer y (10L); + MyContainer z (string ("hey dude")); + + Print print; + + print (x); + print (y); + print (z); + + // + // + // + + typedef + Hetero::Vector + vector; + + vector v; + v.push_back (10L); + v.push_back (true); + v.push_back (false); + v.push_back (string ("hey")); + + for (vector::iterator i = v.begin (); i != v.end (); i++) + { + print (*i); + } + + std::for_each (v.begin (), v.end (), print); + } + catch (Hetero::Typing const&) + { + cerr << "typing error" << endl; + } +} +//$Id$ diff --git a/contrib/utility/Example/Hetero/Makefile b/contrib/utility/Example/Hetero/Makefile new file mode 100644 index 00000000000..a55938e9502 --- /dev/null +++ b/contrib/utility/Example/Hetero/Makefile @@ -0,0 +1,16 @@ +# file : Example/Hetero/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := Container + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.cpp b/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.cpp new file mode 100644 index 00000000000..0dbc616483e --- /dev/null +++ b/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.cpp @@ -0,0 +1,104 @@ +// file : Hierarchy.cpp +// author : Boris Kolpackov +// 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/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.hpp b/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.hpp new file mode 100644 index 00000000000..213e0593f6b --- /dev/null +++ b/contrib/utility/Example/Introspection/InheritanceTree/Hierarchy.hpp @@ -0,0 +1,61 @@ +// file : Example/Introspection/InheritanceTree/Hierarchy.hpp +// author : Boris Kolpackov +// 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/contrib/utility/Example/Introspection/InheritanceTree/Makefile b/contrib/utility/Example/Introspection/InheritanceTree/Makefile new file mode 100644 index 00000000000..9b839c2111f --- /dev/null +++ b/contrib/utility/Example/Introspection/InheritanceTree/Makefile @@ -0,0 +1,22 @@ +# file : Example/Introspection/InheritanceTree/Makefile +# author : Boris Kolpackov +# 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/contrib/utility/Example/Introspection/InheritanceTree/inheritance_tree.cpp b/contrib/utility/Example/Introspection/InheritanceTree/inheritance_tree.cpp new file mode 100644 index 00000000000..97c4c68dda6 --- /dev/null +++ b/contrib/utility/Example/Introspection/InheritanceTree/inheritance_tree.cpp @@ -0,0 +1,64 @@ +// file : Example/Introspection/InheritanceTree/inheritance_tree.cpp +// author : Boris Kolpackov +// 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 ;-). +// + +#include "Hierarchy.hpp" + +#include +#include + +using std::endl; + +typedef +std::set +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$ diff --git a/contrib/utility/Example/Introspection/Makefile b/contrib/utility/Example/Introspection/Makefile new file mode 100644 index 00000000000..2dc0a1f809e --- /dev/null +++ b/contrib/utility/Example/Introspection/Makefile @@ -0,0 +1,16 @@ +# file : Example/Introspection/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := InheritanceTree Traversal + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Example/Introspection/Traversal/Makefile b/contrib/utility/Example/Introspection/Traversal/Makefile new file mode 100644 index 00000000000..c9b1a8da46a --- /dev/null +++ b/contrib/utility/Example/Introspection/Traversal/Makefile @@ -0,0 +1,22 @@ +# file : Example/Introspection/Traversal/Makefile +# author : Boris Kolpackov +# 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 := SyntaxTree.cpp Traversal.cpp driver.cpp + +module_base := driver + +CXX_PREPROCESS_FLAGS += -I $(root) + +CXX_LINK_LIBS += -L$(root)/Utility/Introspection -lIntrospection + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Example/Introspection/Traversal/SyntaxTree.cpp b/contrib/utility/Example/Introspection/Traversal/SyntaxTree.cpp new file mode 100644 index 00000000000..71115ff2b24 --- /dev/null +++ b/contrib/utility/Example/Introspection/Traversal/SyntaxTree.cpp @@ -0,0 +1,119 @@ +// file : Example/Introspection/Traversal/SyntaxTree.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "SyntaxTree.hpp" + +using namespace Utility::Introspection; + +namespace SyntaxTree +{ + + // Node + // + // + + namespace + { + TypeInfo + node_init_ () + { + TypeInfo ti (typeid (Node)); + ti.add_base (Access::PUBLIC, true, Object::static_type_info ()); + return ti; + } + + TypeInfo node_ (node_init_ ()); + } + + TypeInfo const& Node:: + static_type_info () { return node_; } + + + // Declaration + // + // + + namespace + { + TypeInfo + declaration_init_ () + { + TypeInfo ti (typeid (Declaration)); + ti.add_base (Access::PUBLIC, true, Node::static_type_info ()); + return ti; + } + + TypeInfo declaration_ (declaration_init_ ()); + } + + TypeInfo const& Declaration:: + static_type_info () { return declaration_; } + + + // Scope + // + // + + namespace + { + TypeInfo + scope_init_ () + { + TypeInfo ti (typeid (Scope)); + ti.add_base (Access::PUBLIC, true, Declaration::static_type_info ()); + return ti; + } + + TypeInfo scope_ (scope_init_ ()); + } + + TypeInfo const& Scope:: + static_type_info () { return scope_; } + + + // InterfaceDecl + // + // + + namespace + { + TypeInfo + interface_decl_init_ () + { + TypeInfo ti (typeid (InterfaceDecl)); + ti.add_base (Access::PUBLIC, true, Declaration::static_type_info ()); + return ti; + } + + TypeInfo interface_decl_ (interface_decl_init_ ()); + } + + TypeInfo const& InterfaceDecl:: + static_type_info () { return interface_decl_; } + + + // InterfaceDef + // + // + + namespace + { + TypeInfo + interface_def_init_ () + { + TypeInfo ti (typeid (InterfaceDef)); + ti.add_base (Access::PUBLIC, true, InterfaceDecl::static_type_info ()); + ti.add_base (Access::PUBLIC, true, Scope::static_type_info ()); + return ti; + } + + TypeInfo interface_def_ (interface_def_init_ ()); + } + + TypeInfo const& InterfaceDef:: + static_type_info () { return interface_def_; } + +} +//$Id$ diff --git a/contrib/utility/Example/Introspection/Traversal/SyntaxTree.hpp b/contrib/utility/Example/Introspection/Traversal/SyntaxTree.hpp new file mode 100644 index 00000000000..7bd824ce683 --- /dev/null +++ b/contrib/utility/Example/Introspection/Traversal/SyntaxTree.hpp @@ -0,0 +1,95 @@ +// file : Example/Introspection/Traversal/SyntaxTree.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef SYNTAX_TREE_HPP +#define SYNTAX_TREE_HPP + +#include + +#include "Utility/Introspection/Introspection.hpp" + +namespace SyntaxTree +{ + // + // + // + + struct Node : virtual Utility::Introspection::Object + { + Node () + { + type_info (static_type_info ()); + } + + static Utility::Introspection::TypeInfo const& + static_type_info (); + }; + + // + // + // + + struct Declaration : virtual Node + { + Declaration () + { + type_info (static_type_info ()); + } + + static Utility::Introspection::TypeInfo const& + static_type_info (); + }; + + typedef + std::vector + DeclarationList; + + // + // + // + struct Scope : virtual Declaration + { + Scope () + { + type_info (static_type_info ()); + } + + static Utility::Introspection::TypeInfo const& + static_type_info (); + + DeclarationList content_; + }; + + // + // + // + struct InterfaceDecl : virtual Declaration + { + InterfaceDecl () + { + type_info (static_type_info ()); + } + + static Utility::Introspection::TypeInfo const& + static_type_info (); + }; + + // + // + // + struct InterfaceDef : virtual InterfaceDecl, virtual Scope + { + InterfaceDef () + { + type_info (static_type_info ()); + } + + static Utility::Introspection::TypeInfo const& + static_type_info (); + }; +} + +#endif // SYNTAX_TREE_HPP +//$Id$ diff --git a/contrib/utility/Example/Introspection/Traversal/Traversal.cpp b/contrib/utility/Example/Introspection/Traversal/Traversal.cpp new file mode 100644 index 00000000000..9fa94327c2c --- /dev/null +++ b/contrib/utility/Example/Introspection/Traversal/Traversal.cpp @@ -0,0 +1,105 @@ +// file : Example/Introspection/Traversal/Traversal.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Traversal.hpp" + +#include +#include + +using namespace Utility::Introspection; + +namespace Traversal +{ + // Dispatcher + // + // + + struct TypeInfoComparator + { + bool + operator () (TypeInfo const& x, TypeInfo const& y) const + { + return x.type_id () < y.type_id (); + } + }; + + typedef + std::map + LevelMap; + + typedef + std::set + TypeInfoSet; + + unsigned long + compute_levels (TypeInfo const& ti, unsigned long cur, LevelMap& map) + { + unsigned long ret = cur; + + if (map.find (ti) == map.end () || map[ti] < cur) map[ti] = cur; + + for (TypeInfo::BaseIterator i = ti.begin_base (); + i != ti.end_base (); + i++) + { + unsigned long t = compute_levels (i->type_info (), cur + 1, map); + if (t > ret) ret = t; + } + + return ret; + } + + void + flatten_tree (TypeInfo const& ti, TypeInfoSet& set) + { + set.insert (ti); + + for (TypeInfo::BaseIterator i = ti.begin_base (); + i != ti.end_base (); + i++) + { + flatten_tree (i->type_info (), set); + } + } + + void Dispatcher:: + dispatch (SyntaxTree::Node* n) + { + LevelMap levels; + + unsigned long max = compute_levels (n->type_info (), 0, levels); + + for (unsigned long l = 0; l < max + 1; l++) + { + TypeInfoSet dispatched; + + for (LevelMap::const_iterator i = levels.begin (); + i != levels.end (); + i++) + { + if (i->second == l) + { + TraversalMap::const_iterator v = + traversal_map_.find (i->first.type_id ()); + + if (v != traversal_map_.end ()) + { + v->second->traverse (n); + flatten_tree (i->first, dispatched); + } + } + } + + // Remove traversed types from level map. + for (TypeInfoSet::const_iterator i = dispatched.begin (); + i != dispatched.end (); + i++) + { + levels.erase (*i); + } + } + } +} +//$Id$ diff --git a/contrib/utility/Example/Introspection/Traversal/Traversal.hpp b/contrib/utility/Example/Introspection/Traversal/Traversal.hpp new file mode 100644 index 00000000000..7ee84523fc0 --- /dev/null +++ b/contrib/utility/Example/Introspection/Traversal/Traversal.hpp @@ -0,0 +1,157 @@ +// file : Example/Introspection/Traversal/Traversal.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef TRAVERSAL_HPP +#define TRAVERSAL_HPP + +#include +#include + +#include "Utility/Introspection/Introspection.hpp" + +#include "SyntaxTree.hpp" + +namespace Traversal +{ + class Traverser; + + // + // + // + class Dispatcher + { + public: + virtual + ~Dispatcher () + { + } + + virtual void + dispatch (SyntaxTree::Node* n); + + protected: + void + map (Utility::Introspection::TypeId id, Traverser* t) + { + traversal_map_[id] = t; + } + + private: + typedef + std::map + TraversalMap; + + TraversalMap traversal_map_; + }; + + + // + // + // + class Traverser : public virtual Dispatcher + { + public: + virtual void + traverse (SyntaxTree::Node* n) = 0; + }; + + // + // + // + struct Node : Traverser + { + Node () + { + map (typeid (SyntaxTree::Node), this); + } + + virtual void + traverse (SyntaxTree::Node*) + { + std::cerr << "node" << std::endl; + } + }; + + + // + // + // + struct Declaration : Traverser + { + Declaration () + { + map (typeid (SyntaxTree::Declaration), this); + } + + virtual void + traverse (SyntaxTree::Node*) + { + std::cerr << "declaration" << std::endl; + } + }; + + // + // + // + struct Scope : Traverser + { + Scope () + { + map (typeid (SyntaxTree::Scope), this); + } + + virtual void + traverse (SyntaxTree::Node* n) + { + std::cerr << "scope" << std::endl; + + SyntaxTree::Scope* s = dynamic_cast (n); + + for (SyntaxTree::DeclarationList::iterator i = s->content_.begin (); + i != s->content_.end (); + i++) + { + dispatch (*i); + } + } + }; + + // + // + // + struct InterfaceDecl : Traverser + { + InterfaceDecl () + { + map (typeid (SyntaxTree::InterfaceDecl), this); + } + + virtual void + traverse (SyntaxTree::Node*) + { + std::cerr << "interface declaration" << std::endl; + } + }; + + // + // + // + struct InterfaceDef : Traverser + { + InterfaceDef () + { + map (typeid (SyntaxTree::InterfaceDef), this); + } + + virtual void + traverse (SyntaxTree::Node*) + { + std::cerr << "interface definition" << std::endl; + } + }; +} + +#endif // TRAVERSAL_HPP +//$Id$ diff --git a/contrib/utility/Example/Introspection/Traversal/driver.cpp b/contrib/utility/Example/Introspection/Traversal/driver.cpp new file mode 100644 index 00000000000..35891ef58cc --- /dev/null +++ b/contrib/utility/Example/Introspection/Traversal/driver.cpp @@ -0,0 +1,91 @@ +// file : Example/Introspection/Traversal/driver.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include + +#include "SyntaxTree.hpp" +#include "Traversal.hpp" + +int +main () +{ + using namespace SyntaxTree; + + /* + Create a syntax tree that looks something like this: + + scope + { + interface declaration; + + scope + { + interface definition + { + decalartion; + }; + }; + }; + + */ + + Scope s1; + + InterfaceDecl i1; + s1.content_.push_back (&i1); + + Scope s2; + s1.content_.push_back (&s2); + + InterfaceDef i2; + s2.content_.push_back (&i2); + + Declaration d1; + i2.content_.push_back (&d1); + + SyntaxTree::Node* root = &s1; + + // Now different ways of traversing this tree: + + { + std::cout << "test #1" << std::endl; + + struct Generator : Traversal::Declaration, Traversal::Scope + { + }; + + Generator g; + g.dispatch (root); + + std::cout << std::endl; + } + + { + std::cout << "test #2" << std::endl; + + struct Generator : Traversal::Scope, Traversal::InterfaceDecl + { + }; + + Generator g; + g.dispatch (root); + + std::cout << std::endl; + } + + { + std::cout << "test #3" << std::endl; + + struct Generator : Traversal::Scope, Traversal::InterfaceDef + { + }; + + Generator g; + g.dispatch (root); + + std::cout << std::endl; + } +} +//$Id$ diff --git a/contrib/utility/Example/Makefile b/contrib/utility/Example/Makefile new file mode 100644 index 00000000000..1caefc91a39 --- /dev/null +++ b/contrib/utility/Example/Makefile @@ -0,0 +1,16 @@ +# file : Example/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := .. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := ExH Hetero Introspection + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Makefile b/contrib/utility/Makefile new file mode 100644 index 00000000000..d23e380254b --- /dev/null +++ b/contrib/utility/Makefile @@ -0,0 +1,18 @@ +# file : Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := . + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := Utility Test Example Documentation + +Test Example Documentation : Utility + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ExH/Compound/Makefile b/contrib/utility/Test/ExH/Compound/Makefile new file mode 100644 index 00000000000..b596cd2fbce --- /dev/null +++ b/contrib/utility/Test/ExH/Compound/Makefile @@ -0,0 +1,24 @@ +# file : Test/ExH/Compound/Makefile +# author : Boris Kolpackov +# 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 := compound.cpp + +module_base := compound +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ExH/Compound/compound.cpp b/contrib/utility/Test/ExH/Compound/compound.cpp new file mode 100644 index 00000000000..d3319f5d7dc --- /dev/null +++ b/contrib/utility/Test/ExH/Compound/compound.cpp @@ -0,0 +1,115 @@ +// file : Test/ExH/Compound/compound.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/Compound.hpp" + +#include + +using namespace Utility::ExH; + +struct E {}; + +void postcondition (bool p) throw (E) +{ + if (!p) throw E (); +} + +class Base +{ +protected: + Base () throw () + { + } + + void + init (char const* description) throw () + { + str_ = description; + } + + char const* + what () const throw () + { + return str_.c_str (); + } + +public: + std::string str_; +}; + +class A_ {}; +typedef +Compound +A; + +struct StringHolder +{ + StringHolder (char const* s) + : str_ (s) + { + } + + operator std::string () const + { + return str_; + } + + std::string str_; +}; + + +int main () +{ + try + { + // Compound (char const*) + // + { + A a ("hello"); + + postcondition (a.str_ == "hello"); + } + + // Compound (T const&) + // + { + StringHolder a ("hello"); + A b (a); + + postcondition (b.str_ == "hello"); + } + + // Compound (Compound const&) + // + { + A a ("hello"); + A b (a); + + postcondition (b.str_ == "hello"); + } + + // ~Compound () + // + + // operator= (Compound const&) + // + { + A a ("hello"); + A b ("foo"); + b = a; + + postcondition (b.str_ == "hello"); + } + + // Compound () + // + + } + catch (...) + { + return -1; + } +} +//$Id$ diff --git a/contrib/utility/Test/ExH/Converter/Makefile b/contrib/utility/Test/ExH/Converter/Makefile new file mode 100644 index 00000000000..3f37652482d --- /dev/null +++ b/contrib/utility/Test/ExH/Converter/Makefile @@ -0,0 +1,24 @@ +# file : Test/ExH/Converter/Makefile +# author : Boris Kolpackov +# 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 := converter.cpp + +module_base := converter +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ExH/Converter/converter.cpp b/contrib/utility/Test/ExH/Converter/converter.cpp new file mode 100644 index 00000000000..396b616e6a6 --- /dev/null +++ b/contrib/utility/Test/ExH/Converter/converter.cpp @@ -0,0 +1,48 @@ +// file : Test/ExH/Converter/converter.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/Converter.hpp" +#include "Utility/ExH/StringStreamConverter.hpp" + +#include +#include + +using std::string; +using namespace Utility::ExH; + +struct E {}; + +void postcondition (bool p) throw (E) +{ + if (!p) throw E (); +} + +int +main () +{ + try + { + // template + // converter (T const&) + // + { + postcondition (converter ("hello") == string("hello")); + } + + // template<> + // converter (std::ostringstream const&) + // + { + std::ostringstream ostr; + ostr << "hello"; + postcondition (converter (ostr) == string("hello")); + } + } + catch (...) + { + return -1; + } +} +//$Id$ diff --git a/contrib/utility/Test/ExH/Inline/Makefile b/contrib/utility/Test/ExH/Inline/Makefile new file mode 100644 index 00000000000..26606c35669 --- /dev/null +++ b/contrib/utility/Test/ExH/Inline/Makefile @@ -0,0 +1,24 @@ +# file : Test/ExH/Inline/Makefile +# author : Boris Kolpackov +# 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 := inline.cpp unit.cpp + +module_base := inline +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ExH/Inline/inline.cpp b/contrib/utility/Test/ExH/Inline/inline.cpp new file mode 100644 index 00000000000..7700728932f --- /dev/null +++ b/contrib/utility/Test/ExH/Inline/inline.cpp @@ -0,0 +1,18 @@ +// file : Test/ExH/Inline/inline.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +// +// This is a link-time test to detect any problems with inline functions +// (notably missing inline specifier). +// + +#include "Utility/ExH/ExH.hpp" + +int +main () +{ +} + +//$Id$ diff --git a/contrib/utility/Test/ExH/Inline/unit.cpp b/contrib/utility/Test/ExH/Inline/unit.cpp new file mode 100644 index 00000000000..8a57af7d759 --- /dev/null +++ b/contrib/utility/Test/ExH/Inline/unit.cpp @@ -0,0 +1,8 @@ +// file : Test/ExH/Inline/unit.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/ExH.hpp" + +//$Id$ diff --git a/contrib/utility/Test/ExH/Logic/DescriptiveException/Makefile b/contrib/utility/Test/ExH/Logic/DescriptiveException/Makefile new file mode 100644 index 00000000000..6ca8e6029ee --- /dev/null +++ b/contrib/utility/Test/ExH/Logic/DescriptiveException/Makefile @@ -0,0 +1,24 @@ +# file : Test/ExH/Logic/DescriptiveException/Makefile +# author : Boris Kolpackov +# 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 := descriptive_exception.cpp + +module_base := descriptive_exception +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ExH/Logic/DescriptiveException/descriptive_exception.cpp b/contrib/utility/Test/ExH/Logic/DescriptiveException/descriptive_exception.cpp new file mode 100644 index 00000000000..7c3246df491 --- /dev/null +++ b/contrib/utility/Test/ExH/Logic/DescriptiveException/descriptive_exception.cpp @@ -0,0 +1,108 @@ +// file : Test/ExH/Logic/DescriptiveException/descriptive_exception.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +#include + +using std::string; +using namespace Utility::ExH::Logic; + +struct E {}; + +void postcondition (bool p) throw (E) +{ + if (!p) throw E (); +} + +struct StringHolder +{ + StringHolder (char const* s) + : str_ (s) + { + } + + operator std::string () const + { + return str_; + } + + string str_; +}; + +int +main () +{ + try + { + // DescriptiveException (char const*) + // + { + DescriptiveException a ("hello"); + + postcondition (a.what () == string ("hello")); + } + + // DescriptiveException (std::string const&) + // + { + DescriptiveException a (string ("hello")); + + postcondition (a.what () == string ("hello")); + } + + + // DescriptiveException (T const&) + // + { + StringHolder a ("hello"); + + DescriptiveException b (a); + + postcondition (b.what () == string ("hello")); + } + + // DescriptiveException (DescriptiveException const&) + // + { + DescriptiveException a ("hello"); + DescriptiveException b (a); + + postcondition (b.what () == string ("hello")); + } + + // ~DescriptiveException + // + + // operator= (DescriptiveException const&) + // + { + DescriptiveException a ("hello"); + DescriptiveException b ("foo"); + b = a; + + postcondition (b.what () == string ("hello")); + } + + // DescriptiveException () + // + + // init (char const*) + // + + // what () + // + { + DescriptiveException a ("hello"); + + postcondition (a.what () == string ("hello")); + } + } + catch (...) + { + return -1; + } +} +//$Id$ diff --git a/contrib/utility/Test/ExH/Logic/Makefile b/contrib/utility/Test/ExH/Logic/Makefile new file mode 100644 index 00000000000..042b3a172a4 --- /dev/null +++ b/contrib/utility/Test/ExH/Logic/Makefile @@ -0,0 +1,16 @@ +# file : Test/ExH/Logic/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := DescriptiveException + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ExH/Makefile b/contrib/utility/Test/ExH/Makefile new file mode 100644 index 00000000000..161884a439c --- /dev/null +++ b/contrib/utility/Test/ExH/Makefile @@ -0,0 +1,16 @@ +# file : Test/ExH/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := Compound Converter Inline Logic System + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ExH/System/DescriptiveException/Makefile b/contrib/utility/Test/ExH/System/DescriptiveException/Makefile new file mode 100644 index 00000000000..9fd89d86ade --- /dev/null +++ b/contrib/utility/Test/ExH/System/DescriptiveException/Makefile @@ -0,0 +1,24 @@ +# file : Test/ExH/System/DescriptiveException/Makefile +# author : Boris Kolpackov +# 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 := descriptive_exception.cpp + +module_base := descriptive_exception +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ExH/System/DescriptiveException/descriptive_exception.cpp b/contrib/utility/Test/ExH/System/DescriptiveException/descriptive_exception.cpp new file mode 100644 index 00000000000..4cd14da8627 --- /dev/null +++ b/contrib/utility/Test/ExH/System/DescriptiveException/descriptive_exception.cpp @@ -0,0 +1,107 @@ +// file : Test/ExH/System/DescriptiveException/descriptive_exception.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/System/DescriptiveException.hpp" + +#include + +using std::string; +using namespace Utility::ExH::System; + +struct E {}; + +void postcondition (bool p) throw (E) +{ + if (!p) throw E (); +} + +struct StringHolder +{ + StringHolder (char const* s) + : str_ (s) + { + } + + operator std::string () const + { + return str_; + } + + string str_; +}; + +int +main () +{ + try + { + // DescriptiveException (char const*) + // + { + DescriptiveException a ("hello"); + + postcondition (a.what () == string ("hello")); + } + + // DescriptiveException (std::string const&) + // + { + DescriptiveException a (string ("hello")); + + postcondition (a.what () == string ("hello")); + } + + // DescriptiveException (T const&) + // + { + StringHolder a ("hello"); + + DescriptiveException b (a); + + postcondition (b.what () == string ("hello")); + } + + // DescriptiveException (DescriptiveException const&) + // + { + DescriptiveException a ("hello"); + DescriptiveException b (a); + + postcondition (b.what () == string ("hello")); + } + + // ~DescriptiveException + // + + // operator= (DescriptiveException const&) + // + { + DescriptiveException a ("hello"); + DescriptiveException b ("foo"); + b = a; + + postcondition (b.what () == string ("hello")); + } + + // DescriptiveException () + // + + // init (char const*) + // + + // what () + // + { + DescriptiveException a ("hello"); + + postcondition (a.what () == string ("hello")); + } + } + catch (...) + { + return -1; + } +} +//$Id$ diff --git a/contrib/utility/Test/ExH/System/Makefile b/contrib/utility/Test/ExH/System/Makefile new file mode 100644 index 00000000000..2ffea12a6ed --- /dev/null +++ b/contrib/utility/Test/ExH/System/Makefile @@ -0,0 +1,16 @@ +# file : Test/ExH/System/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := DescriptiveException + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Test/Introspection/Inline/Makefile b/contrib/utility/Test/Introspection/Inline/Makefile new file mode 100644 index 00000000000..fb7a72c1e2f --- /dev/null +++ b/contrib/utility/Test/Introspection/Inline/Makefile @@ -0,0 +1,24 @@ +# file : Test/Introspection/Inline/Makefile +# author : Boris Kolpackov +# 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 := inline.cpp unit.cpp + +module_base := inline +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/Introspection/Inline/inline.cpp b/contrib/utility/Test/Introspection/Inline/inline.cpp new file mode 100644 index 00000000000..99ff8ff590f --- /dev/null +++ b/contrib/utility/Test/Introspection/Inline/inline.cpp @@ -0,0 +1,18 @@ +// file : Test/Introspection/Inline/inline.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +// +// This is a link-time test to detect any problems with inline functions +// (notably missing inline specifier). +// + +#include "Utility/Introspection/Introspection.hpp" + +int +main () +{ +} + +//$Id$ diff --git a/contrib/utility/Test/Introspection/Inline/unit.cpp b/contrib/utility/Test/Introspection/Inline/unit.cpp new file mode 100644 index 00000000000..a5fe6f95b65 --- /dev/null +++ b/contrib/utility/Test/Introspection/Inline/unit.cpp @@ -0,0 +1,8 @@ +// file : Test/Introspection/Inline/unit.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/Introspection/Introspection.hpp" + +//$Id$ diff --git a/contrib/utility/Test/Introspection/Makefile b/contrib/utility/Test/Introspection/Makefile new file mode 100644 index 00000000000..8ed18da5c41 --- /dev/null +++ b/contrib/utility/Test/Introspection/Makefile @@ -0,0 +1,16 @@ +# file : Test/Introspection/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := Inline + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Test/Makefile b/contrib/utility/Test/Makefile new file mode 100644 index 00000000000..4ac5c3530b8 --- /dev/null +++ b/contrib/utility/Test/Makefile @@ -0,0 +1,18 @@ +# file : Test/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := .. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := ExH Introspection ReferenceCounting Synch + +ReferenceCounting : ExH Synch + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ReferenceCounting/DefaultImpl/Makefile b/contrib/utility/Test/ReferenceCounting/DefaultImpl/Makefile new file mode 100644 index 00000000000..c3f89dc7a9c --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/DefaultImpl/Makefile @@ -0,0 +1,24 @@ +# file : Test/ReferenceCounting/DefaultImpl/Makefile +# author : Boris Kolpackov +# 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 := default_impl.cpp + +module_base := default_impl +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp b/contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp new file mode 100644 index 00000000000..971751b6677 --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp @@ -0,0 +1,132 @@ +// file : Test/ReferenceCounting/DefaultImpl/default_impl.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ReferenceCounting/DefaultImpl.hpp" + +using namespace Utility::ReferenceCounting; + +struct Base : public virtual Interface +{ + virtual + ~Base () throw () + { + } +}; + + +class Impl : public virtual Base, + public virtual DefaultImpl <> +{ +public: + Impl (bool& destroyed) + : dummy_ (false), + destroyed_ (destroyed) + { + } + + Impl () + : dummy_ (false), + destroyed_ (dummy_) + { + } + + virtual + ~Impl () throw () + { + destroyed_ = true; + } + +public: + void + lock () + { + lock_i (); + } + +private: + bool dummy_; + bool& destroyed_; +}; + +struct E {}; + +void postcondition (bool p) throw (E) +{ + if (!p) throw E (); +} + +int main () +{ + try + { + // DefaultImpl + // + { + Impl* a (new Impl); + + postcondition (a->refcount_value () == 1); + + a->remove_ref (); + } + + // ~DefaultImpl + // + { + Impl* a (new Impl); + a->remove_ref (); + } + + // add_ref + // + { + Impl* a (new Impl); + + a->add_ref (); + + postcondition (a->refcount_value () == 2); + + a->remove_ref (); + a->remove_ref (); + } + + + // remove_ref + // + { + bool destroyed (false); + Impl* a (new Impl (destroyed)); + + a->add_ref (); + a->remove_ref (); + + postcondition (destroyed == false && a->refcount_value () == 1); + + a->remove_ref (); + + postcondition (destroyed == true); + } + + + // refcount_value + // + { + Impl* a (new Impl); + + postcondition (a->refcount_value () == 1); + } + + // lock_i + // + { + Impl* a (new Impl); + a->lock (); + } + } + catch (...) + { + return -1; + } +} +//$Id$ diff --git a/contrib/utility/Test/ReferenceCounting/Inline/Makefile b/contrib/utility/Test/ReferenceCounting/Inline/Makefile new file mode 100644 index 00000000000..5ae9a840c8d --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/Inline/Makefile @@ -0,0 +1,24 @@ +# file : Test/ReferenceCounting/Inline/Makefile +# author : Boris Kolpackov +# 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 := inline.cpp unit.cpp + +module_base := inline +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ReferenceCounting/Inline/inline.cpp b/contrib/utility/Test/ReferenceCounting/Inline/inline.cpp new file mode 100644 index 00000000000..0ff2dfa9986 --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/Inline/inline.cpp @@ -0,0 +1,16 @@ +// file : Test/ReferenceCounting/Inline/inline.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +// +// This is a link-time test to detect any problems with inline functions +// (notably missing inline specifier). +// + +#include "Utility/ReferenceCounting/ReferenceCounting.hpp" + +int main () +{ +} +//$Id$ diff --git a/contrib/utility/Test/ReferenceCounting/Inline/unit.cpp b/contrib/utility/Test/ReferenceCounting/Inline/unit.cpp new file mode 100644 index 00000000000..31dbfdb8708 --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/Inline/unit.cpp @@ -0,0 +1,8 @@ +// file : Test/ReferenceCounting/Inline/unit.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ReferenceCounting/ReferenceCounting.hpp" + +//$Id$ diff --git a/contrib/utility/Test/ReferenceCounting/Interface/Makefile b/contrib/utility/Test/ReferenceCounting/Interface/Makefile new file mode 100644 index 00000000000..4327774eb54 --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/Interface/Makefile @@ -0,0 +1,24 @@ +# file : Test/ReferenceCounting/Interface/Makefile +# author : Boris Kolpackov +# 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 := interface.cpp + +module_base := interface +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ReferenceCounting/Interface/interface.cpp b/contrib/utility/Test/ReferenceCounting/Interface/interface.cpp new file mode 100644 index 00000000000..a9cb4d55824 --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/Interface/interface.cpp @@ -0,0 +1,104 @@ +// file : Test/ReferenceCounting/Interface/interface.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ReferenceCounting/Interface.hpp" + +using namespace Utility::ReferenceCounting; + +struct Obj : public virtual Interface +{ + Obj () + : ref_count_ (1) + { + } + + virtual + ~Obj () throw () + { + } + +public: + virtual void + add_ref () const throw () + { + add_ref_i (); + } + + + virtual void + remove_ref () const throw () + { + if (remove_ref_i ()) delete this; + } + + virtual count_t + refcount_value () const throw () + { + return refcount_value_i (); + } + +protected: + virtual void + add_ref_i () const throw () + { + ++ref_count_; + } + + + virtual bool + remove_ref_i () const throw () + { + return --ref_count_ == 0; + } + + virtual count_t + refcount_value_i () const throw () + { + return ref_count_; + } + +private: + mutable count_t ref_count_; +}; + + +struct E {}; + +void postcondition (bool p) throw (E) +{ + if (!p) throw E (); +} + +int main () +{ + try + { + // add_ref + // + { + Obj* a (new Obj); + + Obj* b (add_ref (a)); + + postcondition (a == b && a->refcount_value () == 2); + + a->remove_ref (); + b->remove_ref (); + } + + { + Obj* a (0); + + Obj* b (add_ref (a)); + + postcondition (b == 0); + } + } + catch (...) + { + return -1; + } +} +//$Id$ diff --git a/contrib/utility/Test/ReferenceCounting/Makefile b/contrib/utility/Test/ReferenceCounting/Makefile new file mode 100644 index 00000000000..1f7d981c87f --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/Makefile @@ -0,0 +1,16 @@ +# file : Test/ReferenceCounting/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := Interface DefaultImpl Inline SmartPtr StrictPtr + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ReferenceCounting/SmartPtr/Makefile b/contrib/utility/Test/ReferenceCounting/SmartPtr/Makefile new file mode 100644 index 00000000000..7bbc0456949 --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/SmartPtr/Makefile @@ -0,0 +1,24 @@ +# file : Test/ReferenceCounting/SmartPtr/Makefile +# author : Boris Kolpackov +# 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 := smart_ptr.cpp + +module_base := smart_ptr +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ReferenceCounting/SmartPtr/smart_ptr.cpp b/contrib/utility/Test/ReferenceCounting/SmartPtr/smart_ptr.cpp new file mode 100644 index 00000000000..67f4442a359 --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/SmartPtr/smart_ptr.cpp @@ -0,0 +1,220 @@ +// file : Test/ReferenceCounting/SmartPtr/smart_ptr.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ReferenceCounting/SmartPtr.hpp" +#include "Utility/ReferenceCounting/DefaultImpl.hpp" + +using namespace Utility::ReferenceCounting; + +struct Base : public virtual Interface +{ + virtual + ~Base () throw () + { + } +}; + +typedef +SmartPtr +BasePtr; + +class Impl : public virtual Base, + public virtual DefaultImpl <> +{ +public: + Impl (bool& destroyed) + : dummy_ (false), + destroyed_ (destroyed) + { + } + + Impl () + : dummy_ (false), + destroyed_ (dummy_) + { + } + + virtual + ~Impl () throw () + { + destroyed_ = true; + } + +private: + bool dummy_; + bool& destroyed_; +}; + +typedef +SmartPtr +ImplPtr; + +struct E {}; + +void postcondition (bool p) throw (E) +{ + if (!p) throw E (); +} + +int main () +{ + try + { + // SmartPtr () + // + { + BasePtr a; + + postcondition (a.in () == 0); + } + + // SmartPtr (Type*) + // + { + Impl* a (new Impl); + ImplPtr b (a); + + postcondition (b.in () == a && a->refcount_value () == 1); + } + + // SmartPtr (SmartPtr const&) + // + { + ImplPtr a (new Impl); + ImplPtr b (a); + + postcondition (a.in () == b.in () && a->refcount_value () == 2); + } + + // SmartPtr (SmartPtr const&) + // + { + ImplPtr a (new Impl); + BasePtr b (a); + + postcondition (b.in () == static_cast(a.in ()) && + b->refcount_value () == 2); + } + + // ~SmartPtr + // + { + bool destroyed (false); + { + ImplPtr a (new Impl (destroyed)); + } + + postcondition (destroyed == true); + } + + // operator= (Type* ptr) + // + { + Impl* a (new Impl); + ImplPtr b; + b = a; + + postcondition (b.in () == a && a->refcount_value () == 1); + } + + // operator= (SmartPtr const&) + // + { + ImplPtr a (new Impl); + ImplPtr b; + b = a; + + postcondition (b.in () == a.in () && a->refcount_value () == 2); + } + + // operator= (SmartPtr const&) + // + { + ImplPtr a (new Impl); + BasePtr b; + b = a; + + postcondition (b.in () == static_cast(a.in ()) && + b->refcount_value () == 2); + } + + // operator Type* + // + { + Impl* a (new Impl); + ImplPtr b (a); + Impl* c (b); + + postcondition (a == c); + } + + // operator-> + // + { + Impl* a (new Impl); + ImplPtr b (a); + Impl* c (b.operator-> ()); + + postcondition (a == c); + } + + // in + // + { + Impl* a (new Impl); + ImplPtr b (a); + Impl* c (b.in ()); + + postcondition (a == c); + } + + // retn + // + { + Impl* a (new Impl); + ImplPtr b (a); + Impl* c (b.retn ()); + + postcondition (a == c); + + b = a; // give ownership back + } + + // add_ref + // + { + ImplPtr a (new Impl); + ImplPtr b (add_ref (a)); + + postcondition (a.in () == b.in () && b->refcount_value () == 2); + } + + // smart_cast + // + { + BasePtr a (new Impl); + ImplPtr b (smart_cast(a)); + + postcondition (b != 0 && b->refcount_value () == 2); + } + + // acquire + // + { + bool destroyed (false); + Base::count_t c (0); + { + c = acquire (new Impl (destroyed))->refcount_value (); + } + + postcondition (c == 1 && destroyed == true); + } + } + catch (...) + { + return -1; + } +} +//$Id$ diff --git a/contrib/utility/Test/ReferenceCounting/StrictPtr/Makefile b/contrib/utility/Test/ReferenceCounting/StrictPtr/Makefile new file mode 100644 index 00000000000..e078ef688fe --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/StrictPtr/Makefile @@ -0,0 +1,24 @@ +# file : Test/ReferenceCounting/StrictPtr/Makefile +# author : Boris Kolpackov +# 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 := strict_ptr.cpp + +module_base := strict_ptr +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/ReferenceCounting/StrictPtr/strict_ptr.cpp b/contrib/utility/Test/ReferenceCounting/StrictPtr/strict_ptr.cpp new file mode 100644 index 00000000000..1fcee9448ea --- /dev/null +++ b/contrib/utility/Test/ReferenceCounting/StrictPtr/strict_ptr.cpp @@ -0,0 +1,218 @@ +// file : Test/ReferenceCounting/StrictPtr/strict_ptr.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ReferenceCounting/StrictPtr.hpp" +#include "Utility/ReferenceCounting/DefaultImpl.hpp" + +using namespace Utility::ReferenceCounting; + +struct Base : public virtual Interface +{ + virtual + ~Base () throw () + { + } +}; + +typedef +StrictPtr +BasePtr; + +class Impl : public virtual Base, + public virtual DefaultImpl <> +{ +public: + Impl (bool& destroyed) + : dummy_ (false), + destroyed_ (destroyed) + { + } + + Impl () + : dummy_ (false), + destroyed_ (dummy_) + { + } + + virtual + ~Impl () throw () + { + destroyed_ = true; + } + +private: + bool dummy_; + bool& destroyed_; +}; + +typedef +StrictPtr +ImplPtr; + +struct E {}; + +void postcondition (bool p) throw (E) +{ + if (!p) throw E (); +} + +int main () +{ + try + { + // StrictPtr () + // + { + BasePtr a; + + postcondition (a.in () == 0); + } + + // StrictPtr (Type*) + // + { + Impl* a (new Impl); + ImplPtr b (a); + + postcondition (b.in () == a && a->refcount_value () == 1); + } + + // StrictPtr (StrictPtr const&) + // + { + ImplPtr a (new Impl); + ImplPtr b (a); + + postcondition (a.in () == b.in () && a->refcount_value () == 2); + } + + // StrictPtr (StrictPtr const&) + // + { + ImplPtr a (new Impl); + BasePtr b (a); + + postcondition (b.in () == static_cast(a.in ()) && + b->refcount_value () == 2); + } + + // ~StrictPtr + // + { + bool destroyed (false); + { + ImplPtr a (new Impl (destroyed)); + } + + postcondition (destroyed == true); + } + + // operator= (Type* ptr) + // + { + Impl* a (new Impl); + ImplPtr b; + b = a; + + postcondition (b.in () == a && a->refcount_value () == 1); + } + + // operator= (StrictPtr const&) + // + { + ImplPtr a (new Impl); + ImplPtr b; + b = a; + + postcondition (b.in () == a.in () && a->refcount_value () == 2); + } + + // operator= (StrictPtr const&) + // + { + ImplPtr a (new Impl); + BasePtr b; + b = a; + + postcondition (b.in () == static_cast(a.in ()) && + b->refcount_value () == 2); + } + + // operator== + // + { + Impl* a (new Impl); + ImplPtr b (a); + bool r (b.in () == a); + + postcondition (r == true); + } + + // operator!= + // + { + Impl* a (new Impl); + ImplPtr b (a); + bool r (b.in () != a); + + postcondition (r == false); + } + + // operator-> + // + { + Impl* a (new Impl); + ImplPtr b (a); + Impl* c (b.operator-> ()); + + postcondition (a == c); + } + + // in + // + { + Impl* a (new Impl); + ImplPtr b (a); + Impl* c (b.in ()); + + postcondition (a == c); + } + + // retn + // + { + Impl* a (new Impl); + ImplPtr b (a); + Impl* c (b.retn ()); + + postcondition (a == c); + + b = a; // give ownership back + } + + // add_ref + // + { + ImplPtr a (new Impl); + ImplPtr b (add_ref (a)); + + postcondition (a.in () == b.in () && b->refcount_value () == 2); + } + + // strict_cast + // + { + BasePtr a (new Impl); + ImplPtr b (strict_cast(a)); + + postcondition (b != 0 && b->refcount_value () == 2); + } + } + catch (...) + { + return -1; + } +} +//$Id$ diff --git a/contrib/utility/Test/Synch/Inline/Makefile b/contrib/utility/Test/Synch/Inline/Makefile new file mode 100644 index 00000000000..2101cc3ee8c --- /dev/null +++ b/contrib/utility/Test/Synch/Inline/Makefile @@ -0,0 +1,24 @@ +# file : Test/Synch/Inline/Makefile +# author : Boris Kolpackov +# 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 := inline.cpp unit.cpp + +module_base := inline +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/contrib/utility/Test/Synch/Inline/inline.cpp b/contrib/utility/Test/Synch/Inline/inline.cpp new file mode 100644 index 00000000000..0b2db8a7d57 --- /dev/null +++ b/contrib/utility/Test/Synch/Inline/inline.cpp @@ -0,0 +1,18 @@ +// file : Test/Synch/Inline/inline.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +// +// This is a link-time test to detect any problems with inline functions +// (notably missing inline specifier). +// + +#include "Utility/Synch/Policy/Null.hpp" + +int +main () +{ +} + +//$Id$ diff --git a/contrib/utility/Test/Synch/Inline/unit.cpp b/contrib/utility/Test/Synch/Inline/unit.cpp new file mode 100644 index 00000000000..b570c97ae5e --- /dev/null +++ b/contrib/utility/Test/Synch/Inline/unit.cpp @@ -0,0 +1,8 @@ +// file : Test/Synch/Inline/unit.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/Synch/Policy/Null.hpp" + +//$Id$ diff --git a/contrib/utility/Test/Synch/Makefile b/contrib/utility/Test/Synch/Makefile new file mode 100644 index 00000000000..c4b730ca6a5 --- /dev/null +++ b/contrib/utility/Test/Synch/Makefile @@ -0,0 +1,16 @@ +# file : Test/Synch/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := Inline + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Utility/ExH/Compound.hpp b/contrib/utility/Utility/ExH/Compound.hpp new file mode 100644 index 00000000000..664583fffb2 --- /dev/null +++ b/contrib/utility/Utility/ExH/Compound.hpp @@ -0,0 +1,47 @@ +// file : Utility/ExH/Compound.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_COMPOUND_HPP +#define UTILITY_EX_H_COMPOUND_HPP + +#include + +namespace Utility +{ + namespace ExH + { + template + class Compound : public virtual Base + { + public: + explicit + Compound (char const* description) throw (); + + explicit + Compound (std::string const& description) throw (); + + template + explicit + Compound (T const& description) throw (); + + Compound (Compound const& src) throw (); + + virtual + ~Compound () throw (); + + public: + Compound& + operator= (Compound const& src) throw (); + + protected: + Compound () throw (); + }; + } +} + +#include "Utility/ExH/Compound.tpp" + +#endif // UTILITY_EX_H_COMPOUND_HPP +//$Id$ diff --git a/contrib/utility/Utility/ExH/Compound.tpp b/contrib/utility/Utility/ExH/Compound.tpp new file mode 100644 index 00000000000..a4c798d97cb --- /dev/null +++ b/contrib/utility/Utility/ExH/Compound.tpp @@ -0,0 +1,71 @@ +// file : Utility/ExH/Compound.tpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/Converter.hpp" + +namespace Utility +{ + namespace ExH + { + // c-tor's & d-tor + template + Compound:: + Compound () throw () + { + } + + template + Compound:: + Compound (char const* description) throw () + { + Base::init (description); + } + + template + Compound:: + Compound (std::string const& description) throw () + { + try + { + Base::init (description.c_str ()); + } + catch (...) + { + } + } + + template + template + Compound:: + Compound (T const& description) throw () + { + Base::init (converter (description).c_str ()); + } + + template + Compound:: + Compound (Compound const& src) throw () + { + Base::init (src.what ()); + } + + template + Compound:: + ~Compound () throw () + { + } + + // operator= + + template + Compound& Compound:: + operator= (Compound const& src) throw () + { + Base::init (src.what ()); + return *this; + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/ExH/Converter.hpp b/contrib/utility/Utility/ExH/Converter.hpp new file mode 100644 index 00000000000..563114fd1c4 --- /dev/null +++ b/contrib/utility/Utility/ExH/Converter.hpp @@ -0,0 +1,24 @@ +// file : Utility/ExH/Converter.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_CONVERTER_HPP +#define UTILITY_EX_H_CONVERTER_HPP + +#include + +namespace Utility +{ + namespace ExH + { + template + std::string + converter (T const& t); + } +} + +#include "Utility/ExH/Converter.tpp" + +#endif // UTILITY_EX_H_CONVERTER_HPP +//$Id$ diff --git a/contrib/utility/Utility/ExH/Converter.tpp b/contrib/utility/Utility/ExH/Converter.tpp new file mode 100644 index 00000000000..2d48015fe80 --- /dev/null +++ b/contrib/utility/Utility/ExH/Converter.tpp @@ -0,0 +1,19 @@ +// file : Utility/ExH/Converter.tpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ExH + { + template + std::string + converter (T const& t) + { + // Default implementation just assumes that implicit converion exist. + return t; + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/ExH/ExH.hpp b/contrib/utility/Utility/ExH/ExH.hpp new file mode 100644 index 00000000000..722ecd02d25 --- /dev/null +++ b/contrib/utility/Utility/ExH/ExH.hpp @@ -0,0 +1,22 @@ +// file : Utility/ExH/ExH.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_EX_H_HPP +#define UTILITY_EX_H_EX_H_HPP + +#include "Utility/ExH/System/Exception.hpp" +#include "Utility/ExH/System/DescriptiveException.hpp" + +#include "Utility/ExH/Logic/Exception.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +#include "Utility/ExH/Compound.hpp" + +#include "Utility/ExH/Converter.hpp" +#include "Utility/ExH/StringStreamConverter.hpp" + +#endif // UTILITY_EX_H_EX_H_HPP + +//$Id$ diff --git a/contrib/utility/Utility/ExH/Logic/DescriptiveException.hpp b/contrib/utility/Utility/ExH/Logic/DescriptiveException.hpp new file mode 100644 index 00000000000..9559014e64d --- /dev/null +++ b/contrib/utility/Utility/ExH/Logic/DescriptiveException.hpp @@ -0,0 +1,63 @@ +// file : Utility/ExH/Logic/DescriptiveException.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_LOGIC_DESCRIPTIVE_EXCEPTION_HPP +#define UTILITY_EX_H_LOGIC_DESCRIPTIVE_EXCEPTION_HPP + +#include +#include + + +#include "Utility/ExH/Logic/Exception.hpp" + +namespace Utility +{ + namespace ExH + { + namespace Logic + { + class DescriptiveException : public virtual Exception + { + public: + explicit + DescriptiveException (char const* description) throw (); + + explicit + DescriptiveException (std::string const& description) throw (); + + template + explicit + DescriptiveException (T const& description) throw (); + + DescriptiveException (DescriptiveException const& src) throw (); + + virtual + ~DescriptiveException () throw (); + + DescriptiveException& + operator= (DescriptiveException const& src) throw (); + + protected: + DescriptiveException () throw (); + + void + init (char const* description) throw (); + + public: + virtual char const* + what () const throw (); + + private: + std::auto_ptr description_; + }; + } + } +} + +#include "Utility/ExH/Logic/DescriptiveException.ipp" +#include "Utility/ExH/Logic/DescriptiveException.tpp" + +#endif // UTILITY_EX_H_LOGIC_DESCRIPTIVE_EXCEPTION_HPP +//$Id$ diff --git a/contrib/utility/Utility/ExH/Logic/DescriptiveException.ipp b/contrib/utility/Utility/ExH/Logic/DescriptiveException.ipp new file mode 100644 index 00000000000..4a50a687777 --- /dev/null +++ b/contrib/utility/Utility/ExH/Logic/DescriptiveException.ipp @@ -0,0 +1,104 @@ +// file : Utility/ExH/Logic/DescriptiveException.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ExH + { + namespace Logic + { + // c-tor's & d-tor + + inline DescriptiveException:: + DescriptiveException () throw () + { + } + + inline DescriptiveException:: + DescriptiveException (char const* description) throw () + { + init (description); + } + + inline DescriptiveException:: + DescriptiveException (std::string const& description) throw () + { + try + { + init (description.c_str ()); + } + catch (...) + { + } + } + + inline DescriptiveException:: + DescriptiveException (DescriptiveException const& src) throw () + { + init (src.what ()); + } + + inline DescriptiveException:: + ~DescriptiveException () throw () + { + } + + inline DescriptiveException& DescriptiveException:: + operator= (DescriptiveException const& src) throw () + { + init (src.what ()); + return *this; + } + + + // accessors / modifiers + + inline void + DescriptiveException::init (char const* description) throw () + { + try + { + if (description == 0 || description[0] == '\0') + { + description_.reset (0); + } + else + { + if (description_.get () != 0) + { + *description_ = description; + } + else + { + description_.reset (new std::string (description)); + } + } + } + catch (...) + { + description_.reset (0); + } + } + + inline char const* + DescriptiveException::what () const throw () + { + try + { + if (description_.get () != 0) + { + return description_->c_str (); + } + } + catch (...) + { + } + + return Exception::what (); + } + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/ExH/Logic/DescriptiveException.tpp b/contrib/utility/Utility/ExH/Logic/DescriptiveException.tpp new file mode 100644 index 00000000000..02c65a67e2b --- /dev/null +++ b/contrib/utility/Utility/ExH/Logic/DescriptiveException.tpp @@ -0,0 +1,23 @@ +// file : Utility/ExH/Logic/DescriptiveException.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/Converter.hpp" + +namespace Utility +{ + namespace ExH + { + namespace Logic + { + template + DescriptiveException:: + DescriptiveException (T const& description) throw () + { + init (converter (description).c_str ()); + } + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/ExH/Logic/Exception.hpp b/contrib/utility/Utility/ExH/Logic/Exception.hpp new file mode 100644 index 00000000000..e91e1811622 --- /dev/null +++ b/contrib/utility/Utility/ExH/Logic/Exception.hpp @@ -0,0 +1,40 @@ +// file : Utility/ExH/Logic/Exception.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_LOGIC_EXCEPTION_HPP +#define UTILITY_EX_H_LOGIC_EXCEPTION_HPP + +#include "Utility/ExH/System/Exception.hpp" + +namespace Utility +{ + namespace ExH + { + namespace Logic + { + + // Logic::Exception inherits from System::Exception for the + // following reason. Semantically for some part of the + // system particular instance of Logic::Exception may seem as + // opaque System::Exception and the only way to handle it would + // be to propagate it further. In other words Logic::Exception + // can be seemlesly "converted" to System::Exception if there is + // no part of the system interested in handling it. + // + + class Exception : public virtual System::Exception + { + public: + virtual + ~Exception () throw (); + }; + } + } +} + +#include "Utility/ExH/Logic/Exception.ipp" + +#endif // UTILITY_EX_H_LOGIC_EXCEPTION_HPP +//$Id$ diff --git a/contrib/utility/Utility/ExH/Logic/Exception.ipp b/contrib/utility/Utility/ExH/Logic/Exception.ipp new file mode 100644 index 00000000000..d3b774be937 --- /dev/null +++ b/contrib/utility/Utility/ExH/Logic/Exception.ipp @@ -0,0 +1,20 @@ +// file : Utility/ExH/Logic/Exception.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ExH + { + namespace Logic + { + inline Exception:: + ~Exception () throw () + { + } + } + } +} + +//$Id$ diff --git a/contrib/utility/Utility/ExH/StringStreamConverter.hpp b/contrib/utility/Utility/ExH/StringStreamConverter.hpp new file mode 100644 index 00000000000..a9a495f22e2 --- /dev/null +++ b/contrib/utility/Utility/ExH/StringStreamConverter.hpp @@ -0,0 +1,26 @@ +// file : Utility/ExH/StringStreamConverter.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_STRING_STREAM_CONVERTER_HPP +#define UTILITY_EX_H_STRING_STREAM_CONVERTER_HPP + +#include + +#include "Utility/ExH/Converter.hpp" + +namespace Utility +{ + namespace ExH + { + template <> + std::string + converter (std::ostringstream const& t); + } +} + +#include "Utility/ExH/StringStreamConverter.ipp" + +#endif // UTILITY_EX_H_STRING_STREAM_CONVERTER_HPP +//$Id$ diff --git a/contrib/utility/Utility/ExH/StringStreamConverter.ipp b/contrib/utility/Utility/ExH/StringStreamConverter.ipp new file mode 100644 index 00000000000..e454ac3f96c --- /dev/null +++ b/contrib/utility/Utility/ExH/StringStreamConverter.ipp @@ -0,0 +1,18 @@ +// file : Utility/ExH/StringStreamConverter.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ExH + { + template <> + inline std::string + converter (std::ostringstream const& t) + { + return t.str (); + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/ExH/System/DescriptiveException.hpp b/contrib/utility/Utility/ExH/System/DescriptiveException.hpp new file mode 100644 index 00000000000..8bc3de8ba1e --- /dev/null +++ b/contrib/utility/Utility/ExH/System/DescriptiveException.hpp @@ -0,0 +1,63 @@ +// file : Utility/ExH/System/DescriptiveException.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_SYSTEM_DESCRIPTIVE_EXCEPTION_HPP +#define UTILITY_EX_H_SYSTEM_DESCRIPTIVE_EXCEPTION_HPP + +#include +#include "Utility/ExH/System/Exception.hpp" + +namespace Utility +{ + namespace ExH + { + namespace System + { + class DescriptiveException : public virtual Exception + { + public: + explicit + DescriptiveException (char const* description) throw (); + + explicit + DescriptiveException (std::string const& description) throw (); + + template + explicit + DescriptiveException (T const& description) throw (); + + DescriptiveException (DescriptiveException const& src) throw (); + + virtual + ~DescriptiveException () throw (); + + DescriptiveException& + operator= (DescriptiveException const& src) throw (); + + protected: + DescriptiveException () throw (); + + void + init (char const* description) throw (); + + public: + virtual char const* + what () const throw (); + + private: + + static unsigned long const DESCRIPTION_SIZE = 256; + + char description_ [DESCRIPTION_SIZE]; + }; + } + } +} + +#include "Utility/ExH/System/DescriptiveException.ipp" +#include "Utility/ExH/System/DescriptiveException.tpp" + +#endif // UTILITY_EX_H_SYSTEM_DESCRIPTIVE_EXCEPTION_HPP +//$Id$ diff --git a/contrib/utility/Utility/ExH/System/DescriptiveException.ipp b/contrib/utility/Utility/ExH/System/DescriptiveException.ipp new file mode 100644 index 00000000000..d9768a518eb --- /dev/null +++ b/contrib/utility/Utility/ExH/System/DescriptiveException.ipp @@ -0,0 +1,90 @@ +// file : Utility/ExH/System/DescriptiveException.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include + +namespace Utility +{ + namespace ExH + { + namespace System + { + // c-tor's & d-tor + + inline DescriptiveException:: + DescriptiveException () throw () + { + description_[0] = '\0'; + } + + inline DescriptiveException:: + DescriptiveException (char const* description) throw () + { + init (description); + } + + inline DescriptiveException:: + DescriptiveException (std::string const& description) throw () + { + try + { + init (description.c_str ()); + } + catch (...) + { + } + } + + inline DescriptiveException:: + DescriptiveException (DescriptiveException const& src) throw () + { + init (src.what ()); + } + + inline DescriptiveException:: + ~DescriptiveException () throw () + { + } + + inline DescriptiveException& DescriptiveException:: + operator= (DescriptiveException const& src) throw () + { + init (src.what ()); + return *this; + } + + + // accessors / modifiers + + inline void DescriptiveException:: + init (char const* description) throw () + { + if (description != 0) + { + std::strncpy (description_, description, DESCRIPTION_SIZE - 1); + description_[DESCRIPTION_SIZE - 1] = '\0'; + } + else + { + description_[0] = '\0'; + } + } + + inline char const* DescriptiveException:: + what () const throw () + { + if (description_[0] != '\0') + { + return description_; + } + else + { + return Exception::what (); + } + } + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/ExH/System/DescriptiveException.tpp b/contrib/utility/Utility/ExH/System/DescriptiveException.tpp new file mode 100644 index 00000000000..320216acc2e --- /dev/null +++ b/contrib/utility/Utility/ExH/System/DescriptiveException.tpp @@ -0,0 +1,23 @@ +// file : Utility/ExH/System/DescriptiveException.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/ExH/Converter.hpp" + +namespace Utility +{ + namespace ExH + { + namespace System + { + template + inline DescriptiveException:: + DescriptiveException (T const& description) throw () + { + init (converter (description).c_str ()); + } + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/ExH/System/Exception.hpp b/contrib/utility/Utility/ExH/System/Exception.hpp new file mode 100644 index 00000000000..0ed7fbfa975 --- /dev/null +++ b/contrib/utility/Utility/ExH/System/Exception.hpp @@ -0,0 +1,29 @@ +// file : Utility/ExH/System/Exception.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_SYSTEM_EXCEPTION_HPP +#define UTILITY_EX_H_SYSTEM_EXCEPTION_HPP + +#include + +namespace Utility +{ + namespace ExH + { + namespace System + { + // This is the only way to make predefined exceptions like + // std::bad_alloc, etc to appear in the right place of the hierarchy. + // + + typedef std::exception Exception; + } + } +} + +#endif // UTILITY_EX_H_SYSTEM_EXCEPTION_HPP + + +//$Id$ diff --git a/contrib/utility/Utility/Hetero/Container.hpp b/contrib/utility/Utility/Hetero/Container.hpp new file mode 100644 index 00000000000..d28d5fff0c4 --- /dev/null +++ b/contrib/utility/Utility/Hetero/Container.hpp @@ -0,0 +1,182 @@ +// file : Utility/Hetero/Container.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_HETERO_CONTAINER_HPP +#define UTILITY_HETERO_CONTAINER_HPP + +#include + +namespace Utility +{ + namespace Hetero + { + // + // + // + class Typing {}; + + // + // + // + class Container + { + public: + ~Container () + { + delete holder_; + } + + public: + template + Container (T const& t) + : holder_ (new TypedHolder (t)) + { + } + + Container (Container const& c) + : holder_ (c.holder_->clone ()) + { + } + + public: + template + Container& + operator= (T const& t) + { + delete holder_; + holder_ = 0; + holder_ = new TypedHolder (t); + return *this; + } + + Container& + operator= (Container const& c) + { + delete holder_; + holder_ = 0; + holder_ = c.holder_->clone (); + return *this; + } + + public: + template + operator T& () + { + return value (); + } + + template + operator T const& () const + { + return value (); + } + + public: + template + T& + value () + { + if (holder_->type () == typeid (T)) + { + return dynamic_cast*>(holder_)->value (); + } + else + { + throw Typing (); + } + } + + template + T const& + value () const + { + if (holder_->type () == typeid (T)) + { + return dynamic_cast*>(holder_)->value (); + } + else + { + throw Typing (); + } + } + + public: + std::type_info const& + type () const + { + return holder_->type (); + } + + public: + template + friend T + operator+ (Container const& a, T const& b) + { + return a.value () + b; + } + + template + friend T + operator+ (T const& a, Container const& b) + { + return a + b.value (); + } + + private: + struct Holder + { + virtual + ~Holder () {} + + virtual Holder* + clone () const = 0; + + virtual std::type_info const& + type () const = 0; + }; + + template + struct TypedHolder : public Holder + { + TypedHolder (T const& value) + : value_ (value) + { + } + + virtual Holder* + clone () const + { + return new TypedHolder (value_); + } + + virtual std::type_info const& + type () const + { + return typeid (T); + } + + T const& + value () const + { + return value_; + } + + T& + value () + { + return value_; + } + + private: + T value_; + }; + + Holder* holder_; + }; + } +} + +#endif // UTILITY_HETERO_CONTAINER_HPP +//$Id$ diff --git a/contrib/utility/Utility/Hetero/Shell.hpp b/contrib/utility/Utility/Hetero/Shell.hpp new file mode 100644 index 00000000000..0d37a6ba09d --- /dev/null +++ b/contrib/utility/Utility/Hetero/Shell.hpp @@ -0,0 +1,86 @@ +// file : Utility/Hetero/Shell.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_HETERO_SHELL_HPP +#define UTILITY_HETERO_SHELL_HPP + +namespace Utility +{ + namespace Hetero + { + + // + // + // + class ShellCore + { + protected: + template + static typename F::RetType + apply (F& f, TypedContainer >& c) + { + if (type_check (c)) return type_apply (f, c); + + throw Utility::Hetero::Typing (); + } + + template + static typename F::RetType + apply (F& f, TypedContainer >& c) + { + if (type_check (c)) return type_apply (f, c); + if (type_check (c)) return type_apply (f, c); + + throw Utility::Hetero::Typing (); + } + + template + static typename F::RetType + apply (F& f, TypedContainer >& c) + { + if (type_check (c)) return type_apply (f, c); + if (type_check (c)) return type_apply (f, c); + if (type_check (c)) return type_apply (f, c); + + throw Utility::Hetero::Typing (); + } + + private: + template + static bool + type_check (Container& c) + { + return c.type () == typeid (T); + } + + template + static typename F::RetType + type_apply (F& f, Container& c) + { + return f (c. template value ()); + } + }; + + + // + // + // + template + struct Shell : F, ShellCore + { + using F::operator (); + + template + typename F::RetType + operator () (TypedContainer& p) + { + return apply (*this, p); + } + }; + } +} + +#endif // UTILITY_HETERO_SHELL_HPP +//$Id$ diff --git a/contrib/utility/Utility/Hetero/TypeList.hpp b/contrib/utility/Utility/Hetero/TypeList.hpp new file mode 100644 index 00000000000..ee7e96c2bcd --- /dev/null +++ b/contrib/utility/Utility/Hetero/TypeList.hpp @@ -0,0 +1,46 @@ +// file : Utility/Hetero/TypeList.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_HETERO_TYPE_LIST_HPP +#define UTILITY_HETERO_TYPE_LIST_HPP + +namespace Utility +{ + namespace Hetero + { + class NullType {}; + + template + struct TypeList + { + typedef t0 T0; + typedef t1 T1; + typedef t2 T2; + }; + + template + struct TypeList + { + typedef t0 T0; + typedef t1 T1; + }; + + template + struct TypeList + { + typedef t0 T0; + }; + + template <> + struct TypeList + { + }; + } +} + +#endif // UTILITY_HETERO_TYPE_LIST_HPP +//$Id$ diff --git a/contrib/utility/Utility/Hetero/TypedContainer.hpp b/contrib/utility/Utility/Hetero/TypedContainer.hpp new file mode 100644 index 00000000000..67f94bda0ec --- /dev/null +++ b/contrib/utility/Utility/Hetero/TypedContainer.hpp @@ -0,0 +1,57 @@ +// file : Utility/Hetero/TypedContainer.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_HETERO_TYPED_CONTAINER_HPP +#define UTILITY_HETERO_TYPED_CONTAINER_HPP + +#include "Utility/Hetero/Container.hpp" +#include "Utility/Hetero/TypeList.hpp" + +namespace Utility +{ + namespace Hetero + { + template + class TypedContainer : public Container + { + public: + typedef TL Types; + + public: + template + TypedContainer (T const& t) + : Container (t) + { + } + + TypedContainer (TypedContainer const& c) + : Container (static_cast (c)) + { + } + + public: + template + TypedContainer& + operator= (T const& t) + { + Container& self = *this; + self = t; + return *this; + } + + TypedContainer& + operator= (TypedContainer const& c) + { + Container& self = *this; + Container const& other = c; + self = other; + return *this; + } + }; + } +} + +#endif // UTILITY_HETERO_TYPED_CONTAINER_HPP +//$Id$ diff --git a/contrib/utility/Utility/Hetero/Vector.hpp b/contrib/utility/Utility/Hetero/Vector.hpp new file mode 100644 index 00000000000..3826bd6bb1f --- /dev/null +++ b/contrib/utility/Utility/Hetero/Vector.hpp @@ -0,0 +1,47 @@ +// file : Utility/Hetero/Vector.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_HETERO_VECTOR_HPP +#define UTILITY_HETERO_VECTOR_HPP + +#include + +#include "Utility/Hetero/TypeList.hpp" +#include "Utility/Hetero/TypedContainer.hpp" + +namespace Utility +{ + namespace Hetero + { + template + class Vector; + + template <> + class Vector; + + template + class Vector : + public std::vector > > + { + }; + + template + class Vector : + public std::vector > > + { + }; + + template + class Vector : + public std::vector > > + { + }; + } +} + +#endif // UTILITY_HETERO_VECTOR_HPP +//$Id$ diff --git a/contrib/utility/Utility/Introspection/Introspection.hpp b/contrib/utility/Utility/Introspection/Introspection.hpp new file mode 100644 index 00000000000..d514f62837a --- /dev/null +++ b/contrib/utility/Utility/Introspection/Introspection.hpp @@ -0,0 +1,14 @@ +// file : Utility/Introspection/Introspection.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_INTROSPECTION_INTROSPECTION_HPP +#define UTILITY_INTROSPECTION_INTROSPECTION_HPP + +#include "Utility/Introspection/TypeId.hpp" +#include "Utility/Introspection/TypeInfo.hpp" +#include "Utility/Introspection/Object.hpp" + +#endif // UTILITY_INTROSPECTION_INTROSPECTION_HPP +//$Id$ diff --git a/contrib/utility/Utility/Introspection/Makefile b/contrib/utility/Utility/Introspection/Makefile new file mode 100644 index 00000000000..43f2f67cb51 --- /dev/null +++ b/contrib/utility/Utility/Introspection/Makefile @@ -0,0 +1,19 @@ +# file : Utility/Introspection/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Archive.pre.rules) + +cxx_translation_units := TypeId.cpp Object.cpp + +module_base := Introspection + +CXX_PREPROCESS_FLAGS += -I $(root) + +$(call include, $(root)/BuildRules/Archive.post.rules) +# $Id$ diff --git a/contrib/utility/Utility/Introspection/Object.cpp b/contrib/utility/Utility/Introspection/Object.cpp new file mode 100644 index 00000000000..015a2736aad --- /dev/null +++ b/contrib/utility/Utility/Introspection/Object.cpp @@ -0,0 +1,24 @@ +// file : Utility/Introspection/Object.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/Introspection/Object.hpp" + +namespace Utility +{ + namespace Introspection + { + namespace + { + TypeInfo object_ (typeid (Object)); + } + + TypeInfo const& Object:: + static_type_info () throw () + { + return object_; + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/Introspection/Object.hpp b/contrib/utility/Utility/Introspection/Object.hpp new file mode 100644 index 00000000000..fdf8228c9f3 --- /dev/null +++ b/contrib/utility/Utility/Introspection/Object.hpp @@ -0,0 +1,47 @@ +// file : Utility/Introspection/Object.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_INTROSPECTION_OBJECT_HPP +#define UTILITY_INTROSPECTION_OBJECT_HPP + +#include "Utility/Introspection/TypeInfo.hpp" + +namespace Utility +{ + namespace Introspection + { + class Object + { + public: + static TypeInfo const& + static_type_info () throw (); + + virtual TypeInfo const& + type_info () const throw (); + + protected: + virtual + ~Object (); + + Object () throw (); + Object (Object const&) throw (); + + Object& + operator= (Object const&) throw (); + + protected: + virtual void + type_info (TypeInfo const& tid) throw (); + + private: + TypeInfo const* type_info_; + }; + } +} + +#include "Utility/Introspection/Object.ipp" + +#endif // UTILITY_INTROSPECTION_OBJECT_HPP +//$Id$ diff --git a/contrib/utility/Utility/Introspection/Object.ipp b/contrib/utility/Utility/Introspection/Object.ipp new file mode 100644 index 00000000000..7b5de978c6e --- /dev/null +++ b/contrib/utility/Utility/Introspection/Object.ipp @@ -0,0 +1,48 @@ +// file : Utility/Introspection/Object.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace Introspection + { + inline TypeInfo const& Object:: + type_info () const throw () + { + return *type_info_; + } + + inline Object:: + ~Object () + { + } + + inline Object:: + Object () throw () + { + type_info (static_type_info ()); + } + + + inline Object:: + Object (Object const&) throw () + { + type_info (static_type_info ()); + } + + + inline Object& Object:: + operator= (Object const&) throw () + { + return *this; + } + + inline void Object:: + type_info (TypeInfo const& tid) throw () + { + type_info_ = &tid; + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/Introspection/TypeId.cpp b/contrib/utility/Utility/Introspection/TypeId.cpp new file mode 100644 index 00000000000..a0ceddac2a1 --- /dev/null +++ b/contrib/utility/Utility/Introspection/TypeId.cpp @@ -0,0 +1,21 @@ +// file : Utility/Introspection/TypeId.cpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/Introspection/TypeId.hpp" + +#include + +namespace Utility +{ + namespace Introspection + { + std::ostream& + operator << (std::ostream& os, TypeId const& t) + { + return os << t.tid_->name (); + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/Introspection/TypeId.hpp b/contrib/utility/Utility/Introspection/TypeId.hpp new file mode 100644 index 00000000000..51f66f99a0b --- /dev/null +++ b/contrib/utility/Utility/Introspection/TypeId.hpp @@ -0,0 +1,47 @@ +// file : Utility/Introspection/TypeId.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_INTROSPECTION_TYPE_ID_HPP +#define UTILITY_INTROSPECTION_TYPE_ID_HPP + +#include +#include + +namespace Utility +{ + namespace Introspection + { + class TypeId + { + public: + template + TypeId (T const& t); + + TypeId (std::type_info const& tid); + + public: + bool + operator == (TypeId const& other) const; + + bool + operator != (TypeId const& other) const; + + bool + operator < (TypeId const& other) const; + + friend std::ostream& + operator << (std::ostream& os, TypeId const& t); + + private: + std::type_info const* tid_; + }; + } +} + +#include "Utility/Introspection/TypeId.tpp" +#include "Utility/Introspection/TypeId.ipp" + +#endif // UTILITY_INTROSPECTION_TYPE_ID_HPP +//$Id$ diff --git a/contrib/utility/Utility/Introspection/TypeId.ipp b/contrib/utility/Utility/Introspection/TypeId.ipp new file mode 100644 index 00000000000..83a5a503517 --- /dev/null +++ b/contrib/utility/Utility/Introspection/TypeId.ipp @@ -0,0 +1,37 @@ +// file : Utility/Introspection/TypeId.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html +// cvs-id : $Id$ + +namespace Utility +{ + namespace Introspection + { + inline TypeId:: + TypeId (std::type_info const& tid) + : tid_ (&tid) + { + } + + + inline bool TypeId:: + operator == (TypeId const& other) const + { + return *tid_ == *other.tid_; + } + + inline bool TypeId:: + operator != (TypeId const& other) const + { + return *tid_ != *other.tid_; + } + + inline bool TypeId:: + operator < (TypeId const& other) const + { + return tid_->before (*other.tid_); + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/Introspection/TypeId.tpp b/contrib/utility/Utility/Introspection/TypeId.tpp new file mode 100644 index 00000000000..7c3daef603c --- /dev/null +++ b/contrib/utility/Utility/Introspection/TypeId.tpp @@ -0,0 +1,18 @@ +// file : Utility/Introspection/TypeId.tpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace Introspection + { + template + inline TypeId:: + TypeId (T const& t) + : tid_ (&typeid (t)) + { + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/Introspection/TypeInfo.hpp b/contrib/utility/Utility/Introspection/TypeInfo.hpp new file mode 100644 index 00000000000..4321fdc522c --- /dev/null +++ b/contrib/utility/Utility/Introspection/TypeInfo.hpp @@ -0,0 +1,104 @@ +// file : Utility/Introspection/TypeInfo.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_INTROSPECTION_TYPE_INFO_HPP +#define UTILITY_INTROSPECTION_TYPE_INFO_HPP + +#include + +#include "Utility/Introspection/TypeId.hpp" + +namespace Utility +{ + namespace Introspection + { + // + // + // + struct Access + { + enum Value + { + PRIVATE, + PROTECTED, + PUBLIC + }; + }; + + // Forward declaration of class TypeInfo. + // + // + class TypeInfo; + + // + // + // + class BaseInfo + { + public: + BaseInfo (Access::Value access, + bool virtual_base, + TypeInfo const& ti); + + public: + TypeInfo const& + type_info () const; + + Access::Value + access () const; + + bool + virtual_base () const; + + private: + TypeInfo const* ti_; + bool virtual_base_; + Access::Value access_; + }; + + + // + // + // + class TypeInfo + { + private: + typedef + std::vector + BaseInfoList; + + public: + typedef + BaseInfoList::const_iterator + BaseIterator; + + public: + TypeInfo (TypeId const& tid); + + TypeId + type_id () const; + + BaseIterator + begin_base () const; + + BaseIterator + end_base () const; + + void + add_base (Access::Value access, + bool virtual_base, + TypeInfo const& ti); + + private: + TypeId tid_; + BaseInfoList base_; + }; + } +} + +#include "Utility/Introspection/TypeInfo.ipp" + +#endif // UTILITY_INTROSPECTION_TYPE_INFO_HPP +//$Id$ diff --git a/contrib/utility/Utility/Introspection/TypeInfo.ipp b/contrib/utility/Utility/Introspection/TypeInfo.ipp new file mode 100644 index 00000000000..395cf7d6539 --- /dev/null +++ b/contrib/utility/Utility/Introspection/TypeInfo.ipp @@ -0,0 +1,77 @@ +// file : Utility/Introspection/TypeInfo.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace Introspection + { + // BaseInfo + // + // + + inline BaseInfo:: + BaseInfo (Access::Value access, bool virtual_base, TypeInfo const& ti) + : ti_ (&ti), + virtual_base_ (virtual_base), + access_ (access) + { + } + + inline TypeInfo const& BaseInfo:: + type_info () const + { + return *ti_; + } + + + inline Access::Value BaseInfo:: + access () const + { + return access_; + } + + inline bool BaseInfo:: + virtual_base () const + { + return virtual_base_; + } + + + // TypeInfo + // + // + inline TypeInfo:: + TypeInfo (TypeId const& tid) + : tid_ (tid) + { + } + + inline TypeId TypeInfo:: + type_id () const + { + return tid_; + } + + inline TypeInfo::BaseIterator TypeInfo:: + begin_base () const + { + return base_.begin (); + } + + + inline TypeInfo::BaseIterator TypeInfo:: + end_base () const + { + return base_.end (); + } + + inline void TypeInfo:: + add_base (Access::Value access, bool virtual_base, TypeInfo const& ti) + { + base_.push_back (BaseInfo (access, virtual_base, ti)); + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/Makefile b/contrib/utility/Utility/Makefile new file mode 100644 index 00000000000..e6951f317fa --- /dev/null +++ b/contrib/utility/Utility/Makefile @@ -0,0 +1,16 @@ +# file : Utility/Makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := .. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Recursion.pre.rules) + +target_makefile_list := +target_directory_list := Introspection + +$(call include, $(root)/BuildRules/Recursion.post.rules) +# $Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/DefaultImpl.hpp b/contrib/utility/Utility/ReferenceCounting/DefaultImpl.hpp new file mode 100644 index 00000000000..43160c09a03 --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/DefaultImpl.hpp @@ -0,0 +1,96 @@ +// file : Utility/ReferenceCounting/DefaultImpl.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_DEFAULT_IMPL_HPP +#define UTILITY_REFERENCE_COUNTING_DEFAULT_IMPL_HPP + +#include "Utility/ExH/Compound.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +#include "Utility/Synch/Policy/Null.hpp" + +#include "Utility/ReferenceCounting/Interface.hpp" + +namespace Utility +{ + namespace ReferenceCounting + { + // Default reference counter implementation with parameterised + // synchronization policy. It is assumed that none of the SynchPolicy + // types throw any logic exceptions. If in fact they do then these + // exceptions won't be handled and will be automatically converted + // to system exceptions. + + template + class DefaultImpl : public virtual Interface + { + public: + class InconsistentState_ {}; + typedef + ExH::Compound + InconsistentState; + + public: + DefaultImpl () throw (SystemException); + + virtual + ~DefaultImpl () throw (); + + public: + virtual void + add_ref () const throw (Exception, SystemException); + + virtual void + remove_ref () const throw (); + + virtual count_t + refcount_value () const throw (Exception, SystemException); + + protected: + virtual void + add_ref_i () const throw (Exception, SystemException); + + virtual bool + remove_ref_i () const throw (Exception, SystemException); + + virtual count_t + refcount_value_i () const throw (Exception, SystemException); + + typename SynchPolicy::Mutex& + lock_i () const throw (); + + protected: + typedef + typename SynchPolicy::Mutex + Mutex_; + + typedef + typename SynchPolicy::ReadGuard + ReadGuard_; + + typedef + typename SynchPolicy::WriteGuard + WriteGuard_; + + protected: + mutable count_t ref_count_; + + private: + mutable Mutex_ lock_; + + private: + // Copy semanic is not supported. + DefaultImpl (DefaultImpl const&) throw (); + DefaultImpl& + operator= (DefaultImpl const&) throw (); + }; + } +} + +#include "Utility/ReferenceCounting/DefaultImpl.ipp" + +#endif // UTILITY_REFERENCE_COUNTING_DEFAULT_IMPL_HPP + +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/DefaultImpl.ipp b/contrib/utility/Utility/ReferenceCounting/DefaultImpl.ipp new file mode 100644 index 00000000000..bac28c77ea2 --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/DefaultImpl.ipp @@ -0,0 +1,105 @@ +// file : Utility/ReferenceCounting/DefaultImpl.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + // c-tor & d-tor + + template + DefaultImpl:: + DefaultImpl () throw (Interface::SystemException) + : ref_count_ (1), + lock_ () + { + } + + template + DefaultImpl:: + ~DefaultImpl () throw () + { + } + + // add_ref, remove_ref and refcount_value member functions + + template + void DefaultImpl:: + add_ref () const throw (Exception, SystemException) + { + WriteGuard_ guard (lock_); + add_ref_i (); + } + + template + void DefaultImpl:: + remove_ref () const throw () + { + bool destroy (false); + try + { + WriteGuard_ guard (lock_); + destroy = remove_ref_i (); + } + catch (...) + { + // there is nothing we can do + } + + if (destroy) delete this; + } + + template + Interface::count_t DefaultImpl:: + refcount_value () const throw (Exception, SystemException) + { + ReadGuard_ guard (lock_); + return refcount_value_i (); + } + + // add_ref_i, remove_ref_i and refcount_value_i member functions + + template + void DefaultImpl:: + add_ref_i () const throw (Exception, SystemException) + { + ref_count_++; + } + + template + bool DefaultImpl:: + remove_ref_i () const throw (Exception, SystemException) + { + bool destroy (false); + if (ref_count_ > 0) + { + if (--ref_count_ == 0) destroy = true; + } + else + { + throw InconsistentState ( + "Utility::ReferenceCounting::DefaultImpl::_remove_ref_i: " + "reference counter is zero."); + } + return destroy; + + } + + template + Interface::count_t DefaultImpl:: + refcount_value_i () const throw (Exception, SystemException) + { + return ref_count_; + } + + template + typename SynchPolicy::Mutex& DefaultImpl:: + lock_i() const throw () + { + return lock_; + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/ExternalLockImpl.hpp b/contrib/utility/Utility/ReferenceCounting/ExternalLockImpl.hpp new file mode 100644 index 00000000000..20346e859b3 --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/ExternalLockImpl.hpp @@ -0,0 +1,60 @@ +// file : Utility/ReferenceCounting/ExternalLockImpl.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_EXTERNAL_LOCK_IMPL_HPP +#define UTILITY_REFERENCE_COUNTING_EXTERNAL_LOCK_IMPL_HPP + +namespace Utility +{ + namespace ReferenceCounting + { + + /* + + Not ported yet. + + class ExternalLockRefCounter : public virtual Util::RefCountBase + { + public: + ExternalLockRefCounter (ACE_Lock* lock = 0); + virtual ~ExternalLockRefCounter (); + + void init (ACE_Lock* lock); + + public: + + virtual void _add_ref (); + virtual void _remove_ref (); + virtual unsigned long _refcount_value (); + + protected: + + virtual void _add_ref_i (); + virtual bool _remove_ref_i (); + virtual unsigned long _refcount_value_i (); + + ACE_Lock* lock_i (); + + private: + + typedef ACE_Guard Guard_; + + ACE_Lock* lock_; + unsigned long ref_count_; + + private: + ExternalLockRefCounter (const ExternalLockRefCounter& ); + void operator= (const ExternalLockRefCounter& ); + }; + + */ + } +} + +#include "Utility/ReferenceCounting/ExternalLockImpl.ipp" + +#endif // UTILITY_REFERENCE_COUNTING_EXTERNAL_LOCK_IMPL_HPP + +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/ExternalLockImpl.ipp b/contrib/utility/Utility/ReferenceCounting/ExternalLockImpl.ipp new file mode 100644 index 00000000000..7552d411f27 --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/ExternalLockImpl.ipp @@ -0,0 +1,122 @@ +// file : Utility/ReferenceCounting/ExternalLockImpl.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + /* + inline + ExternalLockRefCounter::ExternalLockRefCounter (ACE_Lock* lock) + : lock_ (lock), + ref_count_ (1) + { + } + + inline + void + ExternalLockRefCounter::init (ACE_Lock* lock) + { + lock_ = lock; + } + + inline + ExternalLockRefCounter::~ExternalLockRefCounter () + { + } + + inline + ACE_Lock* + ExternalLockRefCounter::lock_i () + { + return lock_; + } + + inline + void + ExternalLockRefCounter::_add_ref () + { + if (lock_) + { + Guard_ guard (*lock_); + _add_ref_i (); + } + else + { + _add_ref_i (); + } + } + + inline + void + ExternalLockRefCounter::_remove_ref () + { + bool destroy = false; + { + if (lock_) + { + Guard_ guard (*lock_); + destroy = _remove_ref_i (); + } + else + { + destroy = _remove_ref_i (); + } + } + if (destroy) delete this; + } + + inline + unsigned long + ExternalLockRefCounter::_refcount_value () + { + if (lock_) + { + Guard_ guard (*lock_); + return _refcount_value_i (); + } + else + { + return _refcount_value_i (); + } + } + + inline + void + ExternalLockRefCounter::_add_ref_i () + { + ref_count_++; + } + + inline + bool + ExternalLockRefCounter::_remove_ref_i () + { + bool destroy = false; + if (ref_count_ > 0) + { + if (--ref_count_ == 0) destroy = true; + } + else + { + ACE_ERROR ((LM_ERROR, + "ExternalLockRefCounter::_remove_ref() " + " _remove_ref() called while ref_coundt == 0\n" + )); + } + return destroy; + } + + inline + unsigned long + ExternalLockRefCounter::_refcount_value_i () + { + return ref_count_; + } + */ + } +} + +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/Interface.hpp b/contrib/utility/Utility/ReferenceCounting/Interface.hpp new file mode 100644 index 00000000000..9231860b84a --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/Interface.hpp @@ -0,0 +1,84 @@ +// file : Utility/ReferenceCounting/Interface.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_INTERFACE_HPP +#define UTILITY_REFERENCE_COUNTING_INTERFACE_HPP + +#include "Utility/ExH/Compound.hpp" +#include "Utility/ExH/System/Exception.hpp" +#include "Utility/ExH/Logic/Exception.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +namespace Utility +{ + namespace ReferenceCounting + { + // Interface to a reference-countable object. Note that _remove_ref () + // member function has a no-throw semantic. Even though it can lead to + // a diagnostic loss it was made no-throw because it has a destructor + // semantic. + + class Interface + { + public: + typedef + unsigned long + count_t; + + typedef + ExH::System::Exception + SystemException; + + class Exception_ {}; + typedef + ExH::Compound + Exception; + + public: + virtual void + add_ref () const throw (Exception, SystemException) = 0; + + virtual void + remove_ref () const throw () = 0; + + virtual count_t + refcount_value () const throw (Exception, SystemException) = 0; + + protected: + Interface () throw (); + + virtual + ~Interface () throw (); + + protected: + virtual void + add_ref_i () const throw (Exception, SystemException) = 0; + + virtual bool + remove_ref_i () const throw (Exception, SystemException) = 0; + + virtual count_t + refcount_value_i () const throw (Exception, SystemException) = 0; + + private: + // Copy semanic is not supported. + Interface (Interface const&) throw (); + Interface& + operator= (Interface const&) throw (); + }; + + template + Type* + add_ref (Type* ptr) + throw (Interface::Exception, Interface::SystemException); + } +} + +#include "Utility/ReferenceCounting/Interface.tpp" +#include "Utility/ReferenceCounting/Interface.ipp" + +#endif // UTILITY_REFERENCE_COUNTING_INTERFACE_HPP + +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/Interface.ipp b/contrib/utility/Utility/ReferenceCounting/Interface.ipp new file mode 100644 index 00000000000..f901db4b248 --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/Interface.ipp @@ -0,0 +1,22 @@ +// file : Utility/ReferenceCounting/Interface.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + inline Interface:: + ~Interface () throw () + { + } + + inline Interface:: + Interface () throw () + { + } + } +} + +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/Interface.tpp b/contrib/utility/Utility/ReferenceCounting/Interface.tpp new file mode 100644 index 00000000000..6a6a1d2d263 --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/Interface.tpp @@ -0,0 +1,20 @@ +// file : Utility/ReferenceCounting/Interface.tpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + template + inline Type* + add_ref (Type* ptr) + throw (Interface::Exception, Interface::SystemException) + { + if (ptr != 0) ptr->add_ref (); + return ptr; + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/ReferenceCounting.hpp b/contrib/utility/Utility/ReferenceCounting/ReferenceCounting.hpp new file mode 100644 index 00000000000..a20fe0d888c --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/ReferenceCounting.hpp @@ -0,0 +1,16 @@ +// file : Utility/ReferenceCounting/ReferenceCounting.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_REFERENCE_COUNTING_HPP +#define UTILITY_REFERENCE_COUNTING_REFERENCE_COUNTING_HPP + +#include "Utility/ReferenceCounting/Interface.hpp" +#include "Utility/ReferenceCounting/DefaultImpl.hpp" +#include "Utility/ReferenceCounting/SmartPtr.hpp" +#include "Utility/ReferenceCounting/StrictPtr.hpp" + +#endif // UTILITY_REFERENCE_COUNTING_REFERENCE_COUNTING_HPP + +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/SmartPtr.hpp b/contrib/utility/Utility/ReferenceCounting/SmartPtr.hpp new file mode 100644 index 00000000000..682f0678ee1 --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/SmartPtr.hpp @@ -0,0 +1,103 @@ +// file : Utility/ReferenceCounting/SmartPtr.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_SMART_PTR_HPP +#define UTILITY_REFERENCE_COUNTING_SMART_PTR_HPP + +#include "Utility/ExH/Compound.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +#include "Utility/ReferenceCounting/Interface.hpp" + +namespace Utility +{ + namespace ReferenceCounting + { + template + class SmartPtr + { + public: + typedef + T + Type; + + class NotInitialized_ {}; + typedef + ExH::Compound + NotInitialized; + + public: + // c-tor's + + SmartPtr () throw (); + SmartPtr (Type* ptr) throw (); + SmartPtr (SmartPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + template + SmartPtr (SmartPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + // d-tor + + ~SmartPtr () throw (); + + // assignment & copy-assignment operators + + SmartPtr& + operator= (Type* ptr) throw (); + + SmartPtr& + operator= (SmartPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + template + SmartPtr& + operator= (SmartPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + //conversions + + operator Type* () const throw (); + + // accessors + + Type* + operator-> () const throw (NotInitialized); + + Type* + in () const throw (); + + Type* + retn() throw (); + + private: + Type* ptr_; + }; + + // Specialization of add_ref function for SmartPtr + template + T* + add_ref (SmartPtr const& ptr) + throw (Interface::Exception, Interface::SystemException); + + + // Dynamic type conversion function for SmartPtr's + template + D* + smart_cast (SmartPtr const& s) + throw (Interface::Exception, Interface::SystemException); + + // Acquisition function + template + SmartPtr + acquire (T* ptr) throw (Interface::Exception, Interface::SystemException); + } +} + +#include "Utility/ReferenceCounting/SmartPtr.tpp" + +#endif // UTILITY_REFERENCE_COUNTING_SMART_PTR_HPP +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/SmartPtr.tpp b/contrib/utility/Utility/ReferenceCounting/SmartPtr.tpp new file mode 100644 index 00000000000..6596c67f1b1 --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/SmartPtr.tpp @@ -0,0 +1,170 @@ +// file : Utility/ReferenceCounting/SmartPtr.tpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + // c-tor's & d-tor + + template + SmartPtr:: + SmartPtr () throw () + : ptr_ (0) + { + } + + template + SmartPtr:: + SmartPtr (Type* ptr) throw () + : ptr_ (ptr) + { + } + + template + SmartPtr:: + SmartPtr (SmartPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + : ptr_ (add_ref (s_ptr.in ())) + { + } + + template + template + SmartPtr:: + SmartPtr (SmartPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + : ptr_ (add_ref (s_ptr.in ())) + { + } + + + template + SmartPtr:: + ~SmartPtr () throw () + { + // This is an additional catch-all layer to protect from + // non-conformant Type. + try + { + if (ptr_ != 0) ptr_->remove_ref (); + } + catch (...) + { + } + } + + // operator= + + template + SmartPtr& SmartPtr:: + operator= (Type* ptr) throw () + { + if (ptr_ != 0) ptr_->remove_ref (); + ptr_ = ptr; + return *this; + } + + + template + SmartPtr& SmartPtr:: + operator= (SmartPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + { + Type* old_ptr (ptr_); + Type* new_ptr (add_ref (s_ptr.in ())); // this can throw + if (old_ptr != 0) old_ptr->remove_ref (); + + ptr_ = new_ptr; // commit + + return *this; + } + + + template + template + SmartPtr& SmartPtr:: + operator= (SmartPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + { + Type* old_ptr (ptr_); + Other* new_ptr (add_ref (s_ptr.in ())); // this can throw + if (old_ptr != 0) old_ptr->remove_ref (); + + ptr_ = new_ptr; // commit + + return *this; + } + + // conversions + + template + SmartPtr:: + operator T* () const throw () + { + return ptr_; + } + + + // accessors + + template + T* SmartPtr:: + operator-> () const throw (NotInitialized) + { + if (ptr_ == 0) + { + throw NotInitialized( + "Utility::ReferenceCounting::SmartPtr::operator-> : " + "unable to dereference NULL pointer."); + } + return ptr_; + } + + template + T* SmartPtr:: + in () const throw () + { + return ptr_; + } + + template + T* SmartPtr:: + retn() throw () + { + Type* ret (ptr_); + ptr_ = 0; + return ret; + } + + // Specialization of add_ref function for SmartPtr + template + T* + add_ref (SmartPtr const& ptr) + throw (Interface::Exception, Interface::SystemException) + { + // delegate to generic implementation + return add_ref (ptr.in ()); + } + + // Dynamic type conversion function for SmartPtr's + template + D* + smart_cast (SmartPtr const& s) + throw (Interface::Exception, Interface::SystemException) + { + return add_ref (dynamic_cast(s.in ())); + } + + // Acquisition function + template + SmartPtr + acquire (T* ptr) throw (Interface::Exception, Interface::SystemException) + { + return SmartPtr (ptr); + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/StrictPtr.hpp b/contrib/utility/Utility/ReferenceCounting/StrictPtr.hpp new file mode 100644 index 00000000000..c88c90d5e50 --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/StrictPtr.hpp @@ -0,0 +1,108 @@ +// file : Utility/ReferenceCounting/StrictPtr.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_REFERENCE_COUNTING_STRICT_PTR_HPP +#define UTILITY_REFERENCE_COUNTING_STRICT_PTR_HPP + +#include "Utility/ExH/Compound.hpp" +#include "Utility/ExH/Logic/DescriptiveException.hpp" + +#include "Utility/ReferenceCounting/Interface.hpp" + +namespace Utility +{ + namespace ReferenceCounting + { + template + class StrictPtr + { + public: + typedef + T + Type; + + class NotInitialized_ {}; + typedef + ExH::Compound + NotInitialized; + + public: + // c-tor's + + StrictPtr () throw (); + + explicit + StrictPtr (Type* ptr) throw (); + + StrictPtr (StrictPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + template + StrictPtr (StrictPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + // d-tor + + ~StrictPtr () throw (); + + // assignment & copy-assignment operators + + StrictPtr& + operator= (Type* ptr) throw (); + + StrictPtr& + operator= (StrictPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + template + StrictPtr& + operator= (StrictPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException); + + // conversions + + // Note: implicit conversion (operator Type* ()) is not supported. + + // comparison + + bool + operator== (Type* other) const throw (); + + bool + operator!= (Type* other) const throw (); + + // accessors + + Type* + operator-> () const throw (NotInitialized); + + Type* + in () const throw (); + + Type* + retn() throw (); + + private: + Type* ptr_; + }; + + // Specialization of add_ref function for StrictPtr + template + T* + add_ref (StrictPtr const& ptr) + throw (Interface::Exception, Interface::SystemException); + + // Dynamic type conversion function for StrictPtr's + template + StrictPtr + strict_cast (StrictPtr const& s) + throw (Interface::Exception, Interface::SystemException); + } +} + +#include "Utility/ReferenceCounting/StrictPtr.tpp" + +#endif // UTILITY_REFERENCE_COUNTING_STRICT_PTR_HPP + +//$Id$ diff --git a/contrib/utility/Utility/ReferenceCounting/StrictPtr.tpp b/contrib/utility/Utility/ReferenceCounting/StrictPtr.tpp new file mode 100644 index 00000000000..6a30188119c --- /dev/null +++ b/contrib/utility/Utility/ReferenceCounting/StrictPtr.tpp @@ -0,0 +1,167 @@ +// file : Utility/ReferenceCounting/StrictPtr.tpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ReferenceCounting + { + // c-tor's & d-tor + + template + StrictPtr:: + StrictPtr () throw () + : ptr_ (0) + { + } + + template + StrictPtr:: + StrictPtr (Type* ptr) throw () + : ptr_ (ptr) + { + } + + template + StrictPtr:: + StrictPtr (StrictPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + : ptr_ (add_ref (s_ptr.in ())) + { + } + + template + template + StrictPtr:: + StrictPtr (StrictPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + : ptr_ (add_ref (s_ptr.in ())) + { + } + + + template + StrictPtr:: + ~StrictPtr () throw () + { + // This is an additional catch-all layer to protect from + // non-conformant Type. + try + { + if (ptr_ != 0) ptr_->remove_ref (); + } + catch (...) + { + } + } + + // operator= + + template + StrictPtr& + StrictPtr::operator= (Type* ptr) throw () + { + if (ptr_ != 0) ptr_->remove_ref (); + ptr_ = ptr; + return *this; + } + + template + StrictPtr& StrictPtr:: + operator= (StrictPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + { + Type* old_ptr (ptr_); + Type* new_ptr (add_ref (s_ptr.in ())); // this can throw + if (old_ptr != 0) old_ptr->remove_ref (); + + ptr_ = new_ptr; // commit + + return *this; + } + + + template + template + StrictPtr& StrictPtr:: + operator= (StrictPtr const& s_ptr) + throw (Interface::Exception, Interface::SystemException) + { + Type* old_ptr (ptr_); + Other* new_ptr (add_ref (s_ptr.in ())); // this can throw + if (old_ptr != 0) old_ptr->remove_ref (); + + ptr_ = new_ptr; // commit + + return *this; + } + + // comparison + + template + bool StrictPtr:: + operator== (Type* other) const throw () + { + return ptr_ == other; + } + + template + bool StrictPtr:: + operator!= (Type* other) const throw () + { + return ptr_ != other; + } + + // accessors + + template + T* StrictPtr:: + operator-> () const throw (NotInitialized) + { + if (ptr_ == 0) + { + throw NotInitialized( + "Utility::ReferenceCounting::StrictPtr::operator-> : " + "unable to dereference NULL pointer."); + } + return ptr_; + } + + template + T* StrictPtr:: + in () const throw () + { + return ptr_; + } + + template + T* StrictPtr:: + retn() throw () + { + Type* ret (ptr_); + ptr_ = 0; + return ret; + } + + // Specialization of add_ref function for StrictPtr + template + T* + add_ref (StrictPtr const& ptr) + throw (Interface::Exception, Interface::SystemException) + { + // delegate to generic implementation + return add_ref (ptr.in ()); + } + + // Dynamic type conversion function for StrictPtr's + template + StrictPtr + strict_cast (StrictPtr const& s) + throw (Interface::Exception, Interface::SystemException) + { + return StrictPtr(add_ref (dynamic_cast(s.in ()))); + } + } +} +//$Id$ diff --git a/contrib/utility/Utility/Synch/Policy/Null.hpp b/contrib/utility/Utility/Synch/Policy/Null.hpp new file mode 100644 index 00000000000..cfc9c8f788e --- /dev/null +++ b/contrib/utility/Utility/Synch/Policy/Null.hpp @@ -0,0 +1,54 @@ +// file : Utility/Synch/Policy/Null.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_SYNCH_POLICY_NULL_HPP +#define UTILITY_SYNCH_POLICY_NULL_HPP + +namespace Utility +{ + namespace Synch + { + namespace Policy + { + + class NullMutex + { + }; + + class NullGuard + { + public: + explicit + NullGuard (NullMutex&) throw (); + + private: + NullGuard (NullGuard const&) throw (); + + NullGuard& + operator= (NullGuard const&) throw (); + }; + + struct Null + { + typedef + NullMutex + Mutex; + + typedef + NullGuard + ReadGuard; + + typedef + NullGuard + WriteGuard; + }; + } + } +} + +#include "Utility/Synch/Policy/Null.ipp" + +#endif // UTILITY_SYNCH_POLICY_NULL_HPP +//$Id$ diff --git a/contrib/utility/Utility/Synch/Policy/Null.ipp b/contrib/utility/Utility/Synch/Policy/Null.ipp new file mode 100644 index 00000000000..dbc4c78b698 --- /dev/null +++ b/contrib/utility/Utility/Synch/Policy/Null.ipp @@ -0,0 +1,20 @@ +// file : Utility/Synch/Policy/Null.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace Synch + { + namespace Policy + { + inline NullGuard:: + NullGuard (NullMutex&) throw () + { + } + } + } +} + +//$Id$ diff --git a/contrib/utility/Vault/StringConverter.hpp b/contrib/utility/Vault/StringConverter.hpp new file mode 100644 index 00000000000..0bcb94676b7 --- /dev/null +++ b/contrib/utility/Vault/StringConverter.hpp @@ -0,0 +1,27 @@ +// file : Utility/ExH/StringConverter.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_EX_H_STRING_CONVERTER_HPP +#define UTILITY_EX_H_STRING_CONVERTER_HPP + +#include + +#include "Utility/ExH/Converter.hpp" + +namespace Utility +{ + namespace ExH + { + template <> + char const* + converter (std::string const& t) throw (); + } +} + +#include "Utility/ExH/StringConverter.ipp" + +#endif // UTILITY_EX_H_STRING_CONVERTER_HPP + +//$Id$ diff --git a/contrib/utility/Vault/StringConverter.ipp b/contrib/utility/Vault/StringConverter.ipp new file mode 100644 index 00000000000..c508c8c752a --- /dev/null +++ b/contrib/utility/Vault/StringConverter.ipp @@ -0,0 +1,18 @@ +// file : Utility/ExH/StringConverter.ipp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace ExH + { + template <> + inline char const* + converter (std::string const& t) throw () + { + return t.c_str (); + } + } +} +//$Id$ diff --git a/contrib/utility/Vault/hetero/map b/contrib/utility/Vault/hetero/map new file mode 100644 index 00000000000..0a6113e5c31 --- /dev/null +++ b/contrib/utility/Vault/hetero/map @@ -0,0 +1,13 @@ +// file : Utility/hetero/map +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_HETERO_MAP +#define UTILITY_HETERO_MAP + +#include "Utility/hetero/map.hpp" + +#endif // UTILITY_HETERO_MAP + +// $Id$ diff --git a/contrib/utility/Vault/hetero/map.hpp b/contrib/utility/Vault/hetero/map.hpp new file mode 100644 index 00000000000..b6a3e920633 --- /dev/null +++ b/contrib/utility/Vault/hetero/map.hpp @@ -0,0 +1,249 @@ +// file : Utility/hetero/map.hpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#ifndef UTILITY_HETERO_MAP_HPP +#define UTILITY_HETERO_MAP_HPP + +#include +#include + +namespace Utility +{ + namespace hetero + { + template + class map + { + private: + struct ValueBase + { + virtual + ~ValueBase () {} + }; + + template + class Value : public ValueBase + { + public: + Value (T const& t) + : t_ (t) + { + } + + T t_; + }; + + typedef + std::map + ValueMap; + + typedef + typename std::map::value_type + ValueType; + + public: + + class Typing {}; + + template + struct type + { + typedef std::pair value_type; + }; + + template + struct Pair + { + First first; + + Pair () + : first (), + second_ (0) + { + } + + Pair (First const& k, ValueBase* v) + : first (k), + second_ (v) + { + } + + template + T& + second () throw (Typing) + { + Value* v = dynamic_cast*> (second_); + if (v == 0) throw Typing (); + + return v->t_; + } + + template + T const& + second () const throw (Typing) + { + Value* v = dynamic_cast*> (second_); + if (v == 0) throw Typing (); + + return v->t_; + } + + private: + ValueBase* second_; + }; + + friend + class iterator + { + public: + iterator (typename ValueMap::iterator const& i) + : i_ (i) + { + } + + public: + + Pair& + operator* () + { + current_ = Pair (i_->first, i_->second); + return current_; + } + + Pair* + operator-> () + { + current_ = Pair (i_->first, i_->second); + return ¤t_; + } + + public: + bool + operator== (iterator const& other) + { + return i_ == other.i_; + } + + bool + operator!= (iterator const& other) + { + return i_ != other.i_; + } + + private: + typename ValueMap::iterator i_; + Pair current_; + }; + + + friend + class const_iterator + { + public: + const_iterator (typename ValueMap::const_iterator const& i) + : i_ (i) + { + } + + public: + + Pair const& + operator* () + { + current_ = Pair (i_->first, i_->second); + return current_; + } + + Pair const* + operator-> () + { + current_ = Pair (i_->first, i_->second); + return ¤t_; + } + + public: + bool + operator== (const_iterator const& other) + { + return i_ == other.i_; + } + + bool + operator!= (const_iterator const& other) + { + return i_ != other.i_; + } + + private: + typename ValueMap::const_iterator i_; + Pair current_; + }; + + public: + iterator + begin () + { + return iterator (map_.begin ()); + } + + const_iterator + begin () const + { + return const_iterator (map_.begin ()); + } + + iterator + end () + { + return iterator (map_.end ()); + } + + const_iterator + end () const + { + return const_iterator (map_.end ()); + } + + public: + + template + bool + insert (std::pair const& x) + { + ValueType v (x.first, new Value (x.second)); + return map_.insert (v).second; + } + + template + bool + insert (Key const& k, T const& t) + { + ValueType v (k, new Value (t)); + return map_.insert (v).second; + } + + public: + iterator + find (Key const& k) + { + return iterator (map_.find (k)); + } + + const_iterator + find (Key const& k) const + { + return const_iterator (map_.find (k)); + } + + private: + ValueMap map_; + }; + } +} + +#include "Utility/hetero/map.tpp" + +#endif // UTILITY_HETERO_MAP_HPP +//$Id$ diff --git a/contrib/utility/Vault/hetero/map.tpp b/contrib/utility/Vault/hetero/map.tpp new file mode 100644 index 00000000000..f2e0dfe69b8 --- /dev/null +++ b/contrib/utility/Vault/hetero/map.tpp @@ -0,0 +1,12 @@ +// file : utility/hetero/map.tpp +// author : Boris Kolpackov +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +namespace Utility +{ + namespace hetero + { + } +} +//$Id$ diff --git a/contrib/utility/Version b/contrib/utility/Version new file mode 100644 index 00000000000..937a6c086f5 --- /dev/null +++ b/contrib/utility/Version @@ -0,0 +1,3 @@ +1.2.2 + +$Id$ diff --git a/contrib/utility/license.html b/contrib/utility/license.html new file mode 100644 index 00000000000..9563d7dadfd --- /dev/null +++ b/contrib/utility/license.html @@ -0,0 +1,79 @@ + + + + + + + + + kolpackov.net/license.html + + + + + + + + + + + + + +
+ + + + +
+ +

This software or documentation is provided 'as-is', without any + express or implied warranty. In no event will the author or contributors + be held liable for any damages arising from the use of this software + or documentation.

+ +

Permission is granted to anyone to use this software or documentation + for any purpose, including commercial applications, and to alter it and + redistribute it freely, subject to the following restrictions:

+ +
+ +

1. The origin of this software or documentation must not be + misrepresented; you must not claim that you wrote the original + software or documentation. If you use this software or + documentation in a product, an acknowledgment in the product + documentation would be appreciated but is not required.

+ +

2. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software or documentation. + Altered source versions may be contributed back to the author to be + integrated into the original software or documentation at the + author's discretion.

+ +

3. Neither this notice or reference to it nor any copyright, author or + contributor clause may be removed from or altered in any software + source distribution or documentation covered by this license.

+ +

4. Neither the name of the author, nor the names of contributors may be + used to endorse or promote products derived from this software or + documentation without specific prior written permission.

+ +
+ +
+
+ + + + -- cgit v1.2.1