[pygccxml-commit] SF.net SVN: pygccxml: [1198] pygccxml_dev/docs/example
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-12-05 14:49:42
|
Revision: 1198 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1198&view=rev Author: roman_yakovenko Date: 2007-12-05 06:49:45 -0800 (Wed, 05 Dec 2007) Log Message: ----------- upgrading example Modified Paths: -------------- pygccxml_dev/docs/example/example.hpp pygccxml_dev/docs/example/example.py Modified: pygccxml_dev/docs/example/example.hpp =================================================================== --- pygccxml_dev/docs/example/example.hpp 2007-12-05 07:42:42 UTC (rev 1197) +++ pygccxml_dev/docs/example/example.hpp 2007-12-05 14:49:45 UTC (rev 1198) @@ -1,4 +1,4 @@ -// Copyright 2004 Roman Yakovenko. +// Copyright 2004-2007 Roman Yakovenko. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -6,29 +6,61 @@ #ifndef example_hpp_12_10_2006 #define example_hpp_12_10_2006 +#include <vector> +#include <string> +#include <map> -namespace core{ namespace class_hierarchy{ +namespace unittests{ -class base_t{ -public: - virtual ~base_t(){}; +struct test_results{ + + enum status{ ok, fail, error }; + + typedef std::map< std::string, status > result_container; + + void update( const std::string& name, status result ){ + m_results[ name ] = result; + } + +private: + result_container m_results; }; - -class other_base_t{ + +struct test_case{ + + test_case( const std::string& name ) + : m_name( name ) + {} + + virtual void set_up(){} + + virtual void tear_down(){} + + virtual void run() = 0; + +private: + const std::string m_name; }; -class derived_public_t : public base_t{ +struct test_suite : public test_case{ + + typedef std::vector< test_case* > test_container; + + test_suite( const std::string& name, const test_container& tests ) + : test_case(name) + , m_tests( tests ) + {} + + virtual void run(); + + const test_results& get_results() const + { return m_results; } + +private: + const test_container m_tests; + test_results m_results; }; + +} -class derived_protected_t : protected base_t{ -}; - -class derived_private_t : private base_t{ -}; - -class multi_derived_t : derived_private_t, protected base_t, private other_base_t{ -}; - -} } - #endif//example_hpp_12_10_2006 Modified: pygccxml_dev/docs/example/example.py =================================================================== --- pygccxml_dev/docs/example/example.py 2007-12-05 07:42:42 UTC (rev 1197) +++ pygccxml_dev/docs/example/example.py 2007-12-05 14:49:45 UTC (rev 1198) @@ -3,24 +3,62 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +import os import sys -#~ sys.path.append('../..') #adding pygccxml to the path +#find out the file location within the sources tree +this_module_dir_path = os.path.abspath ( os.path.dirname( sys.modules[__name__].__file__) ) +#find out gccxml location +gccxml_09_path = os.path.join( this_module_dir_path, '..', '..', '..', 'gccxml_bin', 'v09', sys.platform, 'bin' ) +#add pygccxml package to Python path +sys.path.append( os.path.join( this_module_dir_path, '..', '..' ) ) + + from pygccxml import parser from pygccxml import declarations #configure GCC-XML parser -config = parser.config_t( gccxml_path='/home/roman/language-binding/sources/gccxml_bin/v09/linux2/bin' ) +config = parser.config_t( gccxml_path=gccxml_09_path ) #parsing source file decls = parser.parse( ['example.hpp'], config ) global_ns = declarations.get_global_namespace( decls ) -#printing all declarations found in file and its includes -declarations.print_declarations( global_ns ) +#get object that describes unittests namespace +unittests = global_ns.namespace( 'unittests' ) +print '"unittests" declarations: ' +declarations.print_declarations( unittests ) + + #print all base and derived class names -for class_ in global_ns.classes(): - print class_.name - print '\tbases: ', `[base.related_class.name for base in class_.bases]` - print '\tderived: ', `[derive.related_class.name for derive in class_.derived]` +for class_ in unittests.classes(): + print 'class "%s" hierarchy information:' % class_.name + print '\tbase classes : ', `[base.related_class.name for base in class_.bases]` + print '\tderived classes: ', `[derive.related_class.name for derive in class_.derived]` + print '\n' + + +#pygccxml has very powerfull query api: + +#select multiple declarations +run_functions = unittests.member_functions( 'run' ) +print 'the namespace contains %d "run" member functions' % len(run_functions) +print 'they are: ' +for f in run_functions: + print '\t' + declarations.full_name( f ) + + +#select single declaration - all next statements will return same object +#vector< unittests::test_case* > + +#you can select the class using "full" name +test_container_1 = global_ns.class_( 'vector<unittests::test_case*, std::allocator<unittests::test_case*> >' ) +#you can select the class using partial name +test_container_2 = global_ns.class_( 'vector< unittests::test_case* >' ) +#you can define your own "match" criteria +test_container_3 = global_ns.class_( lambda decl: 'vector' in decl.name ) + +is_same_object = test_container_1 is test_container_2 \ + and test_container_2 is test_container_3 +print "Does all test_container_* refer to the same object? ", str(is_same_object) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |