Revision: 95
Author: roman_yakovenko
Date: 2006-05-15 00:09:55 -0700 (Mon, 15 May 2006)
ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=95&view=rev
Log Message:
-----------
adding rational library
Added Paths:
-----------
pyplusplus_dev/examples/pyboost_dev/pyboost/rational/
pyplusplus_dev/examples/pyboost_dev/pyboost/rational/generate_code.py
pyplusplus_dev/examples/pyboost_dev/pyboost/rational/rational_export.hpp
pyplusplus_dev/examples/pyboost_dev/pyboost/rational/rational_settings.py
pyplusplus_dev/examples/pyboost_dev/pyboost/rational/sconscript
Added: pyplusplus_dev/examples/pyboost_dev/pyboost/rational/generate_code.py
===================================================================
--- pyplusplus_dev/examples/pyboost_dev/pyboost/rational/generate_code.py (rev 0)
+++ pyplusplus_dev/examples/pyboost_dev/pyboost/rational/generate_code.py 2006-05-15 07:09:55 UTC (rev 95)
@@ -0,0 +1,100 @@
+#! /usr/bin/python
+# Copyright 2004 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)
+
+
+import os
+import sys
+import time
+import shutil
+import rational_settings
+from pygccxml import parser
+from pygccxml import declarations
+from pyplusplus import code_creators
+from pyplusplus import module_builder
+from pyplusplus.module_builder import call_policies
+
+LICENSE = """// Copyright 2004 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)
+"""
+
+class code_generator_t(object):
+ def __init__(self):
+ self.__file = os.path.join( rational_settings.working_dir, 'rational_export.hpp' )
+
+ self.__mb = module_builder.module_builder_t(
+ [ parser.create_cached_source_fc(
+ self.__file
+ , os.path.join( rational_settings.generated_files_dir, 'rational.xml' ) ) ]
+ , gccxml_path=rational_settings.gccxml.executable
+ , include_paths=[rational_settings.boost.include]
+ , define_symbols=rational_settings.defined_symbols
+ , undefine_symbols=rational_settings.undefined_symbols
+ , optimize_queries=False )
+
+ for f_decl in self.__mb.free_functions():
+ f_decl.alias = f_decl.name
+ f_decl.name = f_decl.demangled_name
+
+ self.__mb.run_query_optimizer()
+
+
+ def filter_declarations(self ):
+ self.__mb.global_ns.exclude()
+ rational = self.__mb.class_('rational<long>')
+ rational.include()
+
+ r_assign = rational.calldef( 'assign', recursive=False )
+ r_assign.call_policies = call_policies.return_self()
+
+ foperators = self.__mb.free_operators( lambda decl: 'rational<long>' in decl.decl_string )
+ foperators.include()
+
+ bad_rational = self.__mb.class_('bad_rational' )
+ bad_rational.include()
+
+ self.__mb.free_function( 'lcm<long>' ).include()
+ self.__mb.free_function( 'gcd<long>' ).include()
+
+ def prepare_decls( self ):
+ self.__mb.class_('rational<long>').alias = 'rational'
+
+ def customize_extmodule( self ):
+ global LICENSE
+ extmodule = self.__mb.code_creator
+ #beautifying include code generation
+ extmodule.license = LICENSE
+ extmodule.user_defined_directories.append( rational_settings.boost.include )
+ extmodule.user_defined_directories.append( rational_settings.working_dir )
+ extmodule.user_defined_directories.append( rational_settings.generated_files_dir )
+ extmodule.precompiled_header = 'boost/python.hpp'
+ extmodule.replace_included_headers( ['boost/rational.hpp'] )
+
+ def write_files( self ):
+ self.__mb.write_module( os.path.join( rational_settings.generated_files_dir, 'rational.pypp.cpp' ) )
+
+ def create(self):
+ start_time = time.clock()
+ self.filter_declarations()
+
+ self.prepare_decls()
+
+ self.__mb.build_code_creator( rational_settings.module_name )
+
+ self.customize_extmodule()
+ self.write_files( )
+ print 'time taken : ', time.clock() - start_time, ' seconds'
+
+def export():
+ cg = code_generator_t()
+ cg.create()
+
+if __name__ == '__main__':
+ export()
+ print 'done'
+
+
Added: pyplusplus_dev/examples/pyboost_dev/pyboost/rational/rational_export.hpp
===================================================================
--- pyplusplus_dev/examples/pyboost_dev/pyboost/rational/rational_export.hpp (rev 0)
+++ pyplusplus_dev/examples/pyboost_dev/pyboost/rational/rational_export.hpp 2006-05-15 07:09:55 UTC (rev 95)
@@ -0,0 +1,24 @@
+// Copyright 2004 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)
+
+#ifndef __rational_export_hpp__
+#define __rational_export_hpp__
+
+#include "boost/rational.hpp"
+
+namespace boost{ namespace detail{
+
+typedef boost::rational< long int > pyrational;
+
+inline void instantiate(){
+ sizeof( pyrational );
+ boost::gcd<long int>( 1, 1);
+ boost::lcm<long int>( 1, 1);
+}
+
+} }
+
+
+#endif//__rational_export_hpp__
\ No newline at end of file
Added: pyplusplus_dev/examples/pyboost_dev/pyboost/rational/rational_settings.py
===================================================================
--- pyplusplus_dev/examples/pyboost_dev/pyboost/rational/rational_settings.py (rev 0)
+++ pyplusplus_dev/examples/pyboost_dev/pyboost/rational/rational_settings.py 2006-05-15 07:09:55 UTC (rev 95)
@@ -0,0 +1,24 @@
+#! /usr/bin/python
+# Copyright 2004 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)
+
+import os
+import sys
+
+_script_dir = os.path.abspath( os.getcwd() )
+environment_path = os.path.realpath( os.path.join( _script_dir, '..', '..', '..', '..' ) )
+sys.path.append( environment_path )
+
+from environment import boost, scons, gccxml, python
+
+module_name = '_rational_'
+working_dir = _script_dir
+generated_files_dir = os.path.join( _script_dir, 'generated' )
+unittests_dir = os.path.join( _script_dir, '..', '..', 'unittests', 'rational' )
+
+defined_symbols = ['BOOST_NO_INCLASS_MEMBER_INITIALIZATION']
+undefined_symbols = [ '__MINGW32__' ]
+
+
\ No newline at end of file
Added: pyplusplus_dev/examples/pyboost_dev/pyboost/rational/sconscript
===================================================================
--- pyplusplus_dev/examples/pyboost_dev/pyboost/rational/sconscript (rev 0)
+++ pyplusplus_dev/examples/pyboost_dev/pyboost/rational/sconscript 2006-05-15 07:09:55 UTC (rev 95)
@@ -0,0 +1,35 @@
+#! /usr/bin/python
+# Copyright 2004 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)
+
+import os
+import sys
+import rational_settings
+
+Import( 'env' )
+
+def get_ccflags():
+ if sys.platform == 'win32':
+ return rational_settings.scons.ccflags \
+ + map( lambda ds: '/D%s' % ds, rational_settings.defined_symbols )
+ else:
+ return map( lambda ds: '-D' + ds, rational_settings.defined_symbols )
+
+def get_source_files():
+ source_files = filter( lambda s: s.endswith( '.cpp' ), os.listdir(rational_settings.generated_files_dir) )
+ return map( lambda fname: os.path.join( rational_settings.generated_files_dir, fname ), source_files )
+
+def get_target():
+ return os.path.join( rational_settings.generated_files_dir
+ , rational_settings.module_name + rational_settings.scons.suffix )
+
+local_env = env.Copy()
+local_env.Append( CPPPATH=[ rational_settings.generated_files_dir ] )
+local_env.Append( CCFLAGS=get_ccflags() )
+
+_rational_ = local_env.SharedLibrary( target=rational_settings.module_name
+ , source=get_source_files() )
+
+local_env.Install( '#unittests/rational', _rational_ )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|