[pygccxml-commit] SF.net SVN: pygccxml: [644] pyplusplus_dev/docs
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-10-11 10:44:22
|
Revision: 644 http://svn.sourceforge.net/pygccxml/?rev=644&view=rev Author: roman_yakovenko Date: 2006-10-11 03:43:41 -0700 (Wed, 11 Oct 2006) Log Message: ----------- switching from :: ( rest preformated block ) to .. code-block:: Modified Paths: -------------- pygccxml_dev/docs/design.rest pygccxml_dev/docs/history/history.rest pygccxml_dev/docs/pygccxml.rest pygccxml_dev/docs/query_interface.rest pyplusplus_dev/docs/comparisons/pyste.rest pyplusplus_dev/docs/documentation/architecture.rest pyplusplus_dev/docs/documentation/best_practices.rest pyplusplus_dev/docs/documentation/containers.rest pyplusplus_dev/docs/documentation/doc_string.rest pyplusplus_dev/docs/documentation/feedback.rest pyplusplus_dev/docs/documentation/hints.rest pyplusplus_dev/docs/documentation/how_to.rest pyplusplus_dev/docs/documentation/inserting_code.rest pyplusplus_dev/docs/documentation/properties.rest pyplusplus_dev/docs/documentation/tutorials/module_builder/module_builder.rest pyplusplus_dev/docs/examples/boost/boost.rest pyplusplus_dev/docs/history/history.rest pyplusplus_dev/docs/peps/dsl_challenge.rest pyplusplus_dev/docs/peps/function_transformation.rest pyplusplus_dev/docs/peps/peps_index.rest pyplusplus_dev/docs/pyplusplus.rest Modified: pygccxml_dev/docs/design.rest =================================================================== --- pygccxml_dev/docs/design.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pygccxml_dev/docs/design.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -255,12 +255,15 @@ -------- Well, `GCC-XML`_ has few bugs, which could not be fixed from it. For example -:: +.. code-block:: C++ + namespace ns1{ namespace ns2{ enum fruit{ apple, orange }; } } +.. code-block:: C++ + void fix_enum( ns1::ns2::fruit arg=ns1::ns2::apple ); `GCC-XML`_ will report the default value of ``arg`` as ``apple``. Obviously Modified: pygccxml_dev/docs/history/history.rest =================================================================== --- pygccxml_dev/docs/history/history.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pygccxml_dev/docs/history/history.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -122,8 +122,9 @@ This has been done in order to provide stable order of enumeration values. 4. Now you can pass operator symbol, as a name to query functions: - :: + .. code-block:: Python + cls = global_namespace.class_( 'my_class' ) op = cls.operator( '<' ) #instead of @@ -154,8 +155,9 @@ of the same name in the decl interface from ``declarations.scopedef_t`` class. So for example: - :: + .. code-block:: Python + classes = ns.decls("class") classes.decls("method") Modified: pygccxml_dev/docs/pygccxml.rest =================================================================== --- pygccxml_dev/docs/pygccxml.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pygccxml_dev/docs/pygccxml.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -89,8 +89,9 @@ try to give small example, that will prove my point. If you want to know more about provided API please read `query interface`__ document or API documentation. Examples: -:: +.. code-block:: Python + #global_ns is the reference to declarations that describes C++ namespace. #In our case, instance of that declarations describes global ( :: ) namespace. global_ns.free_functions( "do_smth", return_type='void', arg_types=[None,'int'] ) @@ -98,14 +99,15 @@ Small explanation. Assume that ``None`` means "any type". Now the code is pretty readable: + :: - select all free functions - where - name equal to "do_smth" - return type is void - function has two arguments - second argument type is int + select all free functions from the project + where + name equal to "do_smth" + return type is void + function has two arguments + second argument type is int .. __: ./query_interface.html Modified: pygccxml_dev/docs/query_interface.rest =================================================================== --- pygccxml_dev/docs/query_interface.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pygccxml_dev/docs/query_interface.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -15,7 +15,7 @@ I don't care about first argument type, but I do want second argument type to be a reference to an integer. More over, I want those functions names to end with "impl" string and they should be protected or private. -:: +.. code-block:: Python #global_ns is the reference to an instance of namespace_t object, that #represents global namespace @@ -26,7 +26,7 @@ The example is complex, but still readable. In many cases you will find your self looking for one or many declarations using one or two properties of that declaration(s). For example: -:: +.. code-block:: Python global_ns.namespaces( 'details' ) @@ -53,7 +53,7 @@ I will explain the usage of ``member_function`` and ``member_functions`` methods. The usage of other methods is very similar to them. Here is definition of those methods: -:: +.. code-block:: Python def member_function( self, name=None, @@ -81,8 +81,9 @@ * ``name`` Python string, that contains member function name or full name. - :: + .. code-block:: Python + do_smth = my_class.member_function( 'do_smth' ) do_smth = my_class.member_function( 'my_namespace::my_class::do_smth' ) @@ -91,8 +92,9 @@ Python callable object. You would use this functionality, if you need to build custom query. This object will be called with one argument - declaration, and it should return ``True`` or ``False``. - :: + .. code-block:: Python + impls = my_class.member_functions( lambda decl: decl.name.endswith( 'impl' ) ) ``impls`` will contain all member functions, that their name ends with "impl". @@ -101,8 +103,9 @@ Function return type. This argument can be Python string or an object that describes C++ type. - :: + .. code-block:: Python + mem_funcs = my_class.member_functions( return_type='int' ) i = declarations.int_t() @@ -117,8 +120,9 @@ type. Size of list says how many arguments function should have. If you want to skip some argument type from within comparison, you put ``None``, into relevant position within the list. - :: + .. code-block:: Python + mem_funcs = my_class.member_functions( arg_types=[ None, 'int'] ) ``mem_funcs`` will contain all member functions, that have two arguments @@ -178,13 +182,16 @@ objects at once. I will give an example from another project - `Py++`_. In order to help `Boost.Python`_ to manage objects life time, all functions should have `call policies`_. For example: -:: +.. code-block:: C++ + struct A{ A* clone() const { return new A(); } ... }; +.. code-block:: C++ + struct B{ B* clone() const { return new B(); } ... @@ -193,8 +200,9 @@ `Call policies`_ of the member function ``clone`` is ``return_value_policy<manage_new_object>()``. Next code applies `call policies`_ on all ``clone`` member functions within the project. -:: +.. code-block:: Python + #global_ns - instance of namespace_t class, that contains reference to global namespace clone = global_ns.member_functions( 'clone' ) clone.call_policies = return_value_policy( manage_new_object ) @@ -210,7 +218,7 @@ class you don't have to write loops. If will do it for you. Also if you insist to write loops, ``mdecl_wrapper_t`` class implements ``__len__``, ``__getitem__`` and ``__iter__`` methods. So you can write next code: -:: +.. code-block:: Python for clone in global_ns.member_functions( 'clone' ): print clone.parent.name Modified: pyplusplus_dev/docs/comparisons/pyste.rest =================================================================== --- pyplusplus_dev/docs/comparisons/pyste.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/comparisons/pyste.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -185,12 +185,17 @@ * identify "call policies" algorithm * code creator that generates body of "overridden" virtual functions: - :: + .. code-block:: C++ + struct expensive_to_copy{...}; + .. code-block:: C++ + void do_smth( expensive_to_copy* x, const expensive_to_copy& y ){...} + .. code-block:: C++ + void do_smth(expensive_to_copy* x, const expensive_to_copy& y){ //Pyste generates next code @@ -326,16 +331,18 @@ those directories into account. * To define namespace alias. - :: + .. code-block:: C++ + namespace dt = boost::date_time; All code, which is generated after this statement, will use ``dt`` instead of ``boost::date_time``. This allows `Py++`_ to create user-friendly code. * Classes and functions support 2 modes of code generation. Example: - :: + .. code-block:: C++ + struct world{ void set(std::string msg) { this->msg = msg; } std::string greet() { return msg; } @@ -343,8 +350,9 @@ }; First mode: - :: + .. code-block:: C++ + class_<world>("world") .def("greet", &world::greet) .def("set", &world::set) @@ -352,8 +360,9 @@ Second mode: - :: + .. code-block:: C++ + if( true ){ typedef class_<world> world_exposer_t; world_exposer_t world_exposer; Modified: pyplusplus_dev/docs/documentation/architecture.rest =================================================================== --- pyplusplus_dev/docs/documentation/architecture.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/documentation/architecture.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -85,16 +85,16 @@ Before I explain how these services are integrated, take a look on next source code: -:: +.. code-block:: Python mb = module_builder_t( ... ) -:: +.. code-block:: Python details = mb.namespace( 'details' ) details.exclude() -:: +.. code-block:: Python my_class = mb.class_( 'my_class' ) my_class.rename("MyClass") @@ -229,7 +229,7 @@ Here is "cut & paste" of the relevant code from the source file: - :: + .. code-block:: Python def _create_impl(self): result = [] Modified: pyplusplus_dev/docs/documentation/best_practices.rest =================================================================== --- pyplusplus_dev/docs/documentation/best_practices.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/documentation/best_practices.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -41,7 +41,7 @@ ``module_builder_t.__init__`` methods takes reference to an instance of cache class or ``None``: - :: + .. code-block:: Python from module_builder import * mb = module_builder_t( ..., cache=file_cache_t( path to project cache file ), ... ) @@ -60,13 +60,12 @@ implemented an initial version of the functionality. After small discussion, we agreed on next interface: - :: + .. code-block:: Python class module_builder_t( ... ): ... def split_module( self, directory_path, huge_classes=None, precompiled_header=None ): ... - ... ``precompiled_header`` argument could be ``None`` or string, that contains name of precompiled header file, which will be created in the directory. @@ -78,7 +77,7 @@ `this error`_. `Py++`_ will automatically split generated code for the huge classes to few files: - :: + .. code-block:: Python mb = module_builder_t( ... ) ... Modified: pyplusplus_dev/docs/documentation/containers.rest =================================================================== --- pyplusplus_dev/docs/documentation/containers.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/documentation/containers.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -77,8 +77,9 @@ By default, `Py++`_ works with built-in indexing suite. If you want to use next version of indexing suite, you should tell this to the ``module_builder_t.__init__`` method: -:: +.. code-block:: Python + mb = module_builder_t( ..., indexing_suite_version=2 ) Every declared class has ``indexing_suite`` property. If the class is an @@ -121,8 +122,9 @@ In this case there is no single place, where you can configure exported container functionality. Please take a look on next C++ code: -:: +.. code-block:: C++ + struct item{ ... private: Modified: pyplusplus_dev/docs/documentation/doc_string.rest =================================================================== --- pyplusplus_dev/docs/documentation/doc_string.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/documentation/doc_string.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -15,7 +15,7 @@ API description --------------- -:: +.. code-block:: Python mb = module_builder_t( ... ) my_class = mb.class_( 'my_class' ) @@ -37,7 +37,7 @@ ``doc_extractor`` is a callable object, which takes one argument - reference to declaration. -:: +.. code-block:: Python def doc_extractor( decl ): ... Modified: pyplusplus_dev/docs/documentation/feedback.rest =================================================================== --- pyplusplus_dev/docs/documentation/feedback.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/documentation/feedback.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -24,27 +24,27 @@ them and in some cases provide hints about how to resolve the problem. Few examples: * - :: + .. code-block:: C++ - struct Y{ ... }; - + struct Y{ ... }; + + .. code-block:: C++ + struct X{ ... virtual Y& do_smth(); - ... }; Member function ``do_smth`` can not be overridden in Python because... [FILL IN HERE]. * - :: + .. code-block:: C++ struct window{ ... void get_size( int& heght, int& widht ) const; - ... }; - + Member function ``get_size`` can be exposed to Python, but it will not be callable because [FILL IN HERE]. * In order to expose free/member function that takes more than 10 arguments user @@ -80,12 +80,12 @@ 1. If you simply want to change the logging message level: - :: + .. code-block:: Python import logging from pyplusplus import module_builder - :: + .. code-block:: Python module_builder.set_logger_level( logging.DEBUG ) @@ -101,20 +101,15 @@ Both packages define a ``loggers`` class. Those classes keep references to different loggers. The ``loggers`` classes look very similar to the next class: - :: + .. code-block:: Python import logging #standard Python package - - :: - + def _create_logger_( name ): logger = logging.getLogger(name) ... return logger - - - :: - + class loggers: file_writer = _create_logger_( 'pyplusplus.file_writer' ) declarations = _create_logger_( 'pyplusplus.declarations' ) Modified: pyplusplus_dev/docs/documentation/hints.rest =================================================================== --- pyplusplus_dev/docs/documentation/hints.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/documentation/hints.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -12,23 +12,18 @@ template, than `Py++`_ will use it as a `Python`_ class name. For example: -:: - #include <vector> +.. code-block:: C++ -:: - + #include <vector> typedef std::vector< int > numbers; - -:: - numbers generate_n(){ ... } `Py++`_ will use "numbers" as Python class name: -:: +.. code-block:: C++ using boost::python; class_< std::vector< int > >( "numbers" ) Modified: pyplusplus_dev/docs/documentation/how_to.rest =================================================================== --- pyplusplus_dev/docs/documentation/how_to.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/documentation/how_to.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -7,17 +7,17 @@ ---------------------------------------- How to add custom exception translation? ---------------------------------------- -:: +.. code-block:: C++ + struct my_exception{ ... const std::string& error() const; - ... } First of all lets define ``translate`` function: -:: +.. code-block:: Python translate_code = \ """ @@ -26,14 +26,14 @@ } """ -:: +.. code-block:: Python mb.add_declaration_code( translate_code ) Now we should register it: -:: +.. code-block:: Python registration_code = "boost::python::register_exception_translator<my_exception>(&translate);" mb.add_registration_code( registration_code ) @@ -43,7 +43,7 @@ `Py++`_ allows you to define a query that will return you all exception classes: -:: +.. code-block:: Python mb = module_builder_t( ... ) exception_classes = mb.decls( lambda decl: decl.name.endswith( 'exception' ) ) @@ -56,25 +56,25 @@ ------------------------------------------------------- How to expose function, which has hand-written wrapper? ------------------------------------------------------- -:: +.. code-block:: C++ struct window_t{ ... void get_size( int& height, int& widht ) const; - ... }; You can not expose ``get_size`` function as is - ``int`` is immutable type in Python. So, we need to create a wrapper to the function: -:: +.. code-block:: C++ + boost::python::tuple get_size_wrapper( const window_t& win ){ int height(0), width( 0 ); win.get_size( height, widht ); return boost::python::make_tuple( height, width ); } -:: +.. code-block:: C++ class_<window_t>( ... ) .def( "get_size", &get_size_wrapper ) @@ -84,9 +84,8 @@ Now, after you know how this problem is solved. I will show how this solution could be integrated with `Py++`_. +.. code-block:: Python -:: - wrapper_code = \ """ static boost::python::tuple get_size( const window_t& win ){ @@ -96,11 +95,11 @@ } """ -:: +.. code-block:: Python registration_code = 'def( "get_size", &%s::get_size )' % window.wrapper_alias -:: +.. code-block:: Python mb = module_builder_t( ... ) window = mb.class_( "window_t" ) @@ -132,33 +131,21 @@ ------------------------------------------------------ Lets say you have next C++ function: -:: - //file point.h +.. code-block:: C++ -:: - + // file point.h namespace geometry{ - -:: - - template< class T> - struct point_t{ - T x, y; - }; - -:: - - template <class T> - double distance( const point_t<T>& point ){ - return sqrt( point.x * point.x + point.y*point.y ); - } - -:: - + template< class T> + struct point_t{ + T x, y; + }; + template <class T> + double distance( const point_t<T>& point ){ + return sqrt( point.x * point.x + point.y*point.y ); + } } //namespace geometry - You should understand, that you can not export template itself, but only its instantiations. The solution is built using next facts: @@ -174,11 +161,11 @@ Open your favorite editor and create a header file with the content: -:: +.. code-block:: C++ #include "point.h" -:: +.. code-block:: C++ namespace py_details{ inline void instantiate(){ @@ -194,7 +181,7 @@ ``module_builder_t.__init__`` method and excludes the ``py_details`` namespace declarations from being exported: -:: +.. code-block:: Python mb = module_builder_t( [..., just created file ], ... ) mb.namespace( 'py_details' ).exclude() @@ -207,20 +194,20 @@ The solution is to build your own code generator, which will generate code similar to the one, in the previous paragraph. -:: +.. code-block:: Python from module_builder import module_builder_t, create_text_fc -:: +.. code-block:: Python def generate_instantiations_string( ... ): ... -:: +.. code-block:: Python code = generate_instantiations_string( ... ) -:: +.. code-block:: Python mb = module_builder_t( [ ..., create_text_fc( code ) ], ... ) mb.namespace( 'py_details' ).exclude() @@ -246,7 +233,7 @@ --------------------------------------------------- How to deal with template on return type functions? --------------------------------------------------- -:: +.. code-block:: C++ struct environment_t{ ... @@ -269,8 +256,9 @@ Otherwise, you will discover the errors while testing the bindings. Generated code: -:: +.. code-block:: C++ + bp::class_< environment_t >( "environment_t" ) ... .def( "get_value" @@ -279,8 +267,9 @@ , (::std::string ( ::environment_t::* )( ::std::string const & ) )( &::environment_t::get_value ) ); The correct code: -:: +.. code-block:: C++ + bp::class_< environment_t >( "environment_t" ) .def( "get_value" , (int ( ::environment_t::* )( ::std::string const & ) )( &::environment_t::get_value< int > ) ) @@ -290,8 +279,9 @@ //------------------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^ The perfect one: -:: +.. code-block:: C++ + bp::class_< environment_t >( "environment_t" ) ... .def( "get_value", &::environment_t::get_value< int > ) @@ -299,7 +289,7 @@ Solution -------- -:: +.. code-block:: Python mb = module_builder_t( ..., optimize_queries=False, ... ) environment = mb.class_( "environment_t" ) Modified: pyplusplus_dev/docs/documentation/inserting_code.rest =================================================================== --- pyplusplus_dev/docs/documentation/inserting_code.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/documentation/inserting_code.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -18,7 +18,7 @@ Almost every ``Boost.Python`` module has next structure: -:: +.. code-block:: C++ //declarations code ... @@ -45,7 +45,7 @@ Example ------- -:: +.. code-block:: Python mb = module_builder_t( ... ) mb.build_code_creator( ... ) @@ -60,7 +60,7 @@ ``class_t`` declaration defines few methods, which add user code to the generated one. Lets take a look on next use case: -:: +.. code-block:: C++ struct window_t{ ... @@ -74,7 +74,7 @@ In the near future `Py++`_ will eliminate the need of creating hand written wrapper for this use case. -:: +.. code-block:: C++ boost::python::tuple get_window_size( const window_t& win ){ int h(0), w(0); @@ -84,7 +84,7 @@ Now you have to register it: -:: +.. code-block:: C++ using boost::python; class_< window_t >( ... ) @@ -112,15 +112,17 @@ What is ``works_on_instance`` argument for? In our case, we added new method to the class. The first argument of the call will be ``self``. - :: + .. code-block:: Python + #From Python user can call this method like this: win = window_t( ) height, width = win.get_size() If you will pass ``works_on_instance=False`` next code will be generated: - :: + .. code-block:: C++ + { class_< window_t > window_exporter( "window_t" ); scope window_scope( window_exporter ); @@ -129,16 +131,17 @@ } And in this case, user will be forced to pass reference to ``window_t`` object: - - :: + .. code-block:: C++ + win = window_t() height, width = window_t.get_size( win ) Example ------- -:: +.. code-block:: Python + mb = module_builder_t( ... ) window = mb.class_( 'window_t' ) window.add_declaration_code( get_window_size definition ) @@ -174,7 +177,7 @@ Solution -------- -:: +.. code-block:: Python def inject_code( cls ): constructors = cls.constructors() @@ -184,9 +187,9 @@ cls.add_wrapper_code( destructor declaration and definition code ) cls.add_wrapper_code( the new class variable definition code ) - -:: +.. code-block:: Python + mb = module_builder_t( ... ) for cls in mb.classes( relevant classes only ): inject_code( cls ) Modified: pyplusplus_dev/docs/documentation/properties.rest =================================================================== --- pyplusplus_dev/docs/documentation/properties.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/documentation/properties.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -18,8 +18,9 @@ ------------- Usage example ------------- -:: +.. code-block:: C++ + struct number{ ... float value() const; @@ -29,7 +30,7 @@ float m_value; } -:: +.. code-block:: Python mb = module_builder_t( ... ) number = mb.class_( 'number' ) @@ -41,8 +42,9 @@ This is rather the hard way to add properties to the class. `Py++`_ comes with built-in algorithm, which automaticly recognizes properties and adds them to the class: -:: +.. code-block:: Python + mb = module_builder_t( ... ) number = mb.class_( 'number' ) number.add_properties( exclude_accessors=False ) #accessors will be exposed @@ -61,10 +63,12 @@ Consider next use case: -:: +.. code-block:: C++ struct nested{ ... }; +.. code-block:: C++ + struct data{ ... const nested& get_nested() const @@ -78,7 +82,7 @@ `call policies`_. Same precondition holds for exposing member function as property: -:: +.. code-block:: Python mb = module_builder_t( ... ) get_nested = mb.member_function( 'get_nested' ) Modified: pyplusplus_dev/docs/documentation/tutorials/module_builder/module_builder.rest =================================================================== --- pyplusplus_dev/docs/documentation/tutorials/module_builder/module_builder.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/documentation/tutorials/module_builder/module_builder.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -118,7 +118,7 @@ open source projects it to have license text within every source file. You can do it with one line of code only: -:: +.. code-block:: Python mb.code_creator.license = your license text Modified: pyplusplus_dev/docs/examples/boost/boost.rest =================================================================== --- pyplusplus_dev/docs/examples/boost/boost.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/examples/boost/boost.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -85,19 +85,15 @@ * Python code: - :: + .. code-block:: Python import time from pyboost import boost_random - - :: - + rng = boost_random.mt19937( int( time.time() ) ) #setting initial seed six = boost_random.uniform_int(1,6) die = boost_random.variate_generator( rng, six ) - - :: - + print die() date_time @@ -107,7 +103,7 @@ * Python code: - :: + .. code-block:: Python import os from pyboost import date_time @@ -115,75 +111,53 @@ from pyboost.date_time import posix_time from pyboost.date_time import local_time from pyboost.date_time import to_simple_string - - :: - - # + #Date programming - # + weekstart = gregorian.date(2002, date_time.Feb,1) print 'weekstart: ', to_simple_string( weekstart ) - - :: - + weekend = weekstart + gregorian.weeks(1) print 'weekend: ', to_simple_string( weekend ) - - :: - + today = gregorian.day_clock.local_day() d2 = weekstart + gregorian.days(5) if d2 >= today: #comparison operator pass - - :: - + thisWeek = gregorian.date_period(today,d2) if thisWeek.contains(today): pass - - :: - + #date generator functions + d5 = gregorian.next_weekday(today, date_time.Sunday); #calculate Sunday following d4 print 'd5: ', to_simple_string( d5 ) - - :: - + #US labor day is first Monday in Sept first = gregorian.nth_day_of_the_week_in_month.first labor_day = gregorian.nth_day_of_the_week_in_month(first, date_time.Monday, date_time.Sep) #calculate a specific date for 2004 from functor print 'labor day 2004: ', to_simple_string( labor_day.get_date(2004) ) - - :: - - # + #Time programming: - # + d = gregorian.date(2002,date_time.Feb,1)#an arbitrary date t1 = posix_time.ptime(d, posix_time.hours(5) + posix_time.millisec(100)); #date + time of day offset print 't1: ', to_simple_string( t1 ) - - :: - + t2 = t1 - posix_time.minutes(4) + posix_time.seconds(2) print 't2: ', to_simple_string( t2 ) - - :: - + now = posix_time.second_clock.local_time(); #use the clock print 'now: ', to_simple_string( now ) today = now.date() #Get the date part out of the time print 'today: ', to_simple_string( today ) tomorrow = today + gregorian.date_duration(1) print 'tomorrow: ', to_simple_string( tomorrow ) - - :: - - # + #Local time programming: - # + #setup some timezones for creating and adjusting times #first time zone uses the time zone file for regional timezone definitions tz_db = local_time.time_zone_database() @@ -191,9 +165,7 @@ nyc_tz = tz_db.time_zone_from_region("America/New_York") #This timezone uses a posix time zone string definition to create a time zone phx_tz = local_time.posix_time_zone("MST-07:00:00") - - :: - + #local departure time in phoenix is 11 pm on April 2 2005 #Note that New York changes to daylight savings on Apr 3 at 2 am) phx_departure = local_time.local_date_time( @@ -201,16 +173,13 @@ , posix_time.hours(23) , phx_tz , local_time.local_date_time.NOT_DATE_TIME_ON_ERROR) - - :: - + flight_length = posix_time.hours(4) + posix_time.minutes(30) phx_arrival = phx_departure + flight_length #convert the phx time to a nyz time nyc_arrival = phx_arrival.local_time_in(nyc_tz, posix_time.time_duration() ) print "New York arrival: ", nyc_arrival.to_string() #//2005-Apr-03 06:30:00 EDT - rational ~~~~~~~~ @@ -218,33 +187,26 @@ * Python code: - :: + .. code-block:: Python import unittest from pyboost import rational - - :: - + half = rational.rational( 1, 2 ) one = rational.rational( 1 ) two = rational.rational( 2 ) - - :: - + #Some basic checks assert half.numerator() == 1 assert half.denominator() == 2 assert float(half) == 0.5 - - :: - + #Arithmetic assert half + half == one == 1 assert one - half == half assert two * half == one == 1 assert one / half == two == 2 - crc ~~~ @@ -252,20 +214,18 @@ * Python code: - :: + .. code-block:: Python import os import sys from pyboost import crc - - :: - + if __name__ == '__main__': if sys.argv: files = sys.argv else: files = [ sys.executable ] - + try: result = crc.crc_32_type() for file_name in files: Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/history/history.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -198,16 +198,17 @@ a default argument. 8. `Py++`_ now generates correct code for hierarchy of abstract classes: - :: + .. code-block:: C++ + struct abstract1{ virtual void do_smth() = 0; } - + struct abstract2 : public abstract1{ virtual void do_smth_else() = 0; } - + struct concrete : public abstract2{ virtual void do_smth(){}; virtual void do_smth_else(){}; Modified: pyplusplus_dev/docs/peps/dsl_challenge.rest =================================================================== --- pyplusplus_dev/docs/peps/dsl_challenge.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/peps/dsl_challenge.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -16,7 +16,7 @@ I will use next C++ code as an example: -:: +.. code-block:: C++ namespace geometry{ struct Point{ @@ -40,8 +40,9 @@ 3. to rename ``x`` and ``y`` to ``X`` and ``Y`` Today, in order to configure this class, the user has to write next code: -:: +.. code-block:: Python + mb = module_builder_t( ... ) Point = mb.class_( 'Point' ) Point.member_function( 'create_new' ).call_policies = ... @@ -54,8 +55,9 @@ If class ``Point`` is not unique, than user will have to write a little bit different code: -:: +.. code-block:: Python + Point = mb.global_ns.namespace('geometry').class( 'Point' ) The current approach is pretty readable and simple. The drawbacks of this approach @@ -68,8 +70,9 @@ --------------------------- Better user interface (BUI) --------------------------- -:: +.. code-block:: Python + mb = module_builder_t( ... ) Point = mb.module.geometry.Point Point.create_new.call_policies = ... @@ -102,27 +105,29 @@ BUI does not work for template instantiated classes and functions. If we change class ``Point`` to be template, the special syntax should be introduced: - :: + .. code-block:: C++ template < class Numeric > struct Point{ ... }; - :: +.. code-block:: Python PointTmpl = mb.module.template('Point') Point = PointTmpl( 'int' ) This is a trivial example, that is why it looks grate. Consider next class: - :: +. code-block:: C++ + template< class String, class Allocator > class regex{ ... } The code the user will need to write is: - :: + .. code-block:: Python + regex_tmpl = mb.module.geometry.template( 'regex' ) #white spaces and scope resolution( :: ) are important regex_std_string = regex_tmpl( @@ -131,11 +136,12 @@ Using current `Py++`_ interface the user can get reference to the class instantiation in one line of code: - :: - regex_std_string = mb.class_( - lambda decl: decl.name.startswith( 'regex' ) and 'wchar_t' not in decl.name ) +.. code-block:: Python + regex_std_string = mb.class_( + lambda decl: decl.name.startswith( 'regex' ) and 'wchar_t' not in decl.name ) + * overloaded functions resolution There are use cases, when overloaded functions should be treated differently. @@ -158,8 +164,9 @@ Using BUI the user is forced to write full declaration name, otherwise he faces next problem: -:: +.. code-block:: Python + Point = mb.module.Point Lets analyze what the ``Point`` value: @@ -173,7 +180,7 @@ There are a lot of use cases, when the user has to add some code to the class: - :: + .. code-block:: Python Point.add_registration_code( ... ) Modified: pyplusplus_dev/docs/peps/function_transformation.rest =================================================================== --- pyplusplus_dev/docs/peps/function_transformation.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/peps/function_transformation.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -46,8 +46,9 @@ ft = int get_last_error(); The definition of ``ft`` could look like: -:: +.. code-block:: C++ + int get_last_error_transformed(){ int error(0); get_last_error( error ); @@ -92,29 +93,37 @@ In an ideal world we would have 2 classes, one class - one responsibility. In `Py++`_ it means that we would have ``transformation_t`` class: -:: +.. code-block:: Python + class transformation_t( object ): def __init__( self ): pass +.. code-block:: Python + def check( self, function ): "checks whether the transformation could be applied on the function or not" raise NotImplementedError() +.. code-block:: Python + def signature_changes( self, function ): "returns a list of changes that should be done on function signature" raise NotImplementedError() The class logically belongs to the ``decl_wrappers`` package. The ``transformer_t`` is the second class, which logically belongs to ``code_creators`` package: -:: +.. code-block:: Python + class transformer_t( ast_visitor_t ): def __init__( self, function, transformation ): function is a reference to the declaration we want to apply transformation on transformation is an instance of "concrete" transformation +.. code-block:: Python + def apply( self, function_body_as_tree ): "integrates transformation code to function body" raise NotImplementedError() @@ -146,21 +155,28 @@ Small re-factoring is needed. I don't expect changes in the user code. Proposed class: -:: +.. code-block:: Python + class transformer_t( object ): "base class for all transformation classes" def __init__( self ): pass +.. code-block:: Python + def check( self, function ): "checks whether the transformation could be applied on the function or not" raise NotImplementedError() +.. code-block:: Python + def signature_changes( self, function ): "returns a list of changes that should be done on function signature" raise NotImplementedError() +.. code-block:: Python + def apply( self, sm ): #sm is an instance of the substitution manager "integrates transformation code into function transformation body" raise NotImplementedError() @@ -197,12 +213,15 @@ ------------------------------------- output_arg transformation example ------------------------------------- -:: +.. code-block:: Python + class output_arg_t( transformer_t ): def __init__( self, ordinal ): self.ordinal = ordinal +.. code-block:: Python + def check( self, decl ): if len( decl.arguments ) <= self.ordinal: return user message @@ -210,11 +229,15 @@ if not reference to immutable type: raise user message +.. code-block:: Python + def signature_changes( self, decl ): assert not self.check( decl ) return [ remove_arg( self.ordinal ) , add_var_to_return_value( decl.arguments[ self.ordinal ].name ] - + +.. code-block:: Python + def apply( self, sm ): if sm is wrapper around C++ function: sm. add declaration of variable type = decl.arguments[ self.ordinal ].type @@ -223,6 +246,8 @@ else: #sm is a wrapper around Python function sm. extract value from the tuple and assign it to the argument +.. code-block:: Python + def output_arg( ordinal ): return output_arg_t( ordinal ) @@ -237,8 +262,9 @@ I am going to change a little an example, from `Boost.Python`_ tutorials: http://www.boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies -:: +.. code-block:: C++ + //C++ code struct Y { @@ -246,12 +272,16 @@ int z_value() { return z->value(); } }; +.. code-block:: C++ + X& f(Y& y, Z* z, int& error) { y.z = z; return y.x; } +.. code-block:: C++ + //Boost.Python code def("f", f, return_internal_reference<1, with_custodian_and_ward<1, 2> >() ); @@ -265,8 +295,9 @@ 1. May be it is possible with `Boost.Python`_ library to set call policies on the part of the return value? - :: + .. code-block:: C++ + boost::tuple f_wrapper( Y& y, Z* z ){ int error(0); X& x = f( y, z, error ); @@ -277,8 +308,9 @@ 2. May be it is possible to create Boost.Python ``object`` with life-time management hint? - :: + .. code-block:: C++ + boost::python::tuple f_wrapper( Y& y, Z* z ){ int error(0); X& x = f( y, z, error ); Modified: pyplusplus_dev/docs/peps/peps_index.rest =================================================================== --- pyplusplus_dev/docs/peps/peps_index.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/peps/peps_index.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -21,7 +21,7 @@ by `Py++`_: -:: +.. code-block:: C++ class Foo{ union { Modified: pyplusplus_dev/docs/pyplusplus.rest =================================================================== --- pyplusplus_dev/docs/pyplusplus.rest 2006-10-10 22:06:12 UTC (rev 643) +++ pyplusplus_dev/docs/pyplusplus.rest 2006-10-11 10:43:41 UTC (rev 644) @@ -67,27 +67,29 @@ simple query interface. For example in one line of code you can select all free functions that have two arguments, where the first argument has type ``int &`` and the type of the second argument is any: -:: +.. code-block:: Python + mb = module_builder_t( ... ) #module_builder_t is the main class that #will help you with code generation process mb.free_functions( arg_types=[ 'int &', None ] ) An other example - the developer wants to exclude all protected functions from being exported: -:: +.. code-block:: Python + mb = module_builder_t( ... ) mb.calldefs( access_type_matcher_t( 'protected' ) ).exclude() The developer can create custom criteria, for example exclude all declarations that have 'impl' ( implementation ) string within the name. -:: +.. code-block:: Python + mb = module_builder_t( ... ) mb.decls( lambda decl: 'impl' in decl.name ).exclude() - Please, note the way queries were built. You can think about those queries as the rules, which will continue to work even after exported C++ code was changed. It means that you don't have to change code generator source code every time. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |