pygccxml-commit Mailing List for C++ Python language bindings (Page 14)
Brought to you by:
mbaas,
roman_yakovenko
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
(190) |
Apr
(166) |
May
(170) |
Jun
(75) |
Jul
(105) |
Aug
(131) |
Sep
(99) |
Oct
(84) |
Nov
(67) |
Dec
(54) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(66) |
Feb
(49) |
Mar
(25) |
Apr
(62) |
May
(21) |
Jun
(34) |
Jul
(9) |
Aug
(21) |
Sep
(5) |
Oct
|
Nov
(63) |
Dec
(34) |
2008 |
Jan
(10) |
Feb
(42) |
Mar
(26) |
Apr
(25) |
May
(6) |
Jun
(40) |
Jul
(18) |
Aug
(29) |
Sep
(6) |
Oct
(32) |
Nov
(14) |
Dec
(56) |
2009 |
Jan
(127) |
Feb
(52) |
Mar
(2) |
Apr
(10) |
May
(29) |
Jun
(3) |
Jul
|
Aug
(16) |
Sep
(4) |
Oct
(11) |
Nov
(8) |
Dec
(14) |
2010 |
Jan
(31) |
Feb
(1) |
Mar
(7) |
Apr
(9) |
May
(1) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
(8) |
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <rom...@us...> - 2009-01-05 15:05:24
|
Revision: 1532 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1532&view=rev Author: roman_yakovenko Date: 2009-01-05 15:05:18 +0000 (Mon, 05 Jan 2009) Log Message: ----------- rename bparser to binary_parsers Removed Paths: ------------- pygccxml_dev/pygccxml/bparsers/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-05 15:04:39
|
Revision: 1531 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1531&view=rev Author: roman_yakovenko Date: 2009-01-05 15:04:35 +0000 (Mon, 05 Jan 2009) Log Message: ----------- rename bparser to binary_parsers Added Paths: ----------- pygccxml_dev/pygccxml/binary_parsers/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-05 13:53:53
|
Revision: 1530 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1530&view=rev Author: roman_yakovenko Date: 2009-01-05 13:53:48 +0000 (Mon, 05 Jan 2009) Log Message: ----------- rename msvc to bparser - the directory, which will contain parsers for different binary files ( .bsc, .pdb, .so, .dll ) Added Paths: ----------- pygccxml_dev/pygccxml/bparsers/ Removed Paths: ------------- pygccxml_dev/pygccxml/msvc/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-05 13:29:47
|
Revision: 1529 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1529&view=rev Author: roman_yakovenko Date: 2009-01-05 13:29:42 +0000 (Mon, 05 Jan 2009) Log Message: ----------- adding calling_convention property Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/calldef.py pygccxml_dev/pygccxml/declarations/decl_printer.py pygccxml_dev/unittests/test_all.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2009-01-04 20:29:35 UTC (rev 1528) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2009-01-05 13:29:42 UTC (rev 1529) @@ -92,6 +92,7 @@ from calldef import VIRTUALITY_TYPES from calldef import FUNCTION_VIRTUALITY_TYPES +from calldef import CALLING_CONVENTION_TYPES from calldef import argument_t from calldef import calldef_t from calldef import member_calldef_t Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2009-01-04 20:29:35 UTC (rev 1528) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2009-01-05 13:29:42 UTC (rev 1529) @@ -16,7 +16,7 @@ - constructor - destructor """ - +import re import cpptypes import algorithm import templates @@ -34,6 +34,32 @@ #preserving backward compatebility FUNCTION_VIRTUALITY_TYPES = VIRTUALITY_TYPES +class CALLING_CONVENTION_TYPES: + """class that defines "calling convention" constants""" + UNKNOWN = '' + CDECL = 'cdecl' + STDCALL = 'stdcall' + THISCALL = 'thiscall' + FASTCALL = 'fastcall' + SYSTEM_DEFAULT = '<<<system default>>>' + + ALL = ( UNKNOWN, CDECL, STDCALL, THISCALL, FASTCALL ) + + pattern = re.compile( r'.*(?:^|\s)(?:__)?(?P<cc>cdecl|stdcall|thiscall|fastcall)(?:__)?.*' ) + + @staticmethod + def extract( text, default=UNKNOWN ): + """extracts calling convention from the text. If the calling convention could not be found, the "default"is used""" + if not text: + return default + found = CALLING_CONVENTION_TYPES.pattern.match( text ) + if found: + return found.group( 'cc' ) + else: + return default + + + #First level in hierarchy of calldef class argument_t(object): """ @@ -140,6 +166,7 @@ self._return_type = return_type self._has_extern = has_extern self._demangled_name = None + self._calling_convention = None def _get__cmp__call_items(self): """implementation details""" @@ -321,6 +348,25 @@ , self.exceptions ) return answer + def guess_calling_convention( self ): + """This function should be overriden in the derived classes and return + more-or-less successfull guess about calling convention""" + return CALLING_CONVENTION_TYPES.UNKNOWN + + def get_calling_convention( self ): + if self._calling_convention is None: + self._calling_convention = CALLING_CONVENTION_TYPES.extract( self.attributes ) + if not self._calling_convention: + self._calling_convention = self.guess_calling_convention() + return self._calling_convention + + def set_calling_convention( self, cc ): + self._calling_convention = cc + + calling_convention = property( get_calling_convention, set_calling_convention + , doc="function calling convention. See L{CALLING_CONVENTION_TYPES} class for possible values" ) + + #Second level in hierarchy of calldef class member_calldef_t( calldef_t ): """base class for "callable" declarations that defined within C++ class or struct""" @@ -412,6 +458,12 @@ else: return f_type.partial_decl_string + def guess_calling_convention( self ): + if self.has_static: + return CALLING_CONVENTION_TYPES.SYSTEM_DEFAULT + else: + return CALLING_CONVENTION_TYPES.THISCALL + class free_calldef_t( calldef_t ): """base class for "callable" declarations that defined within C++ namespace""" def __init__( self, *args, **keywords ): @@ -454,7 +506,12 @@ else: return f_type.partial_decl_string + def guess_calling_convention( self ): + """This function should be overriden in the derived classes and return + more-or-less successfull guess about calling convention""" + return CALLING_CONVENTION_TYPES.UNKNOWN + class operator_t(object): """base class for "operator" declarations""" OPERATOR_WORD_LEN = len( 'operator' ) Modified: pygccxml_dev/pygccxml/declarations/decl_printer.py =================================================================== --- pygccxml_dev/pygccxml/declarations/decl_printer.py 2009-01-04 20:29:35 UTC (rev 1528) +++ pygccxml_dev/pygccxml/declarations/decl_printer.py 2009-01-05 13:29:42 UTC (rev 1529) @@ -136,6 +136,7 @@ self.writer( indent + "is extern: " + str(decl.has_extern) + os.linesep) self.writer( indent + "return type: " + str(retval) + os.linesep) self.writer( indent + "arguments type: " + ', '.join(args) + os.linesep) + self.writer( indent + "calling convention: __%s__" % decl.calling_convention + os.linesep) if isinstance( decl, calldef.member_calldef_t ): self.writer( indent + "virtual: " + str(decl.virtuality) + os.linesep) self.writer( indent + "is const: " + str(decl.has_const) + os.linesep) Modified: pygccxml_dev/unittests/test_all.py =================================================================== --- pygccxml_dev/unittests/test_all.py 2009-01-04 20:29:35 UTC (rev 1528) +++ pygccxml_dev/unittests/test_all.py 2009-01-05 13:29:42 UTC (rev 1529) @@ -53,6 +53,7 @@ import better_templates_matcher_tester import declaration_matcher_tester import undname_creator_tester +import calling_convention_tester testers = [ decl_string_tester @@ -102,6 +103,7 @@ , better_templates_matcher_tester , declaration_matcher_tester , undname_creator_tester + , calling_convention_tester ] def create_suite(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-04 20:29:41
|
Revision: 1528 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1528&view=rev Author: roman_yakovenko Date: 2009-01-04 20:29:35 +0000 (Sun, 04 Jan 2009) Log Message: ----------- adding more unittests Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/dependencies.py pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py pyplusplus_dev/pyplusplus/code_creators/methods_definition.py pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py pyplusplus_dev/unittests/ctypes_pof_tester.py pyplusplus_dev/unittests/data/ctypes/pof/sconscript pyplusplus_dev/unittests/sconstruct Added Paths: ----------- pyplusplus_dev/unittests/data/ctypes/issues/ pyplusplus_dev/unittests/data/ctypes/issues/issues.cpp pyplusplus_dev/unittests/data/ctypes/issues/issues.h pyplusplus_dev/unittests/data/ctypes/issues/sconscript Property Changed: ---------------- pygccxml_dev/unittests/ pygccxml_dev/unittests/data/msvc/ pygccxml_dev/unittests/data/msvc_build/ Modified: pygccxml_dev/pygccxml/declarations/dependencies.py =================================================================== --- pygccxml_dev/pygccxml/declarations/dependencies.py 2009-01-04 19:03:55 UTC (rev 1527) +++ pygccxml_dev/pygccxml/declarations/dependencies.py 2009-01-04 20:29:35 UTC (rev 1528) @@ -61,18 +61,27 @@ return None @staticmethod + def they_depend_on_me( decl ): + """returns set of declarations. every item in the returned set, depends on a + declaration from the input""" + import class_declaration #prevent cyclic imports + to_be_included = set() + for dependency_info in decl.i_depend_on_them(): + ddecl = dependency_info.find_out_depend_on_declaration() + if ddecl: + to_be_included.add( ddecl ) + + if isinstance( decl.parent, class_declaration.class_t ): + to_be_included.add( decl.parent ) + return to_be_included + + @staticmethod def they_depend_on_us( decls ): """returns set of declarations. every item in the returned set, depends on a declaration from the input""" import class_declaration #prevent cyclic imports to_be_included = set() for decl in decls: - for dependency_info in decl.i_depend_on_them(): - ddecl = dependency_info.find_out_depend_on_declaration() - if ddecl: - to_be_included.add( ddecl ) - - if isinstance( decl.parent, class_declaration.class_t ): - to_be_included.add( decl.parent ) + to_be_included.update( dependency_info_t.they_depend_on_me( decl ) ) return to_be_included Property changes on: pygccxml_dev/unittests ___________________________________________________________________ Modified: svn:ignore - *.pyc temp *.pdbrc + *.pyc temp *.pdbrc *.bak Property changes on: pygccxml_dev/unittests/data/msvc ___________________________________________________________________ Modified: svn:ignore - Release + Release Debug *.suo Property changes on: pygccxml_dev/unittests/data/msvc_build ___________________________________________________________________ Modified: svn:ignore - Debug + Debug *.ncb *.suo *.user Modified: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py 2009-01-04 19:03:55 UTC (rev 1527) +++ pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py 2009-01-04 20:29:35 UTC (rev 1528) @@ -4,9 +4,9 @@ import ctypes_utils -easybmp = ctypes.CPPDLL( r"E:\development\language-binding\pyplusplus_dev\examples\pyeasybmp_dev\easybmp\binaries\easybmp.dll" ) +easybmplib = ctypes.CPPDLL( r"E:\development\language-binding\pyplusplus_dev\examples\pyeasybmp_dev\easybmp\binaries\easybmp.dll" ) -easybmp.undecorated_names = {#mapping between decorated and undecorated names +easybmplib.undecorated_names = {#mapping between decorated and undecorated names "unsigned short FlipWORD(unsigned short)" : "?FlipWORD@@YAGG@Z", "BMP::BMP(void)" : "??0BMP@@QAE@XZ", "bool BMP::SetPixel(int,int RGBApixel)" : "?SetPixel@BMP@@QAE_NHHURGBApixel@@@Z", @@ -249,7 +249,7 @@ ("bfOffBits", ctypes.c_uint), ] -mfcreator = ctypes_utils.mem_fun_factory( easybmp, BMFH, "BMFH", "" ) +mfcreator = ctypes_utils.mem_fun_factory( easybmplib, BMFH, "BMFH" ) BMFH._methods_ = { #class non-virtual member functions definition list "__init__" : mfcreator.multi_method() .register( mfcreator.default_constructor() ) @@ -275,7 +275,7 @@ ("biClrImportant", ctypes.c_uint), ] -mfcreator = ctypes_utils.mem_fun_factory( easybmp, BMIH, "BMIH", "" ) +mfcreator = ctypes_utils.mem_fun_factory( easybmplib, BMIH, "BMIH" ) BMIH._methods_ = { #class non-virtual member functions definition list "__init__" : mfcreator.multi_method() .register( mfcreator.default_constructor() ) @@ -294,7 +294,7 @@ ("Alpha", ctypes.c_ubyte), ] -mfcreator = ctypes_utils.mem_fun_factory( easybmp, RGBApixel, "RGBApixel", "" ) +mfcreator = ctypes_utils.mem_fun_factory( easybmplib, RGBApixel, "RGBApixel" ) RGBApixel._methods_ = { #class non-virtual member functions definition list } @@ -314,7 +314,7 @@ ("SizeOfMetaData2", ctypes.c_int), ] -mfcreator = ctypes_utils.mem_fun_factory( easybmp, BMP, "BMP", "" ) +mfcreator = ctypes_utils.mem_fun_factory( easybmplib, BMP, "BMP" ) BMP._methods_ = { #class non-virtual member functions definition list "TellBitDepth" : mfcreator( "int BMP::TellBitDepth(void)", restype=ctypes.c_int ), @@ -372,21 +372,21 @@ } del mfcreator -Square = getattr( easybmp, easybmp.undecorated_names["double Square(double)"] ) +Square = getattr( easybmplib, easybmplib.undecorated_names["double Square(double)"] ) Square.restype = ctypes.c_double Square.argtypes = [ ctypes.c_double ] -IntSquare = getattr( easybmp, easybmp.undecorated_names["int IntSquare(int)"] ) +IntSquare = getattr( easybmplib, easybmplib.undecorated_names["int IntSquare(int)"] ) IntSquare.restype = ctypes.c_int IntSquare.argtypes = [ ctypes.c_int ] -FlipDWORD = getattr( easybmp, easybmp.undecorated_names["unsigned int FlipDWORD(unsigned int)"] ) +FlipDWORD = getattr( easybmplib, easybmplib.undecorated_names["unsigned int FlipDWORD(unsigned int)"] ) FlipDWORD.restype = ctypes.c_uint FlipDWORD.argtypes = [ ctypes.c_uint ] -IsBigEndian = getattr( easybmp, easybmp.undecorated_names["bool IsBigEndian(void)"] ) +IsBigEndian = getattr( easybmplib, easybmplib.undecorated_names["bool IsBigEndian(void)"] ) IsBigEndian.restype = ctypes.c_bool -FlipWORD = getattr( easybmp, easybmp.undecorated_names["unsigned short FlipWORD(unsigned short)"] ) +FlipWORD = getattr( easybmplib, easybmplib.undecorated_names["unsigned short FlipWORD(unsigned short)"] ) FlipWORD.restype = ctypes.c_ushort FlipWORD.argtypes = [ ctypes.c_ushort ] Modified: pyplusplus_dev/pyplusplus/code_creators/methods_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/methods_definition.py 2009-01-04 19:03:55 UTC (rev 1527) +++ pyplusplus_dev/pyplusplus/code_creators/methods_definition.py 2009-01-04 20:29:35 UTC (rev 1528) @@ -37,12 +37,16 @@ del scope[0] #del :: from the global namespace del scope[-1] #del self from the list - result.append( '%(mem_fun_factory_var_name)s = ctypes_utils.mem_fun_factory( %(library_var_name)s, %(complete_py_name)s, "%(class_name)s", "%(ns)s" )' - % dict( mem_fun_factory_var_name=self.mem_fun_factory_var_name - , library_var_name=self.top_parent.library_var_name - , complete_py_name=self.complete_py_name - , class_name=self.declaration.name - , ns='::'.join(scope) ) ) + tmpl = '%(mem_fun_factory_var_name)s = ctypes_utils.mem_fun_factory( %(library_var_name)s, %(complete_py_name)s, "%(class_name)s", "%(ns)s" )' + if not scope: + tmpl = '%(mem_fun_factory_var_name)s = ctypes_utils.mem_fun_factory( %(library_var_name)s, %(complete_py_name)s, "%(class_name)s" )' + + result.append( tmpl % dict( mem_fun_factory_var_name=self.mem_fun_factory_var_name + , library_var_name=self.top_parent.library_var_name + , complete_py_name=self.complete_py_name + , class_name=self.declaration.name + , ns='::'.join(scope) ) ) + result.append( '%(complete_py_name)s._methods_ = { #class non-virtual member functions definition list' % dict( complete_py_name=self.complete_py_name ) ) result.append( compound.compound_t.create_internal_code( self.creators ) ) Modified: pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py =================================================================== --- pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2009-01-04 19:03:55 UTC (rev 1527) +++ pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2009-01-04 20:29:35 UTC (rev 1528) @@ -108,8 +108,7 @@ classes = class_.classes( recursive=False, allow_empty=True) classes = sort_algorithms.sort_classes( classes ) for internal_class in classes: - if self.__contains_exported( internal_class ): - self.__add_class_introductions( ci_creator, internal_class ) + self.__add_class_introductions( ci_creator, internal_class ) def create(self ): """Create and return the module for the extension. Modified: pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2009-01-04 19:03:55 UTC (rev 1527) +++ pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2009-01-04 20:29:35 UTC (rev 1528) @@ -88,14 +88,31 @@ included_decls = set() included_decls.update( self.global_ns.calldefs( is_exported, allow_empty=True, recursive=True ) ) included_decls.update( self.global_ns.variables( is_exported, allow_empty=True, recursive=True ) ) - #include declarations, on which exported declarations depend - they_depend_on_us = decls_package.dependency_info_t.they_depend_on_us - included_decls.update( they_depend_on_us( included_decls ) ) + + they_depend_on_me = decls_package.dependency_info_t.they_depend_on_me for d in included_decls: d.include() - if isinstance( d, decls_package.class_t ): - d.top_class.include() + self.logger.info( 'including decl %s' % str(d) ) + parent = d.parent + while True: + if isinstance( parent, decls_package.namespace_t ): + break + else: + self.logger.info( 'including parent class %s' % str(parent) ) + parent.ignore = False + parent = parent.parent + for dependency in they_depend_on_me( d ): + self.logger.info( 'discovered dependency %s' % str(dependency) ) + #include declarations, on which exported declarations depend + #I need this for classes, referenced by function arguments + decls_traits = ( decls_package.class_traits, decls_package.class_declaration_traits, decls_package.enum_traits ) + for traits in decls_traits: + if traits.is_my_case( dependency ): + self.logger.info( 'discovered dependency %s - included' % str(dependency) ) + traits.get_declaration( dependency ).ignore = False + self.logger.info( 'including decl %s - done' % str(d) ) + def build_code_creator( self, library_path, doc_extractor=None ): creator = creators_factory.ctypes_creator_t( self.global_ns , library_path Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-04 19:03:55 UTC (rev 1527) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-04 20:29:35 UTC (rev 1528) @@ -11,6 +11,7 @@ from pyplusplus.module_builder import ctypes_module_builder_t class ctypes_base_tester_t(unittest.TestCase): + _module_ref_ = None def __init__( self, base_name, *args, **keywd ): unittest.TestCase.__init__( self, *args, **keywd ) @@ -33,22 +34,23 @@ return os.path.join( self.project_dir, 'binaries', self.base_name + '.dll' ) def setUp( self ): - if ctypes_base_tester_t._module_ref_: - return - + if self.base_name in sys.modules: + return sys.modules[ self.base_name ] + #~ import pdb + #~ pdb.set_trace() autoconfig.scons_config.compile( autoconfig.scons.cmd_build + ' ' + self.base_name ) mb = ctypes_module_builder_t( [self.header], self.symbols_file, autoconfig.cxx_parsers_cfg.gccxml ) mb.build_code_creator( self.symbols_file ) mb.write_module( os.path.join( self.project_dir, 'binaries', self.base_name + '.py' ) ) sys.path.insert( 0, os.path.join( self.project_dir, 'binaries' ) ) - ctypes_base_tester_t._module_ref_ = __import__( self.base_name ) + __import__( self.base_name ) @property def module_ref(self): - return self._module_ref_ + return sys.modules[ self.base_name ] -class tester_t( ctypes_base_tester_t ): +class pof_tester_t( ctypes_base_tester_t ): def __init__( self, *args, **keywd ): ctypes_base_tester_t.__init__( self, 'pof', *args, **keywd ) @@ -84,10 +86,24 @@ #~ obj2 = obj1.clone() #~ self.fail( obj1.get_value() == obj2.get_value() ) + +class issues_tester_t( ctypes_base_tester_t ): + def __init__( self, *args, **keywd ): + ctypes_base_tester_t.__init__( self, 'issues', *args, **keywd ) + + def test_return_by_value(self): + x = self.module_ref.return_by_value_t() + result = x.add( 32, 2 ).result + self.failUnless( 34 == result, "Expected result 34, got %d" % result) + + def test_free_fun_add( self ): + self.failUnless( 1977 == self.module_ref.add( 77, 1900 ) ) + def create_suite(): suite = unittest.TestSuite() if 'win' in sys.platform: - suite.addTest( unittest.makeSuite(tester_t)) + suite.addTest( unittest.makeSuite(pof_tester_t)) + suite.addTest( unittest.makeSuite(issues_tester_t)) return suite def run_suite(): Added: pyplusplus_dev/unittests/data/ctypes/issues/issues.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes/issues/issues.cpp (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/issues/issues.cpp 2009-01-04 20:29:35 UTC (rev 1528) @@ -0,0 +1,5 @@ +#include "issues.h" + +int add( int i, int j){ + return i + j; +} Added: pyplusplus_dev/unittests/data/ctypes/issues/issues.h =================================================================== --- pyplusplus_dev/unittests/data/ctypes/issues/issues.h (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/issues/issues.h 2009-01-04 20:29:35 UTC (rev 1528) @@ -0,0 +1,13 @@ +#pragma once + + +struct __declspec(dllexport) return_by_value_t{ +public: + struct result_t{ int i; int j; int result; }; + result_t add( int i, int j ){ + result_t r = { i, j, i + j}; + return r; + } +}; + +int __declspec(dllexport) add( int, int ); Added: pyplusplus_dev/unittests/data/ctypes/issues/sconscript =================================================================== --- pyplusplus_dev/unittests/data/ctypes/issues/sconscript (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/issues/sconscript 2009-01-04 20:29:35 UTC (rev 1528) @@ -0,0 +1,5 @@ +Import('*') + +target_name = 'issues' +shlib = env.SharedLibrary( target=target_name, source=[ target_name + '.cpp' ] ) +env.Alias( target_name, shlib ) Modified: pyplusplus_dev/unittests/data/ctypes/pof/sconscript =================================================================== --- pyplusplus_dev/unittests/data/ctypes/pof/sconscript 2009-01-04 19:03:55 UTC (rev 1527) +++ pyplusplus_dev/unittests/data/ctypes/pof/sconscript 2009-01-04 20:29:35 UTC (rev 1528) @@ -1,7 +1,5 @@ Import('*') target_name = 'pof' -shlib = env.SharedLibrary( target=target_name, source=[ target_name + '.cpp' ] - , LINKFLAGS=[r"/MAP:${TARGET.base}.map", r"/MAPINFO:EXPORTS"] ) - +shlib = env.SharedLibrary( target=target_name, source=[ target_name + '.cpp' ] ) env.Alias( target_name, shlib ) Modified: pyplusplus_dev/unittests/sconstruct =================================================================== --- pyplusplus_dev/unittests/sconstruct 2009-01-04 19:03:55 UTC (rev 1527) +++ pyplusplus_dev/unittests/sconstruct 2009-01-04 20:29:35 UTC (rev 1528) @@ -11,8 +11,9 @@ env.AppendUnique( CCFLAGS=[ r"/MD",r"/EHsc",r"/GR",r"/Zc:wchar_t",r"/Zc:forScope" ] ) env.AppendUnique( LINKFLAGS=[r"/MAP:${TARGET.base}.map", r"/MAPINFO:EXPORTS"] ) -SConscript( 'data/ctypes/pof/sconscript' - , variant_dir='data/ctypes/pof/binaries' - , duplicate=0 - , exports=["env"] ) - +scripts = [ 'pof', 'issues' ] +for s in scripts: + SConscript( 'data/ctypes/%s/sconscript' % s + , variant_dir='data/ctypes/%s/binaries' % s + , duplicate=0 + , exports=["env"] ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-04 19:03:59
|
Revision: 1527 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1527&view=rev Author: roman_yakovenko Date: 2009-01-04 19:03:55 +0000 (Sun, 04 Jan 2009) Log Message: ----------- setup ctypes testers framework Modified Paths: -------------- pygccxml_dev/pygccxml/msvc/common_utils.py pyplusplus_dev/pyplusplus/code_creators/library_reference.py pyplusplus_dev/unittests/autoconfig.py pyplusplus_dev/unittests/ctypes_pof_tester.py pyplusplus_dev/unittests/data/ctypes/pof/sconscript pyplusplus_dev/unittests/sconstruct Added Paths: ----------- pyplusplus_dev/unittests/data/ctypes/pof/pof.cpp pyplusplus_dev/unittests/data/ctypes/pof/pof.h Removed Paths: ------------- pygccxml_dev/unittests/data/xxx.bsc.bz2 pygccxml_dev/unittests/data/xxx.pdb.bz2 pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.cpp pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.h Property Changed: ---------------- pygccxml_dev/unittests/ pygccxml_dev/unittests/data/msvc/ pygccxml_dev/unittests/data/msvc_build/ pyplusplus_dev/unittests/data/ctypes/pof/ Modified: pygccxml_dev/pygccxml/msvc/common_utils.py =================================================================== --- pygccxml_dev/pygccxml/msvc/common_utils.py 2009-01-04 18:32:59 UTC (rev 1526) +++ pygccxml_dev/pygccxml/msvc/common_utils.py 2009-01-04 19:03:55 UTC (rev 1527) @@ -110,7 +110,7 @@ buffer = ctypes.create_string_buffer(1024*16) res = self.__undname( str(name), buffer, ctypes.sizeof(buffer), options) if res: - return self.normalize_undecorated_blob( str(buffer[:res]) ) + return self.normalize_undecorated( str(buffer[:res]) ) else: return name Property changes on: pygccxml_dev/unittests ___________________________________________________________________ Modified: svn:ignore - *.pyc temp + *.pyc temp *.pdbrc Property changes on: pygccxml_dev/unittests/data/msvc ___________________________________________________________________ Added: svn:ignore + Release Property changes on: pygccxml_dev/unittests/data/msvc_build ___________________________________________________________________ Added: svn:ignore + Debug Deleted: pygccxml_dev/unittests/data/xxx.bsc.bz2 =================================================================== (Binary files differ) Deleted: pygccxml_dev/unittests/data/xxx.pdb.bz2 =================================================================== (Binary files differ) Modified: pyplusplus_dev/pyplusplus/code_creators/library_reference.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/library_reference.py 2009-01-04 18:32:59 UTC (rev 1526) +++ pyplusplus_dev/pyplusplus/code_creators/library_reference.py 2009-01-04 19:03:55 UTC (rev 1527) @@ -25,7 +25,7 @@ return library_var_name else: basename = os.path.splitext( os.path.basename( library_path ) )[0] - return decl_wrappers.algorithm.create_valid_name( basename ) + return decl_wrappers.algorithm.create_valid_name( basename ) + 'lib' def _create_impl(self): return '%(var)s = ctypes.%(loader)s( r"%(path)s" )' \ Modified: pyplusplus_dev/unittests/autoconfig.py =================================================================== --- pyplusplus_dev/unittests/autoconfig.py 2009-01-04 18:32:59 UTC (rev 1526) +++ pyplusplus_dev/unittests/autoconfig.py 2009-01-04 19:03:55 UTC (rev 1527) @@ -28,7 +28,7 @@ class cxx_parsers_cfg: keywd = { 'working_directory' : data_directory , 'define_symbols' : [ gccxml_version ] - , 'compiler' : "msvc71" + , 'compiler' : compiler , 'gccxml_path': gccxml.executable } if 'win' in sys.platform: Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-04 18:32:59 UTC (rev 1526) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-04 19:03:55 UTC (rev 1527) @@ -10,15 +10,19 @@ import autoconfig from pyplusplus.module_builder import ctypes_module_builder_t -class tester_t(unittest.TestCase): +class ctypes_base_tester_t(unittest.TestCase): _module_ref_ = None - def __init__( self, *args, **keywd ): + def __init__( self, base_name, *args, **keywd ): unittest.TestCase.__init__( self, *args, **keywd ) - self.base_name = 'ctypes_pof' + self.__base_name = base_name @property + def base_name( self ): + return self.__base_name + + @property def project_dir( self ): - return os.path.join( autoconfig.data_directory, self.base_name ) + return os.path.join( autoconfig.data_directory, 'ctypes', self.base_name ) @property def header( self ): @@ -29,19 +33,25 @@ return os.path.join( self.project_dir, 'binaries', self.base_name + '.dll' ) def setUp( self ): - if tester_t._module_ref_: + if ctypes_base_tester_t._module_ref_: return autoconfig.scons_config.compile( autoconfig.scons.cmd_build + ' ' + self.base_name ) mb = ctypes_module_builder_t( [self.header], self.symbols_file, autoconfig.cxx_parsers_cfg.gccxml ) mb.build_code_creator( self.symbols_file ) - mb.write_module( os.path.join( autoconfig.build_directory, self.module_name + '.py' ) ) - tester_t._module_ref_ = __import__( os.path.join( autoconfig.build_directory, self.base_name + '.py' ) ) + mb.write_module( os.path.join( self.project_dir, 'binaries', self.base_name + '.py' ) ) + sys.path.insert( 0, os.path.join( self.project_dir, 'binaries' ) ) + ctypes_base_tester_t._module_ref_ = __import__( self.base_name ) @property def module_ref(self): return self._module_ref_ + +class tester_t( ctypes_base_tester_t ): + def __init__( self, *args, **keywd ): + ctypes_base_tester_t.__init__( self, 'pof', *args, **keywd ) + def test_constructors(self): n0 = self.module_ref.pof.number_t() self.failUnless( 0 == n0.get_value() ) @@ -74,15 +84,6 @@ #~ obj2 = obj1.clone() #~ self.fail( obj1.get_value() == obj2.get_value() ) - - def test_bsc( self ): - root = r'E:\Documents and Settings\romany\Desktop\ToInstall\bsckit70\bscsdk' - mb = ctypes_module_builder_t( [os.path.join( root, 'bsc.h' )] - , os.path.join( root, 'msbsc70.dll' ), autoconfig.cxx_parsers_cfg.gccxml ) - mb.build_code_creator( self.symbols_file ) - mb.write_module( os.path.join( root, 'bsc.py' ) ) - - def create_suite(): suite = unittest.TestSuite() if 'win' in sys.platform: Property changes on: pyplusplus_dev/unittests/data/ctypes/pof ___________________________________________________________________ Added: svn:ignore + binaries Deleted: pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.cpp 2009-01-04 18:32:59 UTC (rev 1526) +++ pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.cpp 2009-01-04 19:03:55 UTC (rev 1527) @@ -1,69 +0,0 @@ -#include "ctypes_pof.h" -#include "windows.h" -#include <iostream> - -namespace pof{ - -number_t::number_t() -: m_value(0) -{ -// std::cout << "{C++} number_t( 0 )" << std::endl; -} - - -number_t::number_t(int value) -: m_value(value) -{ -// std::cout << "{C++} number_t( " << value << " )" << std::endl; -} - -number_t::~number_t() { -// std::cout << "{C++} ~number_t()" << std::endl; -} -void number_t::print_it() const { - std::cout << "{C++} value: " << m_value << std::endl; -} - -int number_t::get_value() const{ - return m_value; -} - -void number_t::set_value(int x){ - m_value = x; -} - -number_t number_t::clone() const{ - return number_t(*this); -} - -std::auto_ptr<number_t> number_t::clone_ptr() const{ - return std::auto_ptr<number_t>( new number_t( *this ) ); -} - -} - -using namespace pof; - -void do_smth( number_aptr_t& ){ -} - -int identity( int some_data){ return some_data;} - -int identity_cpp( int data){ return data; } - -//~ BOOL APIENTRY DllMain( HMODULE hModule, - //~ DWORD ul_reason_for_call, - //~ LPVOID lpReserved - //~ ) -//~ { - //~ switch (ul_reason_for_call) - //~ { - //~ case DLL_PROCESS_ATTACH: - //~ case DLL_THREAD_ATTACH: - //~ case DLL_THREAD_DETACH: - //~ case DLL_PROCESS_DETACH: - //~ break; - //~ } - //~ return TRUE; -//~ } - Deleted: pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.h =================================================================== --- pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.h 2009-01-04 18:32:59 UTC (rev 1526) +++ pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.h 2009-01-04 19:03:55 UTC (rev 1527) @@ -1,36 +0,0 @@ -#pragma once - -#include <memory> - -namespace pof{ - -class __declspec(dllexport) number_t{ -public: - number_t(); - explicit number_t(int value); - virtual ~number_t(); - virtual void print_it() const; - int get_value() const; - int get_value(){ return m_value; } - void set_value(int x); - - number_t clone() const; - std::auto_ptr<number_t> clone_ptr() const; -private: - int m_value; -}; - -} -template class __declspec(dllexport) std::auto_ptr< pof::number_t >; - -typedef std::auto_ptr< pof::number_t > number_aptr_t; - -void __declspec(dllexport) do_smth( number_aptr_t& ); - -extern "C"{ - -int __declspec(dllexport) identity( int ); - -} - -int __declspec(dllexport) identity_cpp( int ); \ No newline at end of file Added: pyplusplus_dev/unittests/data/ctypes/pof/pof.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes/pof/pof.cpp (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/pof/pof.cpp 2009-01-04 19:03:55 UTC (rev 1527) @@ -0,0 +1,52 @@ +#include "pof.h" +#include <iostream> + +namespace pof{ + +number_t::number_t() +: m_value(0) +{ +// std::cout << "{C++} number_t( 0 )" << std::endl; +} + + +number_t::number_t(int value) +: m_value(value) +{ +// std::cout << "{C++} number_t( " << value << " )" << std::endl; +} + +number_t::~number_t() { +// std::cout << "{C++} ~number_t()" << std::endl; +} +void number_t::print_it() const { + std::cout << "{C++} value: " << m_value << std::endl; +} + +int number_t::get_value() const{ + return m_value; +} + +void number_t::set_value(int x){ + m_value = x; +} + +number_t number_t::clone() const{ + return number_t(*this); +} + +std::auto_ptr<number_t> number_t::clone_ptr() const{ + return std::auto_ptr<number_t>( new number_t( *this ) ); +} + +} + +using namespace pof; + +void do_smth( number_aptr_t& ){ +} + +int identity( int some_data){ return some_data;} + +int identity_cpp( int data){ return data; } + Copied: pyplusplus_dev/unittests/data/ctypes/pof/pof.h (from rev 1526, pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.h) =================================================================== --- pyplusplus_dev/unittests/data/ctypes/pof/pof.h (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/pof/pof.h 2009-01-04 19:03:55 UTC (rev 1527) @@ -0,0 +1,36 @@ +#pragma once + +#include <memory> + +namespace pof{ + +class __declspec(dllexport) number_t{ +public: + number_t(); + explicit number_t(int value); + virtual ~number_t(); + virtual void print_it() const; + int get_value() const; + int get_value(){ return m_value; } + void set_value(int x); + + number_t clone() const; + std::auto_ptr<number_t> clone_ptr() const; +private: + int m_value; +}; + +} +template class __declspec(dllexport) std::auto_ptr< pof::number_t >; + +typedef std::auto_ptr< pof::number_t > number_aptr_t; + +void __declspec(dllexport) do_smth( number_aptr_t& ); + +extern "C"{ + +int __declspec(dllexport) identity( int ); + +} + +int __declspec(dllexport) identity_cpp( int ); \ No newline at end of file Modified: pyplusplus_dev/unittests/data/ctypes/pof/sconscript =================================================================== --- pyplusplus_dev/unittests/data/ctypes/pof/sconscript 2009-01-04 18:32:59 UTC (rev 1526) +++ pyplusplus_dev/unittests/data/ctypes/pof/sconscript 2009-01-04 19:03:55 UTC (rev 1527) @@ -1,9 +1,7 @@ Import('*') -target_name = 'ctypes_pof' -shlib = env.SharedLibrary( target=target_name - , source=[ target_name + '.cpp' ] - , CCFLAGS=[ r"/MD",r"/EHsc",r"/GR",r"/Zc:wchar_t",r"/Zc:forScope" ] +target_name = 'pof' +shlib = env.SharedLibrary( target=target_name, source=[ target_name + '.cpp' ] , LINKFLAGS=[r"/MAP:${TARGET.base}.map", r"/MAPINFO:EXPORTS"] ) env.Alias( target_name, shlib ) Modified: pyplusplus_dev/unittests/sconstruct =================================================================== --- pyplusplus_dev/unittests/sconstruct 2009-01-04 18:32:59 UTC (rev 1526) +++ pyplusplus_dev/unittests/sconstruct 2009-01-04 19:03:55 UTC (rev 1527) @@ -8,8 +8,11 @@ env.Append( CPPPATH=[r"E:\Program Files\Microsoft SDKs\Windows\v6.0A\Include" , r"E:\Program Files\Microsoft Visual Studio 9.0\VC\include"]) -SConscript( 'data/ctypes_pof/sconscript' - , variant_dir='data/ctypes_pof/binaries' +env.AppendUnique( CCFLAGS=[ r"/MD",r"/EHsc",r"/GR",r"/Zc:wchar_t",r"/Zc:forScope" ] ) +env.AppendUnique( LINKFLAGS=[r"/MAP:${TARGET.base}.map", r"/MAPINFO:EXPORTS"] ) + +SConscript( 'data/ctypes/pof/sconscript' + , variant_dir='data/ctypes/pof/binaries' , duplicate=0 , exports=["env"] ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-04 18:33:10
|
Revision: 1526 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1526&view=rev Author: roman_yakovenko Date: 2009-01-04 18:32:59 +0000 (Sun, 04 Jan 2009) Log Message: ----------- small refactoring Added Paths: ----------- pyplusplus_dev/unittests/data/ctypes/ pyplusplus_dev/unittests/data/ctypes/pof/ pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.cpp pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.h pyplusplus_dev/unittests/data/ctypes/pof/sconscript Removed Paths: ------------- pyplusplus_dev/unittests/data/ctypes/ctypes_pof.cpp pyplusplus_dev/unittests/data/ctypes/ctypes_pof.h pyplusplus_dev/unittests/data/ctypes/sconscript pyplusplus_dev/unittests/data/ctypes_pof/ Deleted: pyplusplus_dev/unittests/data/ctypes/ctypes_pof.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.cpp 2009-01-04 11:37:54 UTC (rev 1525) +++ pyplusplus_dev/unittests/data/ctypes/ctypes_pof.cpp 2009-01-04 18:32:59 UTC (rev 1526) @@ -1,69 +0,0 @@ -#include "ctypes_pof.h" -#include "windows.h" -#include <iostream> - -namespace pof{ - -number_t::number_t() -: m_value(0) -{ -// std::cout << "{C++} number_t( 0 )" << std::endl; -} - - -number_t::number_t(int value) -: m_value(value) -{ -// std::cout << "{C++} number_t( " << value << " )" << std::endl; -} - -number_t::~number_t() { -// std::cout << "{C++} ~number_t()" << std::endl; -} -void number_t::print_it() const { - std::cout << "{C++} value: " << m_value << std::endl; -} - -int number_t::get_value() const{ - return m_value; -} - -void number_t::set_value(int x){ - m_value = x; -} - -number_t number_t::clone() const{ - return number_t(*this); -} - -std::auto_ptr<number_t> number_t::clone_ptr() const{ - return std::auto_ptr<number_t>( new number_t( *this ) ); -} - -} - -using namespace pof; - -void do_smth( number_aptr_t& ){ -} - -int identity( int some_data){ return some_data;} - -int identity_cpp( int data){ return data; } - -//~ BOOL APIENTRY DllMain( HMODULE hModule, - //~ DWORD ul_reason_for_call, - //~ LPVOID lpReserved - //~ ) -//~ { - //~ switch (ul_reason_for_call) - //~ { - //~ case DLL_PROCESS_ATTACH: - //~ case DLL_THREAD_ATTACH: - //~ case DLL_THREAD_DETACH: - //~ case DLL_PROCESS_DETACH: - //~ break; - //~ } - //~ return TRUE; -//~ } - Deleted: pyplusplus_dev/unittests/data/ctypes/ctypes_pof.h =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.h 2009-01-04 11:37:54 UTC (rev 1525) +++ pyplusplus_dev/unittests/data/ctypes/ctypes_pof.h 2009-01-04 18:32:59 UTC (rev 1526) @@ -1,36 +0,0 @@ -#pragma once - -#include <memory> - -namespace pof{ - -class __declspec(dllexport) number_t{ -public: - number_t(); - explicit number_t(int value); - virtual ~number_t(); - virtual void print_it() const; - int get_value() const; - int get_value(){ return m_value; } - void set_value(int x); - - number_t clone() const; - std::auto_ptr<number_t> clone_ptr() const; -private: - int m_value; -}; - -} -template class __declspec(dllexport) std::auto_ptr< pof::number_t >; - -typedef std::auto_ptr< pof::number_t > number_aptr_t; - -void __declspec(dllexport) do_smth( number_aptr_t& ); - -extern "C"{ - -int __declspec(dllexport) identity( int ); - -} - -int __declspec(dllexport) identity_cpp( int ); \ No newline at end of file Copied: pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.cpp (from rev 1525, pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.cpp) =================================================================== --- pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.cpp (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.cpp 2009-01-04 18:32:59 UTC (rev 1526) @@ -0,0 +1,69 @@ +#include "ctypes_pof.h" +#include "windows.h" +#include <iostream> + +namespace pof{ + +number_t::number_t() +: m_value(0) +{ +// std::cout << "{C++} number_t( 0 )" << std::endl; +} + + +number_t::number_t(int value) +: m_value(value) +{ +// std::cout << "{C++} number_t( " << value << " )" << std::endl; +} + +number_t::~number_t() { +// std::cout << "{C++} ~number_t()" << std::endl; +} +void number_t::print_it() const { + std::cout << "{C++} value: " << m_value << std::endl; +} + +int number_t::get_value() const{ + return m_value; +} + +void number_t::set_value(int x){ + m_value = x; +} + +number_t number_t::clone() const{ + return number_t(*this); +} + +std::auto_ptr<number_t> number_t::clone_ptr() const{ + return std::auto_ptr<number_t>( new number_t( *this ) ); +} + +} + +using namespace pof; + +void do_smth( number_aptr_t& ){ +} + +int identity( int some_data){ return some_data;} + +int identity_cpp( int data){ return data; } + +//~ BOOL APIENTRY DllMain( HMODULE hModule, + //~ DWORD ul_reason_for_call, + //~ LPVOID lpReserved + //~ ) +//~ { + //~ switch (ul_reason_for_call) + //~ { + //~ case DLL_PROCESS_ATTACH: + //~ case DLL_THREAD_ATTACH: + //~ case DLL_THREAD_DETACH: + //~ case DLL_PROCESS_DETACH: + //~ break; + //~ } + //~ return TRUE; +//~ } + Copied: pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.h (from rev 1525, pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.h) =================================================================== --- pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.h (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/pof/ctypes_pof.h 2009-01-04 18:32:59 UTC (rev 1526) @@ -0,0 +1,36 @@ +#pragma once + +#include <memory> + +namespace pof{ + +class __declspec(dllexport) number_t{ +public: + number_t(); + explicit number_t(int value); + virtual ~number_t(); + virtual void print_it() const; + int get_value() const; + int get_value(){ return m_value; } + void set_value(int x); + + number_t clone() const; + std::auto_ptr<number_t> clone_ptr() const; +private: + int m_value; +}; + +} +template class __declspec(dllexport) std::auto_ptr< pof::number_t >; + +typedef std::auto_ptr< pof::number_t > number_aptr_t; + +void __declspec(dllexport) do_smth( number_aptr_t& ); + +extern "C"{ + +int __declspec(dllexport) identity( int ); + +} + +int __declspec(dllexport) identity_cpp( int ); \ No newline at end of file Copied: pyplusplus_dev/unittests/data/ctypes/pof/sconscript (from rev 1525, pyplusplus_dev/unittests/data/ctypes_pof/sconscript) =================================================================== --- pyplusplus_dev/unittests/data/ctypes/pof/sconscript (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/pof/sconscript 2009-01-04 18:32:59 UTC (rev 1526) @@ -0,0 +1,9 @@ +Import('*') + +target_name = 'ctypes_pof' +shlib = env.SharedLibrary( target=target_name + , source=[ target_name + '.cpp' ] + , CCFLAGS=[ r"/MD",r"/EHsc",r"/GR",r"/Zc:wchar_t",r"/Zc:forScope" ] + , LINKFLAGS=[r"/MAP:${TARGET.base}.map", r"/MAPINFO:EXPORTS"] ) + +env.Alias( target_name, shlib ) Deleted: pyplusplus_dev/unittests/data/ctypes/sconscript =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/sconscript 2009-01-04 11:37:54 UTC (rev 1525) +++ pyplusplus_dev/unittests/data/ctypes/sconscript 2009-01-04 18:32:59 UTC (rev 1526) @@ -1,9 +0,0 @@ -Import('*') - -target_name = 'ctypes_pof' -shlib = env.SharedLibrary( target=target_name - , source=[ target_name + '.cpp' ] - , CCFLAGS=[ r"/MD",r"/EHsc",r"/GR",r"/Zc:wchar_t",r"/Zc:forScope" ] - , LINKFLAGS=[r"/MAP:${TARGET.base}.map", r"/MAPINFO:EXPORTS"] ) - -env.Alias( target_name, shlib ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-04 12:22:22
|
Revision: 1525 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1525&view=rev Author: roman_yakovenko Date: 2009-01-04 11:37:54 +0000 (Sun, 04 Jan 2009) Log Message: ----------- remove cpptypes directory ( all functionality was moved to unittests ) Modified Paths: -------------- pyplusplus_dev/unittests/ctypes_pof_tester.py Removed Paths: ------------- pyplusplus_dev/pyplusplus/cpptypes/ Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-04 07:57:47 UTC (rev 1524) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-04 11:37:54 UTC (rev 1525) @@ -32,7 +32,7 @@ if tester_t._module_ref_: return - autoconfig.scons_config.compile( autoconfig.scons.cmd_build + ' ctypes_pof' ) + autoconfig.scons_config.compile( autoconfig.scons.cmd_build + ' ' + self.base_name ) mb = ctypes_module_builder_t( [self.header], self.symbols_file, autoconfig.cxx_parsers_cfg.gccxml ) mb.build_code_creator( self.symbols_file ) mb.write_module( os.path.join( autoconfig.build_directory, self.module_name + '.py' ) ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-04 07:57:52
|
Revision: 1524 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1524&view=rev Author: roman_yakovenko Date: 2009-01-04 07:57:47 +0000 (Sun, 04 Jan 2009) Log Message: ----------- preparing unittests environment for ctypes testers Modified Paths: -------------- pyplusplus_dev/environment.py pyplusplus_dev/unittests/autoconfig.py pyplusplus_dev/unittests/ctypes_pof_tester.py pyplusplus_dev/unittests/data/ctypes_pof/sconscript pyplusplus_dev/unittests/fundamental_tester_base.py Added Paths: ----------- pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.cpp pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.h Removed Paths: ------------- pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp pyplusplus_dev/unittests/data/ctypes_pof/mydll.h Modified: pyplusplus_dev/environment.py =================================================================== --- pyplusplus_dev/environment.py 2009-01-03 19:48:47 UTC (rev 1523) +++ pyplusplus_dev/environment.py 2009-01-04 07:57:47 UTC (rev 1524) @@ -25,15 +25,11 @@ class scons: suffix = '' - cmd_build = '' - cmd_clean = '' + cmd_build = 'scons' + cmd_clean = 'scons --clean' ccflags = [] if 'roman' in getpass.getuser(): - - scons.cmd_build = 'scons --file=%s' - scons.cmd_clean = 'scons --clean --file=%s' - if sys.platform == 'win32': scons.suffix = '.pyd' scons.ccflags = ['/MD', '/EHsc', '/GR', '/Zc:wchar_t', '/Zc:forScope', '-DBOOST_PYTHON_NO_PY_SIGNATURES' ] @@ -50,10 +46,6 @@ boost.include = '/home/roman/boost_svn' python.include = '/usr/include/python2.5' elif 'root' == getpass.getuser(): - - scons.cmd_build = 'scons --file=%s' - scons.cmd_clean = 'scons --clean --file=%s' - if sys.platform == 'win32': scons.suffix = '.pyd' scons.ccflags = ['/MD', '/EHsc', '/GR', '/Zc:wchar_t', '/Zc:forScope', '-DBOOST_PYTHON_NO_PY_SIGNATURES' ] Modified: pyplusplus_dev/unittests/autoconfig.py =================================================================== --- pyplusplus_dev/unittests/autoconfig.py 2009-01-03 19:48:47 UTC (rev 1523) +++ pyplusplus_dev/unittests/autoconfig.py 2009-01-04 07:57:47 UTC (rev 1524) @@ -7,9 +7,8 @@ import os import sys import unittest +import subprocess -#__pychecker__ = 'limit=1000' -#import pychecker.checker this_module_dir_path = os.path.abspath ( os.path.dirname( sys.modules[__name__].__file__) ) @@ -74,61 +73,32 @@ #~ , " env.AddPostAction(t, 'mt.exe -nologo -manifest %(target)s.pyd.manifest -outputresource:%(target)s.pyd;2' )" ] return os.linesep.join( code ) + @staticmethod + def compile( cmd ) : + print '\n', cmd + process = subprocess.Popen( args=cmd + , shell=True + , stdin=subprocess.PIPE + , stdout=subprocess.PIPE + , stderr=subprocess.STDOUT + , cwd=this_module_dir_path ) + process.stdin.close() + + while process.poll() is None: + line = process.stdout.readline() + print line.rstrip() + for line in process.stdout.readlines(): + print line.rstrip() + if process.returncode: + raise RuntimeError( "unable to compile extension. error: %s" % scons_msg ) + + #I need this in order to allow Python to load just compiled modules sys.path.append( build_dir ) os.chdir( build_dir ) -#~ if sys.platform == 'linux2': - #~ LD_LIBRARY_PATH = 'LD_LIBRARY_PATH' - #~ if not os.environ.has_key( LD_LIBRARY_PATH ) \ - #~ or not set( scons_config.libpath ).issubset( set( os.environ[LD_LIBRARY_PATH].split(':') ) ): - #~ #see http://hathawaymix.org/Weblog/2004-12-30 - #~ print 'error: LD_LIBRARY_PATH has not been set' if sys.platform == 'win32': PATH = os.environ.get( 'PATH', '' ) PATH=PATH + ';' + ';'.join( scons_config.libpath ) os.environ['PATH'] = PATH - - -#~ try: - #~ import pydsc - #~ pydsc.include( r'D:\pygccxml_sources\sources\pyplusplus_dev' ) - #~ pydsc.ignore( [ 'Yakovenko' - #~ , 'Bierbaum' - #~ , 'org' - #~ , 'http' - #~ , 'bool' - #~ , 'str' - #~ , 'www' - #~ , 'param' - #~ , 'txt' - #~ , 'decl' - #~ , 'decls' - #~ , 'namespace' - #~ , 'namespaces' - #~ , 'enum' - #~ , 'const' - #~ , 'GCC' - #~ , 'xcc' - #~ , 'TODO' - #~ , 'typedef' - #~ , 'os' - #~ , 'normcase' - #~ , 'normpath' - #~ , 'scopedef' - #~ , 'ira'#part of Matthias mail address - #~ , 'uka'#part of Matthias mail address - #~ , 'de'#part of Matthias mail address - #~ , 'dat'#file extension of directory cache - #~ , 'config'#parameter description - #~ , 'gccxml'#parameter description - #~ , 'Py++' - #~ , 'pygccxml' - #~ , 'calldef' - #~ , 'XXX' - #~ , 'wstring' - #~ , 'py' - #~ ] ) -#~ except ImportError: - #~ pass Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-03 19:48:47 UTC (rev 1523) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-04 07:57:47 UTC (rev 1524) @@ -11,35 +11,52 @@ from pyplusplus.module_builder import ctypes_module_builder_t class tester_t(unittest.TestCase): + _module_ref_ = None def __init__( self, *args, **keywd ): unittest.TestCase.__init__( self, *args, **keywd ) - self.project_dir = os.path.join( autoconfig.data_directory, 'ctypes_pof' ) - self.header = os.path.join( self.project_dir, 'mydll.h' ) - self.symbols_file = os.path.join( self.project_dir, 'release', 'mydll.dll' ) - self.module_name = 'ctypes_pof' + self.base_name = 'ctypes_pof' - def test(self): + @property + def project_dir( self ): + return os.path.join( autoconfig.data_directory, self.base_name ) + + @property + def header( self ): + return os.path.join( self.project_dir, self.base_name + '.h' ) + + @property + def symbols_file( self ): + return os.path.join( self.project_dir, 'binaries', self.base_name + '.dll' ) + + def setUp( self ): + if tester_t._module_ref_: + return + + autoconfig.scons_config.compile( autoconfig.scons.cmd_build + ' ctypes_pof' ) mb = ctypes_module_builder_t( [self.header], self.symbols_file, autoconfig.cxx_parsers_cfg.gccxml ) - #~ mb.print_declarations() mb.build_code_creator( self.symbols_file ) mb.write_module( os.path.join( autoconfig.build_directory, self.module_name + '.py' ) ) - #mb.code_creator.create() - sys.path.append( autoconfig.build_directory ) - import ctypes_pof + tester_t._module_ref_ = __import__( os.path.join( autoconfig.build_directory, self.base_name + '.py' ) ) - #the following code fails - difference in the calling conventions - #TODO: the following test failes, because of the wrong calling convention used - #self.failUnless( ctypes_pof.identity_cpp( int(111) ) == 111 ) + @property + def module_ref(self): + return self._module_ref_ - #testing constructors - n0 = ctypes_pof.pof.number_t() + def test_constructors(self): + n0 = self.module_ref.pof.number_t() self.failUnless( 0 == n0.get_value() ) - n1 = ctypes_pof.pof.number_t( ctypes.c_long(32) ) + n1 = self.module_ref.pof.number_t( ctypes.c_long(32) ) self.failUnless( 32 == n1.get_value() ) - n2 = ctypes_pof.pof.number_t( ctypes.pointer(n1) ) + n2 = self.module_ref.pof.number_t( ctypes.pointer(n1) ) self.failUnless( 32 == n2.get_value() ) - #testing get/set value + def test_free_functions(self): + #the following code fails - difference in the calling conventions + #TODO: the following test failes, because of the wrong calling convention used + self.failUnless( self.module_ref.identity_cpp( int(111) ) == 111 ) + + def test_get_set_values( self ): + n0 = self.module_ref.pof.number_t() n0.set_value( 1977 ) self.failUnless( 1977 == n0.get_value() ) @@ -58,12 +75,12 @@ #~ self.fail( obj1.get_value() == obj2.get_value() ) - #~ def test_bsc( self ): - #~ root = r'E:\Documents and Settings\romany\Desktop\ToInstall\bsckit70\bscsdk' - #~ mb = ctypes_module_builder_t( [os.path.join( root, 'bsc.h' )] - #~ , os.path.join( root, 'msbsc70.dll' ), autoconfig.cxx_parsers_cfg.gccxml ) - #~ mb.build_code_creator( self.symbols_file ) - #~ mb.write_module( os.path.join( root, 'bsc.py' ) ) + def test_bsc( self ): + root = r'E:\Documents and Settings\romany\Desktop\ToInstall\bsckit70\bscsdk' + mb = ctypes_module_builder_t( [os.path.join( root, 'bsc.h' )] + , os.path.join( root, 'msbsc70.dll' ), autoconfig.cxx_parsers_cfg.gccxml ) + mb.build_code_creator( self.symbols_file ) + mb.write_module( os.path.join( root, 'bsc.py' ) ) def create_suite(): Copied: pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.cpp (from rev 1523, pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp) =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.cpp (rev 0) +++ pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.cpp 2009-01-04 07:57:47 UTC (rev 1524) @@ -0,0 +1,69 @@ +#include "ctypes_pof.h" +#include "windows.h" +#include <iostream> + +namespace pof{ + +number_t::number_t() +: m_value(0) +{ +// std::cout << "{C++} number_t( 0 )" << std::endl; +} + + +number_t::number_t(int value) +: m_value(value) +{ +// std::cout << "{C++} number_t( " << value << " )" << std::endl; +} + +number_t::~number_t() { +// std::cout << "{C++} ~number_t()" << std::endl; +} +void number_t::print_it() const { + std::cout << "{C++} value: " << m_value << std::endl; +} + +int number_t::get_value() const{ + return m_value; +} + +void number_t::set_value(int x){ + m_value = x; +} + +number_t number_t::clone() const{ + return number_t(*this); +} + +std::auto_ptr<number_t> number_t::clone_ptr() const{ + return std::auto_ptr<number_t>( new number_t( *this ) ); +} + +} + +using namespace pof; + +void do_smth( number_aptr_t& ){ +} + +int identity( int some_data){ return some_data;} + +int identity_cpp( int data){ return data; } + +//~ BOOL APIENTRY DllMain( HMODULE hModule, + //~ DWORD ul_reason_for_call, + //~ LPVOID lpReserved + //~ ) +//~ { + //~ switch (ul_reason_for_call) + //~ { + //~ case DLL_PROCESS_ATTACH: + //~ case DLL_THREAD_ATTACH: + //~ case DLL_THREAD_DETACH: + //~ case DLL_PROCESS_DETACH: + //~ break; + //~ } + //~ return TRUE; +//~ } + Copied: pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.h (from rev 1523, pyplusplus_dev/unittests/data/ctypes_pof/mydll.h) =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.h (rev 0) +++ pyplusplus_dev/unittests/data/ctypes_pof/ctypes_pof.h 2009-01-04 07:57:47 UTC (rev 1524) @@ -0,0 +1,36 @@ +#pragma once + +#include <memory> + +namespace pof{ + +class __declspec(dllexport) number_t{ +public: + number_t(); + explicit number_t(int value); + virtual ~number_t(); + virtual void print_it() const; + int get_value() const; + int get_value(){ return m_value; } + void set_value(int x); + + number_t clone() const; + std::auto_ptr<number_t> clone_ptr() const; +private: + int m_value; +}; + +} +template class __declspec(dllexport) std::auto_ptr< pof::number_t >; + +typedef std::auto_ptr< pof::number_t > number_aptr_t; + +void __declspec(dllexport) do_smth( number_aptr_t& ); + +extern "C"{ + +int __declspec(dllexport) identity( int ); + +} + +int __declspec(dllexport) identity_cpp( int ); \ No newline at end of file Deleted: pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2009-01-03 19:48:47 UTC (rev 1523) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2009-01-04 07:57:47 UTC (rev 1524) @@ -1,69 +0,0 @@ -#include "mydll.h" -#include "windows.h" -#include <iostream> - -namespace pof{ - -number_t::number_t() -: m_value(0) -{ -// std::cout << "{C++} number_t( 0 )" << std::endl; -} - - -number_t::number_t(int value) -: m_value(value) -{ -// std::cout << "{C++} number_t( " << value << " )" << std::endl; -} - -number_t::~number_t() { -// std::cout << "{C++} ~number_t()" << std::endl; -} -void number_t::print_it() const { - std::cout << "{C++} value: " << m_value << std::endl; -} - -int number_t::get_value() const{ - return m_value; -} - -void number_t::set_value(int x){ - m_value = x; -} - -number_t number_t::clone() const{ - return number_t(*this); -} - -std::auto_ptr<number_t> number_t::clone_ptr() const{ - return std::auto_ptr<number_t>( new number_t( *this ) ); -} - -} - -using namespace pof; - -void do_smth( number_aptr_t& ){ -} - -int identity( int some_data){ return some_data;} - -int identity_cpp( int data){ return data; } - -BOOL APIENTRY DllMain( HMODULE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved - ) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} - Deleted: pyplusplus_dev/unittests/data/ctypes_pof/mydll.h =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.h 2009-01-03 19:48:47 UTC (rev 1523) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.h 2009-01-04 07:57:47 UTC (rev 1524) @@ -1,36 +0,0 @@ -#pragma once - -#include <memory> - -namespace pof{ - -class __declspec(dllexport) number_t{ -public: - number_t(); - explicit number_t(int value); - virtual ~number_t(); - virtual void print_it() const; - int get_value() const; - int get_value(){ return m_value; } - void set_value(int x); - - number_t clone() const; - std::auto_ptr<number_t> clone_ptr() const; -private: - int m_value; -}; - -} -template class __declspec(dllexport) std::auto_ptr< pof::number_t >; - -typedef std::auto_ptr< pof::number_t > number_aptr_t; - -void __declspec(dllexport) do_smth( number_aptr_t& ); - -extern "C"{ - -int __declspec(dllexport) identity( int ); - -} - -int __declspec(dllexport) identity_cpp( int ); \ No newline at end of file Modified: pyplusplus_dev/unittests/data/ctypes_pof/sconscript =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/sconscript 2009-01-03 19:48:47 UTC (rev 1523) +++ pyplusplus_dev/unittests/data/ctypes_pof/sconscript 2009-01-04 07:57:47 UTC (rev 1524) @@ -1,6 +1,9 @@ Import('*') -t = env.SharedLibrary( target=r'mydll' - , source=[ r'mydll.cpp' ] - , CCFLAGS=[ r"/MD",r"/EHsc",r"/GR",r"/Zc:wchar_t",r"/Zc:forScope" ] - , LINKFLAGS=[r"/MAP:${TARGET.base}.map", r"/MAPINFO:EXPORTS"] ) +target_name = 'ctypes_pof' +shlib = env.SharedLibrary( target=target_name + , source=[ target_name + '.cpp' ] + , CCFLAGS=[ r"/MD",r"/EHsc",r"/GR",r"/Zc:wchar_t",r"/Zc:forScope" ] + , LINKFLAGS=[r"/MAP:${TARGET.base}.map", r"/MAPINFO:EXPORTS"] ) + +env.Alias( target_name, shlib ) Modified: pyplusplus_dev/unittests/fundamental_tester_base.py =================================================================== --- pyplusplus_dev/unittests/fundamental_tester_base.py 2009-01-03 19:48:47 UTC (rev 1523) +++ pyplusplus_dev/unittests/fundamental_tester_base.py 2009-01-04 07:57:47 UTC (rev 1524) @@ -128,24 +128,6 @@ sconstruct_file.write( sconstruct_script ) sconstruct_file.close() - def _create_extension(self): - cmd = autoconfig.scons.cmd_build % self.__generated_scons_file_name - print cmd - output = os.popen( cmd ) - scons_reports = [] - while True: - data = output.readline() - scons_reports.append( data ) - if not data: - break - exit_status = output.close() - scons_msg = ''.join(scons_reports) - if scons_msg: - print os.linesep - print scons_msg - if exit_status: - raise RuntimeError( "unable to compile extension. error: %s" % scons_msg ) - def _clean_build( self, sconstruct_file ): cmd = autoconfig.scons.cmd_clean % sconstruct_file output = os.popen( cmd ) @@ -166,7 +148,7 @@ self._create_extension_source_file() sources = self.get_source_files() self._create_sconstruct(sources) - self._create_extension() + autoconfig.scons_config.compile( autoconfig.scons.cmd_build + ' --file=%s' % self.__generated_scons_file_name ) pypp = __import__( self.__module_name ) self.run_tests(pypp) finally: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-03 19:48:58
|
Revision: 1523 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1523&view=rev Author: roman_yakovenko Date: 2009-01-03 19:48:47 +0000 (Sat, 03 Jan 2009) Log Message: ----------- moving to scons Added Paths: ----------- pyplusplus_dev/unittests/data/ctypes_pof/sconscript pyplusplus_dev/unittests/sconstruct Removed Paths: ------------- pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj Property Changed: ---------------- pyplusplus_dev/unittests/data/ctypes_pof/ Property changes on: pyplusplus_dev/unittests/data/ctypes_pof ___________________________________________________________________ Added: svn:ignore + .sconsign.dblite Deleted: pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj 2009-01-03 09:03:22 UTC (rev 1522) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj 2009-01-03 19:48:47 UTC (rev 1523) @@ -1,187 +0,0 @@ -<?xml version="1.0" encoding="windows-1255"?> -<VisualStudioProject - ProjectType="Visual C++" - Version="8.00" - Name="mydll" - ProjectGUID="{0B9466BC-60F8-4FC2-A1A9-6A01577690E5}" - RootNamespace="mydll" - Keyword="Win32Proj" - > - <Platforms> - <Platform - Name="Win32" - /> - </Platforms> - <ToolFiles> - </ToolFiles> - <Configurations> - <Configuration - Name="Debug|Win32" - OutputDirectory="$(SolutionDir)$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="2" - CharacterSet="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" - MinimalRebuild="true" - BasicRuntimeChecks="3" - RuntimeLibrary="3" - UsePrecompiledHeader="0" - WarningLevel="3" - Detect64BitPortabilityProblems="true" - DebugInformationFormat="4" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - LinkIncremental="2" - GenerateDebugInformation="true" - SubSystem="2" - TargetMachine="1" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCWebDeploymentTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - <Configuration - Name="Release|Win32" - OutputDirectory="$(SolutionDir)$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="2" - CharacterSet="1" - WholeProgramOptimization="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" - RuntimeLibrary="2" - UsePrecompiledHeader="0" - BrowseInformation="1" - WarningLevel="3" - Detect64BitPortabilityProblems="true" - DebugInformationFormat="3" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - LinkIncremental="1" - GenerateDebugInformation="true" - GenerateMapFile="true" - MapFileName="$(TargetDir)$(TargetName).map" - MapExports="true" - SubSystem="2" - OptimizeReferences="2" - EnableCOMDATFolding="2" - TargetMachine="1" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCWebDeploymentTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - </Configurations> - <References> - </References> - <Files> - <File - RelativePath=".\mydll.cpp" - > - </File> - <File - RelativePath=".\mydll.h" - > - </File> - </Files> - <Globals> - </Globals> -</VisualStudioProject> Deleted: pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj 2009-01-03 09:03:22 UTC (rev 1522) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj 2009-01-03 19:48:47 UTC (rev 1523) @@ -1,182 +0,0 @@ -<?xml version="1.0" encoding="Windows-1252"?> -<VisualStudioProject - ProjectType="Visual C++" - Version="9.00" - Name="mydll" - ProjectGUID="{E7A34C45-534F-43A6-AF95-3CA2428619E2}" - RootNamespace="mydll" - Keyword="Win32Proj" - TargetFrameworkVersion="196613" - > - <Platforms> - <Platform - Name="Win32" - /> - </Platforms> - <ToolFiles> - </ToolFiles> - <Configurations> - <Configuration - Name="Debug|Win32" - OutputDirectory="$(SolutionDir)$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="2" - CharacterSet="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" - MinimalRebuild="true" - BasicRuntimeChecks="3" - RuntimeLibrary="3" - UsePrecompiledHeader="2" - WarningLevel="3" - DebugInformationFormat="4" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - LinkIncremental="2" - GenerateDebugInformation="true" - SubSystem="2" - TargetMachine="1" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - <Configuration - Name="Release|Win32" - OutputDirectory="$(SolutionDir)$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="2" - CharacterSet="1" - WholeProgramOptimization="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="2" - EnableIntrinsicFunctions="true" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" - RuntimeLibrary="2" - EnableFunctionLevelLinking="true" - UsePrecompiledHeader="0" - BrowseInformation="1" - WarningLevel="3" - DebugInformationFormat="3" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - LinkIncremental="1" - GenerateDebugInformation="true" - GenerateMapFile="true" - MapExports="true" - SubSystem="2" - OptimizeReferences="2" - EnableCOMDATFolding="2" - TargetMachine="1" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - </Configurations> - <References> - </References> - <Files> - <File - RelativePath=".\mydll.cpp" - > - </File> - <File - RelativePath=".\mydll.h" - > - </File> - </Files> - <Globals> - </Globals> -</VisualStudioProject> Added: pyplusplus_dev/unittests/data/ctypes_pof/sconscript =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/sconscript (rev 0) +++ pyplusplus_dev/unittests/data/ctypes_pof/sconscript 2009-01-03 19:48:47 UTC (rev 1523) @@ -0,0 +1,6 @@ +Import('*') + +t = env.SharedLibrary( target=r'mydll' + , source=[ r'mydll.cpp' ] + , CCFLAGS=[ r"/MD",r"/EHsc",r"/GR",r"/Zc:wchar_t",r"/Zc:forScope" ] + , LINKFLAGS=[r"/MAP:${TARGET.base}.map", r"/MAPINFO:EXPORTS"] ) Added: pyplusplus_dev/unittests/sconstruct =================================================================== --- pyplusplus_dev/unittests/sconstruct (rev 0) +++ pyplusplus_dev/unittests/sconstruct 2009-01-03 19:48:47 UTC (rev 1523) @@ -0,0 +1,15 @@ +import os + +env = Environment() + +if os.path.exists( r'E:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib' ): + env.Append( LIBPATH=[ r'E:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib' + , r'E:\Program Files\Microsoft Visual Studio 9.0\VC\lib'] ) + env.Append( CPPPATH=[r"E:\Program Files\Microsoft SDKs\Windows\v6.0A\Include" + , r"E:\Program Files\Microsoft Visual Studio 9.0\VC\include"]) + +SConscript( 'data/ctypes_pof/sconscript' + , variant_dir='data/ctypes_pof/binaries' + , duplicate=0 + , exports=["env"] ) + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-03 09:03:27
|
Revision: 1522 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1522&view=rev Author: roman_yakovenko Date: 2009-01-03 09:03:22 +0000 (Sat, 03 Jan 2009) Log Message: ----------- adding easybmp example - first working draft Added Paths: ----------- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/ctypes_utils.py pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py pyplusplus_dev/examples/pyeasybmp_dev/ctypes/grayscale.py pyplusplus_dev/examples/pyeasybmp_dev/ctypes/source.bmp pyplusplus_dev/examples/pyeasybmp_dev/ctypes/target.bmp pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.dll pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.dll.manifest pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.exp pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.lib pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.map Added: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/ctypes_utils.py =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/ctypes_utils.py (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/ctypes/ctypes_utils.py 2009-01-03 09:03:22 UTC (rev 1522) @@ -0,0 +1,131 @@ +# This file has been generated by Py++. + +# Copyright 2004-2008 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 ctypes + +# what is the best way to treat overloaded constructors +class native_callable( object ): + def __init__(self, dll, name, restype=None, argtypes=None ): + self.name = name + self.func = getattr( dll, dll.undecorated_names[name] ) + self.func.restype = restype + self.func.argtypes = argtypes + + def __call__(self, *args, **keywd ): + return self.func( *args, **keywd ) + +class native_overloaded_callable( object ): + def __init__(self, functions ): + self.__functions = functions + + def __call__( self, *args ): + types = None + if args: + types = tuple(arg.__class__ for arg in args) + f = self.__functions.get(types) + if f is None: + msg = ['Unable to find a function that match the arguments you passed.'] + msg.append( 'First argument type is "this" type.' ) + msg.append( 'This function call argument types: ' + str( types ) ) + msg.append( 'Registered methods argument types: ' ) + for key in self.__functions.iterkeys(): + msg.append(' ' + str(key)) + raise TypeError(os.linesep.join(msg)) + else: + return f(*args) + +class multi_method_registry_t: + def __init__( self, factory, restype ): + self.factory = factory + self.restype = restype + self.__functions = {} + + def register( self, callable_or_name, argtypes=None ): + if isinstance( callable_or_name, native_callable ): + callable = callable_or_name + else: + name = callable_or_name + callable = self.factory( name, restype=self.restype, argtypes=argtypes ) + self.__functions[ tuple(callable.func.argtypes) ] = callable.func + return self + + def finalize(self): + return native_overloaded_callable( self.__functions ) + + +class mem_fun_factory( object ): + def __init__( self, dll, wrapper, class_name, namespace='' ): + self.dll = dll + self.namespace = namespace + self.class_name = class_name + self.this_type = ctypes.POINTER( wrapper ) + + def __call__( self, name, **keywd ): + if 'argtypes' not in keywd or keywd['argtypes'] is None: + keywd['argtypes'] = [ self.this_type ] + else: + keywd['argtypes'].insert( 0, self.this_type ) + return native_callable( self.dll, name, **keywd ) + + def __get_ns_name(self): + if self.namespace: + return self.namespace + '::' + else: + return '' + + def default_constructor( self ): + return self( '%(ns)s%(class_name)s::%(class_name)s(void)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) ) + + def constructor( self, argtypes_str, **keywd ): + return self( '%(ns)s%(class_name)s::%(class_name)s(%(args)s)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name + , args=argtypes_str ) + , **keywd ) + + def copy_constructor( self ): + return self( '%(ns)s%(class_name)s::%(class_name)s(%(ns)s%(class_name)s const &)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) + , argtypes=[self.this_type] ) + + def destructor( self, is_virtual=False ): + virtuality = '' + if is_virtual: + virtuality = 'virtual ' + return self( '%(virtuality)s%(ns)s%(class_name)s::~%(class_name)s(void)' + % dict( ns=self.__get_ns_name() + , virtuality=virtuality + , class_name=self.class_name ) ) + + def operator_assign( self ): + return self( '%(ns)s%(class_name)s & %(class_name)s::operator=(%(class_name)s const &)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) + , restype=self.this_type + , argtypes=[self.this_type] ) + + def method( self, name, restype_str=None, argtypes_str=None, **keywd ): + if None is restype_str: + restype_str = 'void' + if None is argtypes_str: + argtypes_str = 'void' + + return self( '%(return_)s %(ns)s%(class_name)s::%(method_name)s(%(args)s)' + % dict( return_=restype_str + , ns=self.__get_ns_name() + , class_name=self.class_name + , method_name=name + , args=argtypes_str ) + , **keywd ) + + def multi_method( self, restype=None ): + return multi_method_registry_t( self, restype ) + Added: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/ctypes/easybmp.py 2009-01-03 09:03:22 UTC (rev 1522) @@ -0,0 +1,392 @@ +# This file has been generated by Py++. + +import ctypes + +import ctypes_utils + +easybmp = ctypes.CPPDLL( r"E:\development\language-binding\pyplusplus_dev\examples\pyeasybmp_dev\easybmp\binaries\easybmp.dll" ) + +easybmp.undecorated_names = {#mapping between decorated and undecorated names + "unsigned short FlipWORD(unsigned short)" : "?FlipWORD@@YAGG@Z", + "BMP::BMP(void)" : "??0BMP@@QAE@XZ", + "bool BMP::SetPixel(int,int RGBApixel)" : "?SetPixel@BMP@@QAE_NHHURGBApixel@@@Z", + "bool BMP::Read32bitRow(unsigned char *,int,int)" : "?Read32bitRow@BMP@@AAE_NPAEHH@Z", + "bool BMP::ReadFromFile(char const *)" : "?ReadFromFile@BMP@@QAE_NPBD@Z", + "void BMIH::display(void)" : "?display@BMIH@@QAEXXZ", + "double Square(double)" : "?Square@@YANN@Z", + "unsigned char BMP::FindClosestColor RGBApixel &)" : "?FindClosestColor@BMP@@AAEEAAURGBApixel@@@Z", + "bool BMP::Read24bitRow(unsigned char *,int,int)" : "?Read24bitRow@BMP@@AAE_NPAEHH@Z", + "int BMP::TellBitDepth(void)" : "?TellBitDepth@BMP@@QAEHXZ", + "bool BMP::Write24bitRow(unsigned char *,int,int)" : "?Write24bitRow@BMP@@AAE_NPAEHH@Z", + "BMIH::BMIH(void)" : "??0BMIH@@QAE@XZ", + "int BMP::TellWidth(void)" : "?TellWidth@BMP@@QAEHXZ", + "bool BMP::Write1bitRow(unsigned char *,int,int)" : "?Write1bitRow@BMP@@AAE_NPAEHH@Z", + "RGBApixel & RGBApixel::operator= RGBApixel const &)" : "??4RGBApixel@@QAEAAU0@ABU0@@Z", + "int BMP::TellVerticalDPI(void)" : "?TellVerticalDPI@BMP@@QAEHXZ", + "bool BMP::WriteToFile(char const *)" : "?WriteToFile@BMP@@QAE_NPBD@Z", + "bool BMP::Read4bitRow(unsigned char *,int,int)" : "?Read4bitRow@BMP@@AAE_NPAEHH@Z", + "void BMP::SetDPI(int,int)" : "?SetDPI@BMP@@QAEXHH@Z", + "int IntSquare(int)" : "?IntSquare@@YAHH@Z", + "bool BMP::Write32bitRow(unsigned char *,int,int)" : "?Write32bitRow@BMP@@AAE_NPAEHH@Z", + "BMFH & BMFH::operator= BMFH const &)" : "??4BMFH@@QAEAAV0@ABV0@@Z", + "bool BMP::Read1bitRow(unsigned char *,int,int)" : "?Read1bitRow@BMP@@AAE_NPAEHH@Z", + "BMFH::BMFH(void)" : "??0BMFH@@QAE@XZ", + "BMP::BMP BMP &)" : "??0BMP@@QAE@AAV0@@Z", + "bool BMP::Write4bitRow(unsigned char *,int,int)" : "?Write4bitRow@BMP@@AAE_NPAEHH@Z", + "unsigned int FlipDWORD(unsigned int)" : "?FlipDWORD@@YAII@Z", + "int BMP::TellHeight(void)" : "?TellHeight@BMP@@QAEHXZ", + "bool IsBigEndian(void)" : "?IsBigEndian@@YA_NXZ", + "RGBApixel BMP::GetPixel(int,int)const" : "?GetPixel@BMP@@QBE?AURGBApixel@@HH@Z", + "bool BMP::SetBitDepth(int)" : "?SetBitDepth@BMP@@QAE_NH@Z", + "void BMIH::SwitchEndianess(void)" : "?SwitchEndianess@BMIH@@QAEXXZ", + "int BMP::TellNumberOfColors(void)" : "?TellNumberOfColors@BMP@@QAEHXZ", + "BMP & BMP::operator= BMP const &)" : "??4BMP@@QAEAAV0@ABV0@@Z", + "bool BMP::SetColor(int RGBApixel)" : "?SetColor@BMP@@QAE_NHURGBApixel@@@Z", + "void BMFH::SwitchEndianess(void)" : "?SwitchEndianess@BMFH@@QAEXXZ", + "void BMFH::display(void)" : "?display@BMFH@@QAEXXZ", + "bool BMP::SetSize(int,int)" : "?SetSize@BMP@@QAE_NHH@Z", + "bool BMP::Read8bitRow(unsigned char *,int,int)" : "?Read8bitRow@BMP@@AAE_NPAEHH@Z", + "BMIH & BMIH::operator= BMIH const &)" : "??4BMIH@@QAEAAV0@ABV0@@Z", + "bool BMP::Write8bitRow(unsigned char *,int,int)" : "?Write8bitRow@BMP@@AAE_NPAEHH@Z", + "BMP::~BMP(void)" : "??1BMP@@QAE@XZ", + "RGBApixel * BMP::operator()(int,int)" : "??RBMP@@QAEPAURGBApixel@@HH@Z", + "RGBApixel BMP::GetColor(int)" : "?GetColor@BMP@@QAE?AURGBApixel@@H@Z", + "int BMP::TellHorizontalDPI(void)" : "?TellHorizontalDPI@BMP@@QAEHXZ", + "bool BMP::CreateStandardColorTable(void)" : "?CreateStandardColorTable@BMP@@QAE_NXZ", + "?FlipWORD@@YAGG@Z" : "unsigned short FlipWORD(unsigned short)", + "??0BMP@@QAE@XZ" : "BMP::BMP(void)", + "?SetPixel@BMP@@QAE_NHHURGBApixel@@@Z" : "bool BMP::SetPixel(int,int RGBApixel)", + "?Read32bitRow@BMP@@AAE_NPAEHH@Z" : "bool BMP::Read32bitRow(unsigned char *,int,int)", + "?ReadFromFile@BMP@@QAE_NPBD@Z" : "bool BMP::ReadFromFile(char const *)", + "?display@BMIH@@QAEXXZ" : "void BMIH::display(void)", + "?Square@@YANN@Z" : "double Square(double)", + "?FindClosestColor@BMP@@AAEEAAURGBApixel@@@Z" : "unsigned char BMP::FindClosestColor RGBApixel &)", + "?Read24bitRow@BMP@@AAE_NPAEHH@Z" : "bool BMP::Read24bitRow(unsigned char *,int,int)", + "?TellBitDepth@BMP@@QAEHXZ" : "int BMP::TellBitDepth(void)", + "?Write24bitRow@BMP@@AAE_NPAEHH@Z" : "bool BMP::Write24bitRow(unsigned char *,int,int)", + "??0BMIH@@QAE@XZ" : "BMIH::BMIH(void)", + "?TellWidth@BMP@@QAEHXZ" : "int BMP::TellWidth(void)", + "?Write1bitRow@BMP@@AAE_NPAEHH@Z" : "bool BMP::Write1bitRow(unsigned char *,int,int)", + "??4RGBApixel@@QAEAAU0@ABU0@@Z" : "RGBApixel & RGBApixel::operator= RGBApixel const &)", + "?TellVerticalDPI@BMP@@QAEHXZ" : "int BMP::TellVerticalDPI(void)", + "?WriteToFile@BMP@@QAE_NPBD@Z" : "bool BMP::WriteToFile(char const *)", + "?Read4bitRow@BMP@@AAE_NPAEHH@Z" : "bool BMP::Read4bitRow(unsigned char *,int,int)", + "?SetDPI@BMP@@QAEXHH@Z" : "void BMP::SetDPI(int,int)", + "?IntSquare@@YAHH@Z" : "int IntSquare(int)", + "?Write32bitRow@BMP@@AAE_NPAEHH@Z" : "bool BMP::Write32bitRow(unsigned char *,int,int)", + "??4BMFH@@QAEAAV0@ABV0@@Z" : "BMFH & BMFH::operator= BMFH const &)", + "?Read1bitRow@BMP@@AAE_NPAEHH@Z" : "bool BMP::Read1bitRow(unsigned char *,int,int)", + "??0BMFH@@QAE@XZ" : "BMFH::BMFH(void)", + "??0BMP@@QAE@AAV0@@Z" : "BMP::BMP BMP &)", + "?Write4bitRow@BMP@@AAE_NPAEHH@Z" : "bool BMP::Write4bitRow(unsigned char *,int,int)", + "?FlipDWORD@@YAII@Z" : "unsigned int FlipDWORD(unsigned int)", + "?TellHeight@BMP@@QAEHXZ" : "int BMP::TellHeight(void)", + "?IsBigEndian@@YA_NXZ" : "bool IsBigEndian(void)", + "?GetPixel@BMP@@QBE?AURGBApixel@@HH@Z" : "RGBApixel BMP::GetPixel(int,int)const", + "?SetBitDepth@BMP@@QAE_NH@Z" : "bool BMP::SetBitDepth(int)", + "?SwitchEndianess@BMIH@@QAEXXZ" : "void BMIH::SwitchEndianess(void)", + "?TellNumberOfColors@BMP@@QAEHXZ" : "int BMP::TellNumberOfColors(void)", + "??4BMP@@QAEAAV0@ABV0@@Z" : "BMP & BMP::operator= BMP const &)", + "?SetColor@BMP@@QAE_NHURGBApixel@@@Z" : "bool BMP::SetColor(int RGBApixel)", + "?SwitchEndianess@BMFH@@QAEXXZ" : "void BMFH::SwitchEndianess(void)", + "?display@BMFH@@QAEXXZ" : "void BMFH::display(void)", + "?SetSize@BMP@@QAE_NHH@Z" : "bool BMP::SetSize(int,int)", + "?Read8bitRow@BMP@@AAE_NPAEHH@Z" : "bool BMP::Read8bitRow(unsigned char *,int,int)", + "??4BMIH@@QAEAAV0@ABV0@@Z" : "BMIH & BMIH::operator= BMIH const &)", + "?Write8bitRow@BMP@@AAE_NPAEHH@Z" : "bool BMP::Write8bitRow(unsigned char *,int,int)", + "??1BMP@@QAE@XZ" : "BMP::~BMP(void)", + "??RBMP@@QAEPAURGBApixel@@HH@Z" : "RGBApixel * BMP::operator()(int,int)", + "?GetColor@BMP@@QAE?AURGBApixel@@H@Z" : "RGBApixel BMP::GetColor(int)", + "?TellHorizontalDPI@BMP@@QAEHXZ" : "int BMP::TellHorizontalDPI(void)", + "?CreateStandardColorTable@BMP@@QAE_NXZ" : "bool BMP::CreateStandardColorTable(void)", +} + +class BMFH(ctypes.Structure): + """class BMFH""" + + def __init__( self, *args ): + """BMFH::BMFH(void)""" + return self._methods_['__init__']( ctypes.pointer( self ), *args ) + + def display( self, *args ): + """void BMFH::display(void)""" + return self._methods_['display']( ctypes.pointer( self ), *args ) + + def SwitchEndianess( self, *args ): + """void BMFH::SwitchEndianess(void)""" + return self._methods_['SwitchEndianess']( ctypes.pointer( self ), *args ) + +class BMIH(ctypes.Structure): + """class BMIH""" + + def __init__( self, *args ): + """BMIH::BMIH(void)""" + return self._methods_['__init__']( ctypes.pointer( self ), *args ) + + def display( self, *args ): + """void BMIH::display(void)""" + return self._methods_['display']( ctypes.pointer( self ), *args ) + + def SwitchEndianess( self, *args ): + """void BMIH::SwitchEndianess(void)""" + return self._methods_['SwitchEndianess']( ctypes.pointer( self ), *args ) + +class BMP(ctypes.Structure): + """class BMP""" + + def TellBitDepth( self, *args ): + """int BMP::TellBitDepth(void)""" + return self._methods_['TellBitDepth']( ctypes.pointer( self ), *args ) + + def TellWidth( self, *args ): + """int BMP::TellWidth(void)""" + return self._methods_['TellWidth']( ctypes.pointer( self ), *args ) + + def TellHeight( self, *args ): + """int BMP::TellHeight(void)""" + return self._methods_['TellHeight']( ctypes.pointer( self ), *args ) + + def TellNumberOfColors( self, *args ): + """int BMP::TellNumberOfColors(void)""" + return self._methods_['TellNumberOfColors']( ctypes.pointer( self ), *args ) + + def SetDPI( self, *args ): + """void BMP::SetDPI(int,int)""" + return self._methods_['SetDPI']( ctypes.pointer( self ), *args ) + + def TellVerticalDPI( self, *args ): + """int BMP::TellVerticalDPI(void)""" + return self._methods_['TellVerticalDPI']( ctypes.pointer( self ), *args ) + + def TellHorizontalDPI( self, *args ): + """int BMP::TellHorizontalDPI(void)""" + return self._methods_['TellHorizontalDPI']( ctypes.pointer( self ), *args ) + + def __init__( self, *args ): + """BMP::BMP(void)""" + return self._methods_['__init__']( ctypes.pointer( self ), *args ) + + def __del__( self ): + """BMP::~BMP(void)""" + return self._methods_['__del__']( ctypes.pointer( self ) ) + + def GetPixel( self, *args ): + """RGBApixel BMP::GetPixel(int,int)const""" + return self._methods_['GetPixel']( ctypes.pointer( self ), *args ) + + def CreateStandardColorTable( self, *args ): + """bool BMP::CreateStandardColorTable(void)""" + return self._methods_['CreateStandardColorTable']( ctypes.pointer( self ), *args ) + + def SetSize( self, *args ): + """bool BMP::SetSize(int,int)""" + return self._methods_['SetSize']( ctypes.pointer( self ), *args ) + + def SetBitDepth( self, *args ): + """bool BMP::SetBitDepth(int)""" + return self._methods_['SetBitDepth']( ctypes.pointer( self ), *args ) + + def WriteToFile( self, *args ): + """bool BMP::WriteToFile(char const *)""" + return self._methods_['WriteToFile']( ctypes.pointer( self ), *args ) + + def ReadFromFile( self, *args ): + """bool BMP::ReadFromFile(char const *)""" + return self._methods_['ReadFromFile']( ctypes.pointer( self ), *args ) + + def GetColor( self, *args ): + """RGBApixel BMP::GetColor(int)""" + return self._methods_['GetColor']( ctypes.pointer( self ), *args ) + + def Read32bitRow( self, *args ): + """bool BMP::Read32bitRow(unsigned char *,int,int)""" + return self._methods_['Read32bitRow']( ctypes.pointer( self ), *args ) + + def Read24bitRow( self, *args ): + """bool BMP::Read24bitRow(unsigned char *,int,int)""" + return self._methods_['Read24bitRow']( ctypes.pointer( self ), *args ) + + def Read8bitRow( self, *args ): + """bool BMP::Read8bitRow(unsigned char *,int,int)""" + return self._methods_['Read8bitRow']( ctypes.pointer( self ), *args ) + + def Read4bitRow( self, *args ): + """bool BMP::Read4bitRow(unsigned char *,int,int)""" + return self._methods_['Read4bitRow']( ctypes.pointer( self ), *args ) + + def Read1bitRow( self, *args ): + """bool BMP::Read1bitRow(unsigned char *,int,int)""" + return self._methods_['Read1bitRow']( ctypes.pointer( self ), *args ) + + def Write32bitRow( self, *args ): + """bool BMP::Write32bitRow(unsigned char *,int,int)""" + return self._methods_['Write32bitRow']( ctypes.pointer( self ), *args ) + + def Write24bitRow( self, *args ): + """bool BMP::Write24bitRow(unsigned char *,int,int)""" + return self._methods_['Write24bitRow']( ctypes.pointer( self ), *args ) + + def Write8bitRow( self, *args ): + """bool BMP::Write8bitRow(unsigned char *,int,int)""" + return self._methods_['Write8bitRow']( ctypes.pointer( self ), *args ) + + def Write4bitRow( self, *args ): + """bool BMP::Write4bitRow(unsigned char *,int,int)""" + return self._methods_['Write4bitRow']( ctypes.pointer( self ), *args ) + + def Write1bitRow( self, *args ): + """bool BMP::Write1bitRow(unsigned char *,int,int)""" + return self._methods_['Write1bitRow']( ctypes.pointer( self ), *args ) + +class RGBApixel(ctypes.Structure): + """class RGBApixel""" + +BMFH._fields_ = [ #class BMFH + ("bfType", ctypes.c_ushort), + ("bfSize", ctypes.c_uint), + ("bfReserved1", ctypes.c_ushort), + ("bfReserved2", ctypes.c_ushort), + ("bfOffBits", ctypes.c_uint), +] + +mfcreator = ctypes_utils.mem_fun_factory( easybmp, BMFH, "BMFH", "" ) +BMFH._methods_ = { #class non-virtual member functions definition list + "__init__" : mfcreator.multi_method() + .register( mfcreator.default_constructor() ) + .finalize(), + + "display" : mfcreator( "void BMFH::display(void)" ), + + "SwitchEndianess" : mfcreator( "void BMFH::SwitchEndianess(void)" ), +} +del mfcreator + +BMIH._fields_ = [ #class BMIH + ("biSize", ctypes.c_uint), + ("biWidth", ctypes.c_uint), + ("biHeight", ctypes.c_uint), + ("biPlanes", ctypes.c_ushort), + ("biBitCount", ctypes.c_ushort), + ("biCompression", ctypes.c_uint), + ("biSizeImage", ctypes.c_uint), + ("biXPelsPerMeter", ctypes.c_uint), + ("biYPelsPerMeter", ctypes.c_uint), + ("biClrUsed", ctypes.c_uint), + ("biClrImportant", ctypes.c_uint), +] + +mfcreator = ctypes_utils.mem_fun_factory( easybmp, BMIH, "BMIH", "" ) +BMIH._methods_ = { #class non-virtual member functions definition list + "__init__" : mfcreator.multi_method() + .register( mfcreator.default_constructor() ) + .finalize(), + + "display" : mfcreator( "void BMIH::display(void)" ), + + "SwitchEndianess" : mfcreator( "void BMIH::SwitchEndianess(void)" ), +} +del mfcreator + +RGBApixel._fields_ = [ #class RGBApixel + ("Blue", ctypes.c_ubyte), + ("Green", ctypes.c_ubyte), + ("Red", ctypes.c_ubyte), + ("Alpha", ctypes.c_ubyte), +] + +mfcreator = ctypes_utils.mem_fun_factory( easybmp, RGBApixel, "RGBApixel", "" ) +RGBApixel._methods_ = { #class non-virtual member functions definition list + +} +del mfcreator + +BMP._fields_ = [ #class BMP + ("BitDepth", ctypes.c_int), + ("Width", ctypes.c_int), + ("Height", ctypes.c_int), + ("Pixels", ctypes.POINTER( ctypes.POINTER( RGBApixel ) )), + ("Colors", ctypes.POINTER( RGBApixel )), + ("XPelsPerMeter", ctypes.c_int), + ("YPelsPerMeter", ctypes.c_int), + ("MetaData1", ctypes.POINTER( ctypes.c_ubyte )), + ("SizeOfMetaData1", ctypes.c_int), + ("MetaData2", ctypes.POINTER( ctypes.c_ubyte )), + ("SizeOfMetaData2", ctypes.c_int), +] + +mfcreator = ctypes_utils.mem_fun_factory( easybmp, BMP, "BMP", "" ) +BMP._methods_ = { #class non-virtual member functions definition list + "TellBitDepth" : mfcreator( "int BMP::TellBitDepth(void)", restype=ctypes.c_int ), + + "TellWidth" : mfcreator( "int BMP::TellWidth(void)", restype=ctypes.c_int ), + + "TellHeight" : mfcreator( "int BMP::TellHeight(void)", restype=ctypes.c_int ), + + "TellNumberOfColors" : mfcreator( "int BMP::TellNumberOfColors(void)", restype=ctypes.c_int ), + + "SetDPI" : mfcreator( "void BMP::SetDPI(int,int)", argtypes=[ ctypes.c_int, ctypes.c_int ] ), + + "TellVerticalDPI" : mfcreator( "int BMP::TellVerticalDPI(void)", restype=ctypes.c_int ), + + "TellHorizontalDPI" : mfcreator( "int BMP::TellHorizontalDPI(void)", restype=ctypes.c_int ), + + "__init__" : mfcreator.multi_method() + .register( mfcreator.default_constructor() ) + .finalize(), + + "__del__" : mfcreator.destructor(is_virtual=False), + + "GetPixel" : mfcreator( "RGBApixel BMP::GetPixel(int,int)const", restype=RGBApixel, argtypes=[ ctypes.c_int, ctypes.c_int ] ), + + "CreateStandardColorTable" : mfcreator( "bool BMP::CreateStandardColorTable(void)", restype=ctypes.c_bool ), + + "SetSize" : mfcreator( "bool BMP::SetSize(int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.c_int, ctypes.c_int ] ), + + "SetBitDepth" : mfcreator( "bool BMP::SetBitDepth(int)", restype=ctypes.c_bool, argtypes=[ ctypes.c_int ] ), + + "WriteToFile" : mfcreator( "bool BMP::WriteToFile(char const *)", restype=ctypes.c_bool, argtypes=[ ctypes.c_char_p ] ), + + "ReadFromFile" : mfcreator( "bool BMP::ReadFromFile(char const *)", restype=ctypes.c_bool, argtypes=[ ctypes.c_char_p ] ), + + "GetColor" : mfcreator( "RGBApixel BMP::GetColor(int)", restype=RGBApixel, argtypes=[ ctypes.c_int ] ), + + "Read32bitRow" : mfcreator( "bool BMP::Read32bitRow(unsigned char *,int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.POINTER( ctypes.c_ubyte ), ctypes.c_int, ctypes.c_int ] ), + + "Read24bitRow" : mfcreator( "bool BMP::Read24bitRow(unsigned char *,int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.POINTER( ctypes.c_ubyte ), ctypes.c_int, ctypes.c_int ] ), + + "Read8bitRow" : mfcreator( "bool BMP::Read8bitRow(unsigned char *,int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.POINTER( ctypes.c_ubyte ), ctypes.c_int, ctypes.c_int ] ), + + "Read4bitRow" : mfcreator( "bool BMP::Read4bitRow(unsigned char *,int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.POINTER( ctypes.c_ubyte ), ctypes.c_int, ctypes.c_int ] ), + + "Read1bitRow" : mfcreator( "bool BMP::Read1bitRow(unsigned char *,int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.POINTER( ctypes.c_ubyte ), ctypes.c_int, ctypes.c_int ] ), + + "Write32bitRow" : mfcreator( "bool BMP::Write32bitRow(unsigned char *,int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.POINTER( ctypes.c_ubyte ), ctypes.c_int, ctypes.c_int ] ), + + "Write24bitRow" : mfcreator( "bool BMP::Write24bitRow(unsigned char *,int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.POINTER( ctypes.c_ubyte ), ctypes.c_int, ctypes.c_int ] ), + + "Write8bitRow" : mfcreator( "bool BMP::Write8bitRow(unsigned char *,int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.POINTER( ctypes.c_ubyte ), ctypes.c_int, ctypes.c_int ] ), + + "Write4bitRow" : mfcreator( "bool BMP::Write4bitRow(unsigned char *,int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.POINTER( ctypes.c_ubyte ), ctypes.c_int, ctypes.c_int ] ), + + "Write1bitRow" : mfcreator( "bool BMP::Write1bitRow(unsigned char *,int,int)", restype=ctypes.c_bool, argtypes=[ ctypes.POINTER( ctypes.c_ubyte ), ctypes.c_int, ctypes.c_int ] ), +} +del mfcreator + +Square = getattr( easybmp, easybmp.undecorated_names["double Square(double)"] ) +Square.restype = ctypes.c_double +Square.argtypes = [ ctypes.c_double ] + +IntSquare = getattr( easybmp, easybmp.undecorated_names["int IntSquare(int)"] ) +IntSquare.restype = ctypes.c_int +IntSquare.argtypes = [ ctypes.c_int ] + +FlipDWORD = getattr( easybmp, easybmp.undecorated_names["unsigned int FlipDWORD(unsigned int)"] ) +FlipDWORD.restype = ctypes.c_uint +FlipDWORD.argtypes = [ ctypes.c_uint ] + +IsBigEndian = getattr( easybmp, easybmp.undecorated_names["bool IsBigEndian(void)"] ) +IsBigEndian.restype = ctypes.c_bool + +FlipWORD = getattr( easybmp, easybmp.undecorated_names["unsigned short FlipWORD(unsigned short)"] ) +FlipWORD.restype = ctypes.c_ushort +FlipWORD.argtypes = [ ctypes.c_ushort ] Added: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/grayscale.py =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/grayscale.py (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/ctypes/grayscale.py 2009-01-03 09:03:22 UTC (rev 1522) @@ -0,0 +1,51 @@ +#! /usr/bin/python +# Copyright 2004-2008 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 sys +import math +import easybmp as pyeasybmp + +pyeasybmp.IntSquare = lambda x: int( math.sqrt( x ) ) + +def grayscale_example(source, target): + bmp = pyeasybmp.BMP() + if not bmp.ReadFromFile( source ): + raise RuntimeError( "Unable to read .bmp file %s" % source ) + + print 'width : ', bmp.TellWidth() + print 'height : ', bmp.TellHeight() + print 'bit depth: ', bmp.TellBitDepth() + print 'number of colors: ', bmp.TellNumberOfColors() + + print bmp.GetPixel( 1,1 ) + + byte = lambda x: 255 & x + + for j in range( bmp.TellHeight() ): + j += 1 + for i in range( bmp.TellWidth() ): + i += 1 + print i, ', ', j + temp = pyeasybmp.IntSquare( bmp.GetPixel(i,j).Red ) \ + + pyeasybmp.IntSquare( bmp.GetPixel(i,j).Green ) \ + + pyeasybmp.IntSquare( bmp.GetPixel(i,j).Blue ) + temp = int( math.floor( math.sqrt( temp / 3.0 ) ) ) + bmp.GetPixel(i,j).Red = byte( temp ) + bmp.GetPixel(i,j).Green = byte( temp ) + bmp.GetPixel(i,j).Blue = byte( temp ) + + if bmp.TellBitDepth() < 24: + pyeasybmp.CreateGrayscaleColorTable( bmp ) + + bmp.WriteToFile( target ) + +if __name__ == "__main__": + if 1 == len( sys.argv ): + print 'not enough arguments. first arg is source bmp, second is target bmp' + print 'entering demo mode' + sys.argv.append( './source.bmp' ) + sys.argv.append( './target.bmp' ) + grayscale_example( sys.argv[1], sys.argv[2] ) Added: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/source.bmp =================================================================== (Binary files differ) Property changes on: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/source.bmp ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/target.bmp =================================================================== (Binary files differ) Property changes on: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/target.bmp ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.dll =================================================================== (Binary files differ) Property changes on: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.dll ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.dll.manifest =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.dll.manifest (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.dll.manifest 2009-01-03 09:03:22 UTC (rev 1522) @@ -0,0 +1,15 @@ +<?xml version='1.0' encoding='UTF-8' standalone='yes'?> +<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> + <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> + <security> + <requestedPrivileges> + <requestedExecutionLevel level='asInvoker' uiAccess='false' /> + </requestedPrivileges> + </security> + </trustInfo> + <dependency> + <dependentAssembly> + <assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' /> + </dependentAssembly> + </dependency> +</assembly> Added: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.exp =================================================================== (Binary files differ) Property changes on: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.exp ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.lib =================================================================== (Binary files differ) Property changes on: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.lib ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.map =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.map (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/binaries/easybmp.map 2009-01-03 09:03:22 UTC (rev 1522) @@ -0,0 +1,322 @@ + easybmp + + Timestamp is 495f259b (Sat Jan 03 10:45:15 2009) + + Preferred load address is 10000000 + + Start Length Name Class + 0001:00000000 00006934H .text CODE + 0001:00006940 00000083H .text$x CODE + 0002:00000000 0000011cH .idata$5 DATA + 0002:0000011c 00000004H .CRT$XCA DATA + 0002:00000120 00000004H .CRT$XCZ DATA + 0002:00000124 00000004H .CRT$XIA DATA + 0002:00000128 00000004H .CRT$XIAA DATA + 0002:0000012c 00000004H .CRT$XIC DATA + 0002:00000130 00000004H .CRT$XIZ DATA + 0002:00000138 00001288H .rdata DATA + 0002:000013c0 00000010H .rdata$sxdata DATA + 0002:000013d0 00000004H .rtc$IAA DATA + 0002:000013d4 00000004H .rtc$IZZ DATA + 0002:000013d8 00000004H .rtc$TAA DATA + 0002:000013dc 00000004H .rtc$TZZ DATA + 0002:000013e0 0000013cH .xdata$x DATA + 0002:0000151c 0000003cH .idata$2 DATA + 0002:00001558 00000014H .idata$3 DATA + 0002:0000156c 0000011cH .idata$4 DATA + 0002:00001688 00000878H .idata$6 DATA + 0002:00001f00 000006eaH .edata DATA + 0003:00000000 00000020H .data DATA + 0003:00000020 00000354H .bss DATA + + Address Publics by Value Rva+Base Lib:Object + + 0000:00000000 __except_list 00000000 <absolute> + 0000:00000004 ___safe_se_handler_count 00000004 <absolute> + 0000:00009876 __fltused 00009876 <absolute> + 0000:00009876 __ldused 00009876 <absolute> + 0000:00000000 ___ImageBase 10000000 <linker-defined> + 0001:00000000 ?Square@@YANN@Z 10001000 f i EasyBMP.obj + 0001:00000010 ?IntSquare@@YAHH@Z 10001010 f i EasyBMP.obj + 0001:00000020 ?IsBigEndian@@YA_NXZ 10001020 f i EasyBMP.obj + 0001:00000040 ?FlipWORD@@YAGG@Z 10001040 f i EasyBMP.obj + 0001:00000060 ?FlipDWORD@@YAII@Z 10001060 f i EasyBMP.obj + 0001:000000a0 ??4RGBApixel@@QAEAAU0@ABU0@@Z 100010a0 f i EasyBMP.obj + 0001:000000c0 ??4BMFH@@QAEAAV0@ABV0@@Z 100010c0 f i EasyBMP.obj + 0001:000000f0 ??4BMIH@@QAEAAV0@ABV0@@Z 100010f0 f i EasyBMP.obj + 0001:00000120 ??4BMP@@QAEAAV0@ABV0@@Z 10001120 f i EasyBMP.obj + 0001:00000150 ?SetEasyBMPwarningsOff@@YAXXZ 10001150 f EasyBMP.obj + 0001:00000160 ?SetEasyBMPwarningsOn@@YAXXZ 10001160 f EasyBMP.obj + 0001:00000170 ?GetEasyBMPwarningState@@YA_NXZ 10001170 f EasyBMP.obj + 0001:00000180 ?IntPow@@YAHHH@Z 10001180 f EasyBMP.obj + 0001:000001c0 ??0BMFH@@QAE@XZ 100011c0 f EasyBMP.obj + 0001:000001f0 ?SwitchEndianess@BMFH@@QAEXXZ 100011f0 f EasyBMP.obj + 0001:00000270 ??0BMIH@@QAE@XZ 10001270 f EasyBMP.obj + 0001:000002c0 ?SwitchEndianess@BMIH@@QAEXXZ 100012c0 f EasyBMP.obj + 0001:000003c0 ?display@BMIH@@QAEXXZ 100013c0 f EasyBMP.obj + 0001:000005d0 ?display@BMFH@@QAEXXZ 100015d0 f EasyBMP.obj + 0001:000006d0 ?GetPixel@BMP@@QBE?AURGBApixel@@HH@Z 100016d0 f EasyBMP.obj + 0001:00000840 ?SetPixel@BMP@@QAE_NHHURGBApixel@@@Z 10001840 f EasyBMP.obj + 0001:00000870 ?SetColor@BMP@@QAE_NHURGBApixel@@@Z 10001870 f EasyBMP.obj + 0001:000009f0 ?GetColor@BMP@@QAE?AURGBApixel@@H@Z 100019f0 f EasyBMP.obj + 0001:00000bb0 ??0BMP@@QAE@XZ 10001bb0 f EasyBMP.obj + 0001:00000c80 ??0BMP@@QAE@AAV0@@Z 10001c80 f EasyBMP.obj + 0001:00000e50 ??1BMP@@QAE@XZ 10001e50 f EasyBMP.obj + 0001:00000f10 ??RBMP@@QAEPAURGBApixel@@HH@Z 10001f10 f EasyBMP.obj + 0001:00001030 ?TellBitDepth@BMP@@QAEHXZ 10002030 f EasyBMP.obj + 0001:00001040 ?TellHeight@BMP@@QAEHXZ 10002040 f EasyBMP.obj + 0001:00001060 ?TellWidth@BMP@@QAEHXZ 10002060 f EasyBMP.obj + 0001:00001080 ?TellNumberOfColors@BMP@@QAEHXZ 10002080 f EasyBMP.obj + 0001:000010c0 ?SetBitDepth@BMP@@QAE_NH@Z 100020c0 f EasyBMP.obj + 0001:00001240 ?SetSize@BMP@@QAE_NHH@Z 10002240 f EasyBMP.obj + 0001:00001460 ?WriteToFile@BMP@@QAE_NPBD@Z 10002460 f EasyBMP.obj + 0001:00002000 ?ReadFromFile@BMP@@QAE_NPBD@Z 10003000 f EasyBMP.obj + 0001:00003280 ?CreateStandardColorTable@BMP@@QAE_NXZ 10004280 f EasyBMP.obj + 0001:00003910 ?SafeFread@@YA_NPADHHPAU_iobuf@@@Z 10004910 f EasyBMP.obj + 0001:00003960 ?SetDPI@BMP@@QAEXHH@Z 10004960 f EasyBMP.obj + 0001:000039a0 ?TellVerticalDPI@BMP@@QAEHXZ 100049a0 f EasyBMP.obj + 0001:000039d0 ?TellHorizontalDPI@BMP@@QAEHXZ 100049d0 f EasyBMP.obj + 0001:00003a00 ?GetBMFH@@YA?AVBMFH@@PBD@Z 10004a00 f EasyBMP.obj + 0001:00003b60 ?GetBMIH@@YA?AVBMIH@@PBD@Z 10004b60 f EasyBMP.obj + 0001:00003d50 ?DisplayBitmapInfo@@YAXPBD@Z 10004d50 f EasyBMP.obj + 0001:00004150 ?GetBitmapColorDepth@@YAHPBD@Z 10005150 f EasyBMP.obj + 0001:00004170 ?PixelToPixelCopy@@YAXAAVBMP@@HH0HH@Z 10005170 f EasyBMP.obj + 0001:000041a0 ?PixelToPixelCopyTransparent@@YAXAAVBMP@@HH0HHAAURGBApixel@@@Z 100051a0 f EasyBMP.obj + 0001:00004230 ?RangedPixelToPixelCopy@@YAXAAVBMP@@HHHH0HH@Z 10005230 f EasyBMP.obj + 0001:00004360 ?RangedPixelToPixelCopyTransparent@@YAXAAVBMP@@HHHH0HHAAURGBApixel@@@Z 10005360 f EasyBMP.obj + 0001:00004490 ?CreateGrayscaleColorTable@@YA_NAAVBMP@@@Z 10005490 f EasyBMP.obj + 0001:000045a0 ?Read32bitRow@BMP@@AAE_NPAEHH@Z 100055a0 f EasyBMP.obj + 0001:00004610 ?Read24bitRow@BMP@@AAE_NPAEHH@Z 10005610 f EasyBMP.obj + 0001:00004680 ?Read8bitRow@BMP@@AAE_NPAEHH@Z 10005680 f EasyBMP.obj + 0001:00004700 ?Read4bitRow@BMP@@AAE_NPAEHH@Z 10005700 f EasyBMP.obj + 0001:000047e0 ?Read1bitRow@BMP@@AAE_NPAEHH@Z 100057e0 f EasyBMP.obj + 0001:00004910 ?Write32bitRow@BMP@@AAE_NPAEHH@Z 10005910 f EasyBMP.obj + 0001:00004980 ?Write24bitRow@BMP@@AAE_NPAEHH@Z 10005980 f EasyBMP.obj + 0001:000049f0 ?Write8bitRow@BMP@@AAE_NPAEHH@Z 100059f0 f EasyBMP.obj + 0001:00004a60 ?Write4bitRow@BMP@@AAE_NPAEHH@Z 10005a60 f EasyBMP.obj + 0001:00004b30 ?Write1bitRow@BMP@@AAE_NPAEHH@Z 10005b30 f EasyBMP.obj + 0001:00004c20 ?FindClosestColor@BMP@@AAEEAAURGBApixel@@@Z 10005c20 f EasyBMP.obj + 0001:00004cf0 ?EasyBMPcheckDataSize@@YA_NXZ 10005cf0 f EasyBMP.obj + 0001:00004e40 ?Rescale@@YA_NAAVBMP@@DH@Z 10005e40 f EasyBMP.obj + 0001:00005a30 ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z 10006a30 f i EasyBMP.obj + 0001:00005d10 ??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@AAV12@@Z 10006d10 f i EasyBMP.obj + 0001:00005dd0 ??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@XZ 10006dd0 f i EasyBMP.obj + 0001:00005e40 ??Bsentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QBE_NXZ 10006e40 f i EasyBMP.obj + 0001:00005e60 ??0_Sentry_base@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@AAV12@@Z 10006e60 f i EasyBMP.obj + 0001:00005eb0 ??1_Sentry_base@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@XZ 10006eb0 f i EasyBMP.obj + 0001:00005ef1 ??_U@YAPAXI@Z 10006ef1 f msvcprt:newaop_s.obj + 0001:00005f00 ??_V@YAXPAX@Z 10006f00 f MSVCRT:MSVCR90.dll + 0001:00005f10 __ftol2_sse 10006f10 f MSVCRT:ftol2.obj + 0001:00005f19 __ftol2_pentium4 10006f19 f MSVCRT:ftol2.obj + 0001:00005f2c __ftol2_sse_excpt 10006f2c f MSVCRT:ftol2.obj + 0001:00005f46 __ftol2 10006f46 f MSVCRT:ftol2.obj + 0001:00005fbc _memcpy 10006fbc f MSVCRT:MSVCR90.dll + 0001:00005fc2 ___CxxFrameHandler3 10006fc2 f MSVCRT:MSVCR90.dll + 0001:00005fc8 @__security_check_cookie@4 10006fc8 f MSVCRT:secchk.obj + 0001:00006026 __CRT_INIT@12 10007026 f MSVCRT:crtdll.obj + 0001:00006362 __DllMainCRTStartup@12 10007362 f MSVCRT:crtdll.obj + 0001:00006386 ??2@YAPAXI@Z 10007386 f MSVCRT:MSVCR90.dll + 0001:000063dc __get_sse2_info 100073dc f MSVCRT:cpu_disp.obj + 0001:0000643e ___sse2_available_init 1000743e f MSVCRT:cpu_disp.obj + 0001:0000644b ___report_gsfailure 1000744b f MSVCRT:gs_report.obj + 0001:00006551 ___clean_type_info_names 10007551 f MSVCRT:tncleanup.obj + 0001:0000655d __onexit 1000755d f MSVCRT:atonexit.obj + 0001:00006602 _atexit 10007602 f MSVCRT:atonexit.obj + 0001:00006619 __RTC_Initialize 10007619 f MSVCRT:_initsect_.obj + 0001:0000663f __RTC_Terminate 1000763f f MSVCRT:_initsect_.obj + 0001:00006670 __ValidateImageBase 10007670 f MSVCRT:pesect.obj + 0001:000066b0 __FindPESection 100076b0 f MSVCRT:pesect.obj + 0001:00006700 __IsNonwritableInCurrentImage 10007700 f MSVCRT:pesect.obj + 0001:000067be __initterm 100077be f MSVCRT:MSVCR90.dll + 0001:000067c4 __initterm_e 100077c4 f MSVCRT:MSVCR90.dll + 0001:000067ca __amsg_exit 100077ca f MSVCRT:MSVCR90.dll + 0001:000067d0 ___CppXcptFilter 100077d0 f MSVCRT:MSVCR90.dll + 0001:000067d6 _DllMain@12 100077d6 f MSVCRT:dllmain.obj + 0001:000067fc __SEH_prolog4 100077fc f MSVCRT:sehprolg4.obj + 0001:00006841 __SEH_epilog4 10007841 f MSVCRT:sehprolg4.obj + 0001:00006855 __except_handler4 10007855 f MSVCRT:chandler4gs.obj + 0001:0000687a ___security_init_cookie 1000787a f MSVCRT:gs_support.obj + 0001:00006910 __crt_debugger_hook 10007910 f MSVCRT:MSVCR90.dll + 0001:00006916 ___clean_type_info_names_internal 10007916 f MSVCRT:MSVCR90.dll + 0001:0000691c __unlock 1000791c f MSVCRT:MSVCR90.dll + 0001:00006922 ___dllonexit 10007922 f MSVCRT:MSVCR90.dll + 0001:00006928 __lock 10007928 f MSVCRT:MSVCR90.dll + 0001:0000692e __except_handler4_common 1000792e f MSVCRT:MSVCR90.dll + 0002:00000000 __imp__Sleep@4 10008000 kernel32:KERNEL32.dll + 0002:00000004 __imp__InterlockedCompareExchange@12 10008004 kernel32:KERNEL32.dll + 0002:00000008 __imp__TerminateProcess@8 10008008 kernel32:KERNEL32.dll + 0002:0000000c __imp__GetCurrentProcess@0 1000800c kernel32:KERNEL32.dll + 0002:00000010 __imp__UnhandledExceptionFilter@4 10008010 kernel32:KERNEL32.dll + 0002:00000014 __imp__SetUnhandledExceptionFilter@4 10008014 kernel32:KERNEL32.dll + 0002:00000018 __imp__IsDebuggerPresent@0 10008018 kernel32:KERNEL32.dll + 0002:0000001c __imp__DisableThreadLibraryCalls@4 1000801c kernel32:KERNEL32.dll + 0002:00000020 __imp__QueryPerformanceCounter@4 10008020 kernel32:KERNEL32.dll + 0002:00000024 __imp__GetTickCount@0 10008024 kernel32:KERNEL32.dll + 0002:00000028 __imp__GetCurrentThreadId@0 10008028 kernel32:KERNEL32.dll + 0002:0000002c __imp__GetCurrentProcessId@0 1000802c kernel32:KERNEL32.dll + 0002:00000030 __imp__GetSystemTimeAsFileTime@4 10008030 kernel32:KERNEL32.dll + 0002:00000034 __imp__InterlockedExchange@8 10008034 kernel32:KERNEL32.dll + 0002:00000038 \177KERNEL32_NULL_THUNK_DATA 10008038 kernel32:KERNEL32.dll + 0002:0000003c __imp_?width@ios_base@std@@QBEHXZ 1000803c msvcprt:MSVCP90.dll + 0002:00000040 __imp_?length@?$char_traits@D@std@@SAIPBD@Z 10008040 msvcprt:MSVCP90.dll + 0002:00000044 __imp_?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ 10008044 msvcprt:MSVCP90.dll + 0002:00000048 __imp_?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ 10008048 msvcprt:MSVCP90.dll + 0002:0000004c __imp_?good@ios_base@std@@QBE_NXZ 1000804c msvcprt:MSVCP90.dll + 0002:00000050 __imp_?flags@ios_base@std@@QBEHXZ 10008050 msvcprt:MSVCP90.dll + 0002:00000054 __imp_?uncaught_exception@std@@YA_NXZ 10008054 msvcprt:MSVCP90.dll + 0002:00000058 __imp_?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ 10008058 msvcprt:MSVCP90.dll + 0002:0000005c __imp_?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ 1000805c msvcprt:MSVCP90.dll + 0002:00000060 __imp_?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ 10008060 msvcprt:MSVCP90.dll + 0002:00000064 __imp_?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ 10008064 msvcprt:MSVCP90.dll + 0002:00000068 __imp_?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z 10008068 msvcprt:MSVCP90.dll + 0002:0000006c __imp_?eof@?$char_traits@D@std@@SAHXZ 1000806c msvcprt:MSVCP90.dll + 0002:00000070 __imp_?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z 10008070 msvcprt:MSVCP90.dll + 0002:00000074 __imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z 10008074 msvcprt:MSVCP90.dll + 0002:00000078 __imp_?width@ios_base@std@@QAEHH@Z 10008078 msvcprt:MSVCP90.dll + 0002:0000007c __imp_?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z 1000807c msvcprt:MSVCP90.dll + 0002:00000080 __imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@G@Z 10008080 msvcprt:MSVCP90.dll + 0002:00000084 __imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@I@Z 10008084 msvcprt:MSVCP90.dll + 0002:00000088 __imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z 10008088 msvcprt:MSVCP90.dll + 0002:0000008c __imp_?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z 1000808c msvcprt:MSVCP90.dll + 0002:00000090 __imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A 10008090 msvcprt:MSVCP90.dll + 0002:00000094 __imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z 10008094 msvcprt:MSVCP90.dll + 0002:00000098 __imp_?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ 10008098 msvcprt:MSVCP90.dll + 0002:0000009c \177MSVCP90_NULL_THUNK_DATA 1000809c msvcprt:MSVCP90.dll + 0002:000000a0 __imp__free 100080a0 MSVCRT:MSVCR90.dll + 0002:000000a4 __imp___encoded_null 100080a4 MSVCRT:MSVCR90.dll + 0002:000000a8 __imp___decode_pointer 100080a8 MSVCRT:MSVCR90.dll + 0002:000000ac __imp___initterm 100080ac MSVCRT:MSVCR90.dll + 0002:000000b0 __imp___initterm_e 100080b0 MSVCRT:MSVCR90.dll + 0002:000000b4 __imp___amsg_exit 100080b4 MSVCRT:MSVCR90.dll + 0002:000000b8 __imp___adjust_fdiv 100080b8 MSVCRT:MSVCR90.dll + 0002:000000bc __imp____CppXcptFilter 100080bc MSVCRT:MSVCR90.dll + 0002:000000c0 __imp___crt_debugger_hook 100080c0 MSVCRT:MSVCR90.dll + 0002:000000c4 __imp____clean_type_info_names_internal 100080c4 MSVCRT:MSVCR90.dll + 0002:000000c8 __imp___unlock 100080c8 MSVCRT:MSVCR90.dll + 0002:000000cc __imp____dllonexit 100080cc MSVCRT:MSVCR90.dll + 0002:000000d0 __imp___lock 100080d0 MSVCRT:MSVCR90.dll + 0002:000000d4 __imp___onexit 100080d4 MSVCRT:MSVCR90.dll + 0002:000000d8 __imp___except_handler4_common 100080d8 MSVCRT:MSVCR90.dll + 0002:000000dc __imp___malloc_crt 100080dc MSVCRT:MSVCR90.dll + 0002:000000e0 __imp___encode_pointer 100080e0 MSVCRT:MSVCR90.dll + 0002:000000e4 __imp_??2@YAPAXI@Z 100080e4 MSVCRT:MSVCR90.dll + 0002:000000e8 __imp____CxxFrameHandler3 100080e8 MSVCRT:MSVCR90.dll + 0002:000000ec __imp__sprintf 100080ec MSVCRT:MSVCR90.dll + 0002:000000f0 __imp__floor 100080f0 MSVCRT:MSVCR90.dll + 0002:000000f4 __imp__memcpy 100080f4 MSVCRT:MSVCR90.dll + 0002:000000f8 __imp__feof 100080f8 MSVCRT:MSVCR90.dll + 0002:000000fc __imp__fread 100080fc MSVCRT:MSVCR90.dll + 0002:00000100 __imp__fopen 10008100 MSVCRT:MSVCR90.dll + 0002:00000104 __imp__fclose 10008104 MSVCRT:MSVCR90.dll + 0002:00000108 __imp__ceil 10008108 MSVCRT:MSVCR90.dll + 0002:0000010c __imp__fwrite 1000810c MSVCRT:MSVCR90.dll + 0002:00000110 __imp_??_V@YAXPAX@Z 10008110 MSVCRT:MSVCR90.dll + 0002:00000114 __imp__toupper 10008114 MSVCRT:MSVCR90.dll + 0002:00000118 \177MSVCR90_NULL_THUNK_DATA 10008118 MSVCRT:MSVCR90.dll + 0002:0000011c ___xc_a 1000811c MSVCRT:cinitexe.obj + 0002:00000120 ___xc_z 10008120 MSVCRT:cinitexe.obj + 0002:00000124 ___xi_a 10008124 MSVCRT:cinitexe.obj + 0002:00000130 ___xi_z 10008130 MSVCRT:cinitexe.obj + 0002:00001318 __real@404b000000000000 10009318 EasyBMP.obj + 0002:00001320 __real@4028000000000000 10009320 EasyBMP.obj + 0002:00001328 __real@4010000000000000 10009328 EasyBMP.obj + 0002:00001330 __real@0000000000000000 10009330 EasyBMP.obj + 0002:00001338 __real@4020000000000000 10009338 EasyBMP.obj + 0002:00001340 __real@4043af5ebd7af5ec 10009340 EasyBMP.obj + 0002:00001348 __real@3ff0000000000000 10009348 EasyBMP.obj + 0002:00001350 __real@4059000000000000 10009350 EasyBMP.obj + 0002:00001358 ??_C@_0P@GHFPNOJB@bad?5allocation?$AA@ 10009358 msvcprt:newaop_s.obj + 0002:00001368 __pRawDllMain 10009368 MSVCRT:crtdll.obj + 0002:00001368 __pDefaultRawDllMain 10009368 MSVCRT:crtdll.obj + 0002:00001378 __load_config_used 10009378 MSVCRT:loadcfg.obj + 0002:000013c0 ___safe_se_handler_table 100093c0 <linker-defined> + 0002:000013d0 ___rtc_iaa 100093d0 MSVCRT:_initsect_.obj + 0002:000013d4 ___rtc_izz 100093d4 MSVCRT:_initsect_.obj + 0002:000013d8 ___rtc_taa 100093d8 MSVCRT:_initsect_.obj + 0002:000013dc ___rtc_tzz 100093dc MSVCRT:_initsect_.obj + 0002:0000151c __IMPORT_DESCRIPTOR_MSVCP90 1000951c msvcprt:MSVCP90.dll + 0002:00001530 __IMPORT_DESCRIPTOR_MSVCR90 10009530 MSVCRT:MSVCR90.dll + 0002:00001544 __IMPORT_DESCRIPTOR_KERNEL32 10009544 kernel32:KERNEL32.dll + 0002:00001558 __NULL_IMPORT_DESCRIPTOR 10009558 msvcprt:MSVCP90.dll + 0003:00000004 ?EasyBMPwarnings@@3_NA 1000b004 EasyBMP.obj + 0003:00000010 ___security_cookie 1000b010 MSVCRT:gs_cookie.obj + 0003:00000014 ___security_cookie_complement 1000b014 MSVCRT:gs_cookie.obj + 0003:00000018 ___native_dllmain_reason 1000b018 MSVCRT:natstart.obj + 0003:0000001c ___native_vcclrit_reason 1000b01c MSVCRT:natstart.obj + 0003:0000034c __forceCRTManifestRTM 1000b34c MSVCRT:crtmanifestrtm.obj + 0003:00000350 ?__type_info_root_node@@3U__type_info_node@@A 1000b350 MSVCRT:tncleanup.obj + 0003:00000358 __adjust_fdiv 1000b358 <common> + 0003:0000035c ___native_startup_state 1000b35c <common> + 0003:00000360 ___native_startup_lock 1000b360 <common> + 0003:00000364 ___onexitend 1000b364 <common> + 0003:00000368 ___onexitbegin 1000b368 <common> + 0003:0000036c ___sse2_available 1000b36c <common> + 0003:00000370 ___dyn_tls_init_callback 1000b370 <common> + + entry point at 0001:00006362 + + Static symbols + + 0001:00005c95 __catch$??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z$0 10006c95 f i EasyBMP.obj + 0001:00005fd7 _pre_c_init 10006fd7 f MSVCRT:crtdll.obj + 0001:0000624c ___DllMainCRTStartup 1000724c f MSVCRT:crtdll.obj + 0001:0000638c _has_osfxsr_set 1000738c f MSVCRT:cpu_disp.obj + 0001:00006940 __unwindfunclet$?Rescale@@YA_NAAVBMP@@DH@Z$0 10007940 f EasyBMP.obj + 0001:00006948 __ehhandler$?Rescale@@YA_NAAVBMP@@DH@Z 10007948 f EasyBMP.obj + 0001:00006970 __unwindfunclet$??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z$2 10007970 f EasyBMP.obj + 0001:00006978 __ehhandler$??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z 10007978 f EasyBMP.obj + 0001:000069a0 __unwindfunclet$??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@XZ$0 100079a0 f EasyBMP.obj + 0001:000069a0 __unwindfunclet$??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@AAV12@@Z$0 100079a0 f EasyBMP.obj + 0001:000069a8 __ehhandler$??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@AAV12@@Z 100079a8 f EasyBMP.obj + 0001:000069a8 __ehhandler$??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@XZ 100079a8 f EasyBMP.obj + + Exports + + ordinal name + + 1 ??0BMFH@@QAE@XZ (public: __thiscall BMFH::BMFH(void)) + 2 ??0BMIH@@QAE@XZ (public: __thiscall BMIH::BMIH(void)) + 3 ??0BMP@@QAE@AAV0@@Z (public: __thiscall BMP::BMP(class BMP &)) + 4 ??0BMP@@QAE@XZ (public: __thiscall BMP::BMP(void)) + 5 ??1BMP@@QAE@XZ (public: __thiscall BMP::~BMP(void)) + 6 ??4BMFH@@QAEAAV0@ABV0@@Z (public: class BMFH & __thiscall BMFH::operator=(class BMFH const &)) + 7 ??4BMIH@@QAEAAV0@ABV0@@Z (public: class BMIH & __thiscall BMIH::operator=(class BMIH const &)) + 8 ??4BMP@@QAEAAV0@ABV0@@Z (public: class BMP & __thiscall BMP::operator=(class BMP const &)) + 9 ??4RGBApixel@@QAEAAU0@ABU0@@Z (public: struct RGBApixel & __thiscall RGBApixel::operator=(struct RGBApixel const &)) + 10 ??RBMP@@QAEPAURGBApixel@@HH@Z (public: struct RGBApixel * __thiscall BMP::operator()(int,int)) + 11 ?CreateStandardColorTable@BMP@@QAE_NXZ (public: bool __thiscall BMP::CreateStandardColorTable(void)) + 12 ?FindClosestColor@BMP@@AAEEAAURGBApixel@@@Z (private: unsigned char __thiscall BMP::FindClosestColor(struct RGBApixel &)) + 13 ?FlipDWORD@@YAII@Z (unsigned int __cdecl FlipDWORD(unsigned int)) + 14 ?FlipWORD@@YAGG@Z (unsigned short __cdecl FlipWORD(unsigned short)) + 15 ?GetColor@BMP@@QAE?AURGBApixel@@H@Z (public: struct RGBApixel __thiscall BMP::GetColor(int)) + 16 ?GetPixel@BMP@@QBE?AURGBApixel@@HH@Z (public: struct RGBApixel __thiscall BMP::GetPixel(int,int)const ) + 17 ?IntSquare@@YAHH@Z (int __cdecl IntSquare(int)) + 18 ?IsBigEndian@@YA_NXZ (bool __cdecl IsBigEndian(void)) + 19 ?Read1bitRow@BMP@@AAE_NPAEHH@Z (private: bool __thiscall BMP::Read1bitRow(unsigned char *,int,int)) + 20 ?Read24bitRow@BMP@@AAE_NPAEHH@Z (private: bool __thiscall BMP::Read24bitRow(unsigned char *,int,int)) + 21 ?Read32bitRow@BMP@@AAE_NPAEHH@Z (private: bool __thiscall BMP::Read32bitRow(unsigned char *,int,int)) + 22 ?Read4bitRow@BMP@@AAE_NPAEHH@Z (private: bool __thiscall BMP::Read4bitRow(unsigned char *,int,int)) + 23 ?Read8bitRow@BMP@@AAE_NPAEHH@Z (private: bool __thiscall BMP::Read8bitRow(unsigned char *,int,int)) + 24 ?ReadFromFile@BMP@@QAE_NPBD@Z (public: bool __thiscall BMP::ReadFromFile(char const *)) + 25 ?SetBitDepth@BMP@@QAE_NH@Z (public: bool __thiscall BMP::SetBitDepth(int)) + 26 ?SetColor@BMP@@QAE_NHURGBApixel@@@Z (public: bool __thiscall BMP::SetColor(int,struct RGBApixel)) + 27 ?SetDPI@BMP@@QAEXHH@Z (public: void __thiscall BMP::SetDPI(int,int)) + 28 ?SetPixel@BMP@@QAE_NHHURGBApixel@@@Z (public: bool __thiscall BMP::SetPixel(int,int,struct RGBApixel)) + 29 ?SetSize@BMP@@QAE_NHH@Z (public: bool __thiscall BMP::SetSize(int,int)) + 30 ?Square@@YANN@Z (double __cdecl Square(double)) + 31 ?SwitchEndianess@BMFH@@QAEXXZ (public: void __thiscall BMFH::SwitchEndianess(void)) + 32 ?SwitchEndianess@BMIH@@QAEXXZ (public: void __thiscall BMIH::SwitchEndianess(void)) + 33 ?TellBitDepth@BMP@@QAEHXZ (public: int __thiscall BMP::TellBitDepth(void)) + 34 ?TellHeight@BMP@@QAEHXZ (public: int __thiscall BMP::TellHeight(void)) + 35 ?TellHorizontalDPI@BMP@@QAEHXZ (public: int __thiscall BMP::TellHorizontalDPI(void)) + 36 ?TellNumberOfColors@BMP@@QAEHXZ (public: int __thiscall BMP::TellNumberOfColors(void)) + 37 ?TellVerticalDPI@BMP@@QAEHXZ (public: int __thiscall BMP::TellVerticalDPI(void)) + 38 ?TellWidth@BMP@@QAEHXZ (public: int __thiscall BMP::TellWidth(void)) + 39 ?Write1bitRow@BMP@@AAE_NPAEHH@Z (private: bool __thiscall BMP::Write1bitRow(unsigned char *,int,int)) + 40 ?Write24bitRow@BMP@@AAE_NPAEHH@Z (private: bool __thiscall BMP::Write24bitRow(unsigned char *,int,int)) + 41 ?Write32bitRow@BMP@@AAE_NPAEHH@Z (private: bool __thiscall BMP::Write32bitRow(unsigned char *,int,int)) + 42 ?Write4bitRow@BMP@@AAE_NPAEHH@Z (private: bool __thiscall BMP::Write4bitRow(unsigned char *,int,int)) + 43 ?Write8bitRow@BMP@@AAE_NPAEHH@Z (private: bool __thiscall BMP::Write8bitRow(unsigned char *,int,int)) + 44 ?WriteToFile@BMP@@QAE_NPBD@Z (public: bool __thiscall BMP::WriteToFile(char const *)) + 45 ?display@BMFH@@QAEXXZ (public: void __thiscall BMFH::display(void)) + 46 ?display@BMIH@@QAEXXZ (public: void __thiscall BMIH::display(void)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-03 09:00:23
|
Revision: 1521 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1521&view=rev Author: roman_yakovenko Date: 2009-01-03 09:00:19 +0000 (Sat, 03 Jan 2009) Log Message: ----------- few changes to allow easybmp example to work Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/ctypes_formatter.py pyplusplus_dev/pyplusplus/code_creators/fields_definition.py pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py Added Paths: ----------- pyplusplus_dev/pyplusplus/code_creators/typedef_as_pyvar.py Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2009-01-03 08:50:16 UTC (rev 1520) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2009-01-03 09:00:19 UTC (rev 1521) @@ -163,3 +163,4 @@ from function_definition import multi_method_definition_t from function_definition import del_definition_t from function_definition import mem_fun_definition_t +from typedef_as_pyvar import typedef_as_pyvar_t Modified: pyplusplus_dev/pyplusplus/code_creators/ctypes_formatter.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/ctypes_formatter.py 2009-01-03 08:50:16 UTC (rev 1520) +++ pyplusplus_dev/pyplusplus/code_creators/ctypes_formatter.py 2009-01-03 09:00:19 UTC (rev 1521) @@ -133,7 +133,12 @@ #~ raise NotImplementedError() def visit_declarated( self ): - return self.decl_formatter( self.user_type.declaration ) + #TODO: the follwoing code removes typedefs + if isinstance( self.user_type.declaration, declarations.typedef_t ): + base_visitor = type_converter_t( self.user_type.declaration.type, self.decl_formatter ) + return declarations.apply_visitor( base_visitor, base_visitor.user_type ) + else: + return self.decl_formatter( self.user_type.declaration ) def visit_restrict( self ): base_visitor = type_converter_t( self.user_type.base, self.decl_formatter ) Modified: pyplusplus_dev/pyplusplus/code_creators/fields_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/fields_definition.py 2009-01-03 08:50:16 UTC (rev 1520) +++ pyplusplus_dev/pyplusplus/code_creators/fields_definition.py 2009-01-03 09:00:19 UTC (rev 1521) @@ -5,6 +5,7 @@ import os import code_creator +import ctypes_formatter import declaration_based from pygccxml import declarations @@ -25,8 +26,17 @@ , decl_identifier=self.decl_identifier) ) if self.declaration.has_vtable: result.append( self.indent( '("_vtable_", ctypes.POINTER(ctypes.c_void_p)),' ) ) - result.append( self.indent( '("__hidden__", ctypes.c_char * %d),' - % ( self.declaration.byte_size - 4*int(self.declaration.has_vtable) ) ) ) + + vars = self.declaration.vars( allow_empty=True, recursive=False ) + if not vars: + result.append( self.indent( '("__empty__", ctypes.c_char * 4)' ) ) + else: + vars = vars.to_list() + vars.sort( key=lambda d: d.location.line ) + for v in vars: + result.append( self.indent( '("%(name)s", %(type)s),' + % dict( name=v.name + ,type=ctypes_formatter.as_ctype( v.type ) ) ) ) result.append( ']' ) return os.linesep.join( result ) Added: pyplusplus_dev/pyplusplus/code_creators/typedef_as_pyvar.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/typedef_as_pyvar.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_creators/typedef_as_pyvar.py 2009-01-03 09:00:19 UTC (rev 1521) @@ -0,0 +1,22 @@ +# Copyright 2004-2008 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 code_creator +import ctypes_formatter +import declaration_based + +class typedef_as_pyvar_t(code_creator.code_creator_t, declaration_based.declaration_based_t): + def __init__( self, ns ): + code_creator.code_creator_t.__init__(self) + declaration_based.declaration_based_t.__init__( self, ns ) + + def _create_impl(self): + return "%(complete_py_name)s = %(type)s" \ + % dict( complete_py_name=self.complete_py_name + , type=ctypes_formatter.as_ctype( self.declaration.type ) ) + + def _get_system_headers_impl( self ): + return [] Modified: pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py =================================================================== --- pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2009-01-03 08:50:16 UTC (rev 1520) +++ pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2009-01-03 09:00:19 UTC (rev 1521) @@ -36,7 +36,8 @@ self.__class_ccs = code_creators.bookmark_t() #bookmark for class deinitions self.__class_defs_ccs = code_creators.bookmark_t() - + #bookmark for typedef definitions + self.__typedefs_ccs = code_creators.bookmark_t() #~ prepared_decls = self.__prepare_decls( global_ns, doc_extractor ) #~ self.__decls = sort_algorithms.sort( prepared_decls ) self.curr_decl = global_ns @@ -138,11 +139,14 @@ ns_classes = self.global_ns.classes( f, recursive=True, allow_empty=True) ns_classes = sort_algorithms.sort_classes( ns_classes ) for class_ in ns_classes: - if self.__contains_exported( class_ ): - self.__add_class_introductions( self.__class_ccs, class_ ) + self.__add_class_introductions( self.__class_ccs, class_ ) ccc.adopt_creator( self.__class_defs_ccs ) + ccc.adopt_creator( code_creators.separator_t() ) + + ccc.adopt_creator( self.__typedefs_ccs ) + declarations.apply_visitor( self, self.curr_decl ) self.__dependencies_manager.inform_user() @@ -248,6 +252,7 @@ def visit_typedef(self): self.__dependencies_manager.add_exported( self.curr_decl ) + self.__typedefs_ccs.adopt_creator( code_creators.typedef_as_pyvar_t( self.curr_decl ) ) def visit_variable(self): self.__dependencies_manager.add_exported( self.curr_decl ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-03 08:50:20
|
Revision: 1520 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1520&view=rev Author: roman_yakovenko Date: 2009-01-03 08:50:16 +0000 (Sat, 03 Jan 2009) Log Message: ----------- making easybmp example to work Modified Paths: -------------- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/generate_code.py pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.cpp pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_DataStructures.h pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sconscript Modified: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/generate_code.py =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/generate_code.py 2009-01-03 07:28:24 UTC (rev 1519) +++ pyplusplus_dev/examples/pyeasybmp_dev/ctypes/generate_code.py 2009-01-03 08:50:16 UTC (rev 1520) @@ -4,18 +4,19 @@ from environment import settings +from pygccxml import utils from pygccxml import parser from pyplusplus.module_builder import ctypes_module_builder_t symbols_file = os.path.join( settings.easybmp_path, 'binaries', 'easybmp.map' ) shared_library = os.path.join( settings.easybmp_path, 'binaries', 'easybmp.dll' ) - gccxml_cfg = parser.gccxml_configuration_t( working_directory=settings.working_dir - , compiler='msvc71' + , compiler=utils.native_compiler.get_gccxml_compiler() , gccxml_path=settings.gccxml_path ) mb = ctypes_module_builder_t( ['EasyBMP.h'], symbols_file, gccxml_cfg ) +#~ mb.print_declarations() mb.build_code_creator( shared_library ) mb.write_module( 'easybmp.py' ) Modified: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.cpp =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.cpp 2009-01-03 07:28:24 UTC (rev 1519) +++ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.cpp 2009-01-03 08:50:16 UTC (rev 1520) @@ -1,1286 +1,1287 @@ -/************************************************* -* * -* EasyBMP Cross-Platform Windows Bitmap Library * -* * -* Author: Paul Macklin * -* email: mac...@us... * -* support: http://easybmp.sourceforge.net * -* * -* file: EasyBMP.cpp * -* date added: 03-31-2006 * -* date modified: 12-01-2006 * -* version: 1.06 * -* * -* License: BSD (revised/modified) * -* Copyright: 2005-6 by the EasyBMP Project * -* * -* description: Actual source file * -* * +/************************************************* +* * +* EasyBMP Cross-Platform Windows Bitmap Library * +* * +* Author: Paul Macklin * +* email: mac...@us... * +* support: http://easybmp.sourceforge.net * +* * +* file: EasyBMP.cpp * +* date added: 03-31-2006 * +* date modified: 12-01-2006 * +* version: 1.06 * +* * +* License: BSD (revised/modified) * +* Copyright: 2005-6 by the EasyBMP Project * +* * +* description: Actual source file * +* * *************************************************/ #include "EasyBMP.h" - -/* These functions are defined in EasyBMP.h */ - -bool EasyBMPwarnings = true; - -void SetEasyBMPwarningsOff( void ) -{ EasyBMPwarnings = false; } -void SetEasyBMPwarningsOn( void ) -{ EasyBMPwarnings = true; } -bool GetEasyBMPwarningState( void ) -{ return EasyBMPwarnings; } - + +/* These functions are defined in EasyBMP.h */ + +bool EasyBMPwarnings = true; + +void SetEasyBMPwarningsOff( void ) +{ EasyBMPwarnings = false; } +void SetEasyBMPwarningsOn( void ) +{ EasyBMPwarnings = true; } +bool GetEasyBMPwarningState( void ) +{ return EasyBMPwarnings; } + /* These functions are defined in EasyBMP_DataStructures.h */ -int IntPow( int base, int exponent ) -{ - int i; - int output = 1; - for( i=0 ; i < exponent ; i++ ) - { output *= base; } - return output; +int IntPow( int base, int exponent ) +{ + int i; + int output = 1; + for( i=0 ; i < exponent ; i++ ) + { output *= base; } + return output; } -BMFH::BMFH() -{ - bfType = 19778; - bfReserved1 = 0; - bfReserved2 = 0; +BMFH::BMFH() +{ + bfType = 19778; + bfReserved1 = 0; + bfReserved2 = 0; } -void BMFH::SwitchEndianess( void ) -{ - bfType = FlipWORD( bfType ); - bfSize = FlipDWORD( bfSize ); - bfReserved1 = FlipWORD( bfReserved1 ); - bfReserved2 = FlipWORD( bfReserved2 ); - bfOffBits = FlipDWORD( bfOffBits ); - return; -} +void BMFH::SwitchEndianess( void ) +{ + bfType = FlipWORD( bfType ); + bfSize = FlipDWORD( bfSize ); + bfReserved1 = FlipWORD( bfReserved1 ); + bfReserved2 = FlipWORD( bfReserved2 ); + bfOffBits = FlipDWORD( bfOffBits ); + return; +} -BMIH::BMIH() +BMIH::BMIH() { - biPlanes = 1; - biCompression = 0; - biXPelsPerMeter = DefaultXPelsPerMeter; - biYPelsPerMeter = DefaultYPelsPerMeter; - biClrUsed = 0; - biClrImportant = 0; -} - -void BMIH::SwitchEndianess( void ) -{ - biSize = FlipDWORD( biSize ); - biWidth = FlipDWORD( biWidth ); - biHeight = FlipDWORD( biHeight ); - biPlanes = FlipWORD( biPlanes ); - biBitCount = FlipWORD( biBitCount ); - biCompression = FlipDWORD( biCompression ); - biSizeImage = FlipDWORD( biSizeImage ); - biXPelsPerMeter = FlipDWORD( biXPelsPerMeter ); - biYPelsPerMeter = FlipDWORD( biYPelsPerMeter ); - biClrUsed = FlipDWORD( biClrUsed ); - biClrImportant = FlipDWORD( biClrImportant ); - return; -} - -void BMIH::display( void ) -{ - using namespace std; - cout << "biSize: " << (int) biSize << endl - << "biWidth: " << (int) biWidth << endl - << "biHeight: " << (int) biHeight << endl - << "biPlanes: " << (int) biPlanes << endl - << "biBitCount: " << (int) biBitCount << endl - << "biCompression: " << (int) biCompression << endl - << "biSizeImage: " << (int) biSizeImage << endl - << "biXPelsPerMeter: " << (int) biXPelsPerMeter << endl - << "biYPelsPerMeter: " << (int) biYPelsPerMeter << endl - << "biClrUsed: " << (int) biClrUsed << endl - << "biClrImportant: " << (int) biClrImportant << endl << endl; -} - -void BMFH::display( void ) -{ - using namespace std; - cout << "bfType: " << (int) bfType << endl - << "bfSize: " << (int) bfSize << endl - << "bfReserved1: " << (int) bfReserved1 << endl - << "bfReserved2: " << (int) bfReserved2 << endl - << "bfOffBits: " << (int) bfOffBits << endl << endl; -} + biPlanes = 1; + biCompression = 0; + biXPelsPerMeter = DefaultXPelsPerMeter; + biYPelsPerMeter = DefaultYPelsPerMeter; + biClrUsed = 0; + biClrImportant = 0; +} -/* These functions are defined in EasyBMP_BMP.h */ - -RGBApixel BMP::GetPixel( int i, int j ) const -{ - using namespace std; - bool Warn = false; +void BMIH::SwitchEndianess( void ) +{ + biSize = FlipDWORD( biSize ); + biWidth = FlipDWORD( biWidth ); + biHeight = FlipDWORD( biHeight ); + biPlanes = FlipWORD( biPlanes ); + biBitCount = FlipWORD( biBitCount ); + biCompression = FlipDWORD( biCompression ); + biSizeImage = FlipDWORD( biSizeImage ); + biXPelsPerMeter = FlipDWORD( biXPelsPerMeter ); + biYPelsPerMeter = FlipDWORD( biYPelsPerMeter ); + biClrUsed = FlipDWORD( biClrUsed ); + biClrImportant = FlipDWORD( biClrImportant ); + return; +} + +void BMIH::display( void ) +{ + using namespace std; + cout << "biSize: " << (int) biSize << endl + << "biWidth: " << (int) biWidth << endl + << "biHeight: " << (int) biHeight << endl + << "biPlanes: " << (int) biPlanes << endl + << "biBitCount: " << (int) biBitCount << endl + << "biCompression: " << (int) biCompression << endl + << "biSizeImage: " << (int) biSizeImage << endl + << "biXPelsPerMeter: " << (int) biXPelsPerMeter << endl + << "biYPelsPerMeter: " << (int) biYPelsPerMeter << endl + << "biClrUsed: " << (int) biClrUsed << endl + << "biClrImportant: " << (int) biClrImportant << endl << endl; +} + +void BMFH::display( void ) +{ + using namespace std; + cout << "bfType: " << (int) bfType << endl + << "bfSize: " << (int) bfSize << endl + << "bfReserved1: " << (int) bfReserved1 << endl + << "bfReserved2: " << (int) bfReserved2 << endl + << "bfOffBits: " << (int) bfOffBits << endl << endl; +} + +/* These functions are defined in EasyBMP_BMP.h */ + +RGBApixel BMP::GetPixel( int i, int j ) const +{ + using namespace std; + std::cout << "\nGetPixel(" << i << "," << j << ")\n"; + bool Warn = false; if( i >= Width ) - { i = Width-1; Warn = true; } + { i = Width-1; Warn = true; } if( i < 0 ) - { i = 0; Warn = true; } + { i = 0; Warn = true; } if( j >= Height ) - { j = Height-1; Warn = true; } + { j = Height-1; Warn = true; } if( j < 0 ) - { j = 0; Warn = true; } - if( Warn && EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Attempted to access non-existent pixel;" << endl - << " Truncating request to fit in the range [0," - << Width-1 << "] x [0," << Height-1 << "]." << endl; - } - return Pixels[i][j]; -} - -bool BMP::SetPixel( int i, int j, RGBApixel NewPixel ) -{ - Pixels[i][j] = NewPixel; - return true; -} + { j = 0; Warn = true; } + if( Warn && EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to access non-existent pixel;" << endl + << " Truncating request to fit in the range [0," + << Width-1 << "] x [0," << Height-1 << "]." << endl; + } + return Pixels[i][j]; +} +bool BMP::SetPixel( int i, int j, RGBApixel NewPixel ) +{ + Pixels[i][j] = NewPixel; + return true; +} -bool BMP::SetColor( int ColorNumber , RGBApixel NewColor ) -{ - using namespace std; - if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Attempted to change color table for a BMP object" << endl - << " that lacks a color table. Ignoring request." << endl; - } - return false; - } - if( !Colors ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Attempted to set a color, but the color table" << endl - << " is not defined. Ignoring request." << endl; - } - return false; - } - if( ColorNumber >= TellNumberOfColors() ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Requested color number " - << ColorNumber << " is outside the allowed" << endl - << " range [0," << TellNumberOfColors()-1 - << "]. Ignoring request to set this color." << endl; - } - return false; - } - Colors[ColorNumber] = NewColor; - return true; -} - -// RGBApixel BMP::GetColor( int ColorNumber ) const -RGBApixel BMP::GetColor( int ColorNumber ) -{ - RGBApixel Output; - Output.Red = 255; - Output.Green = 255; - Output.Blue = 255; - Output.Alpha = 0; - - using namespace std; - if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Attempted to access color table for a BMP object" << endl - << " that lacks a color table. Ignoring request." << endl; - } - return Output; - } - if( !Colors ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Requested a color, but the color table" << endl - << " is not defined. Ignoring request." << endl; - } - return Output; - } - if( ColorNumber >= TellNumberOfColors() ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Requested color number " - << ColorNumber << " is outside the allowed" << endl - << " range [0," << TellNumberOfColors()-1 - << "]. Ignoring request to get this color." << endl; - } - return Output; - } - Output = Colors[ColorNumber]; - return Output; -} - -BMP::BMP() -{ - Width = 1; - Height = 1; - BitDepth = 24; - Pixels = new RGBApixel* [Width]; - Pixels[0] = new RGBApixel [Height]; + +bool BMP::SetColor( int ColorNumber , RGBApixel NewColor ) +{ + using namespace std; + if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to change color table for a BMP object" << endl + << " that lacks a color table. Ignoring request." << endl; + } + return false; + } + if( !Colors ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to set a color, but the color table" << endl + << " is not defined. Ignoring request." << endl; + } + return false; + } + if( ColorNumber >= TellNumberOfColors() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Requested color number " + << ColorNumber << " is outside the allowed" << endl + << " range [0," << TellNumberOfColors()-1 + << "]. Ignoring request to set this color." << endl; + } + return false; + } + Colors[ColorNumber] = NewColor; + return true; +} + +// RGBApixel BMP::GetColor( int ColorNumber ) const +RGBApixel BMP::GetColor( int ColorNumber ) +{ + RGBApixel Output; + Output.Red = 255; + Output.Green = 255; + Output.Blue = 255; + Output.Alpha = 0; + + using namespace std; + if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to access color table for a BMP object" << endl + << " that lacks a color table. Ignoring request." << endl; + } + return Output; + } + if( !Colors ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Requested a color, but the color table" << endl + << " is not defined. Ignoring request." << endl; + } + return Output; + } + if( ColorNumber >= TellNumberOfColors() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Requested color number " + << ColorNumber << " is outside the allowed" << endl + << " range [0," << TellNumberOfColors()-1 + << "]. Ignoring request to get this color." << endl; + } + return Output; + } + Output = Colors[ColorNumber]; + return Output; +} + +BMP::BMP() +{ + Width = 1; + Height = 1; + BitDepth = 24; + Pixels = new RGBApixel* [Width]; + Pixels[0] = new RGBApixel [Height]; Colors = NULL; XPelsPerMeter = 0; - YPelsPerMeter = 0; - - MetaData1 = NULL; - SizeOfMetaData1 = 0; - MetaData2 = NULL; - SizeOfMetaData2 = 0; -} - -// BMP::BMP( const BMP& Input ) -BMP::BMP( BMP& Input ) -{ - // first, make the image empty. - - Width = 1; - Height = 1; - BitDepth = 24; - Pixels = new RGBApixel* [Width]; - Pixels[0] = new RGBApixel [Height]; - Colors = NULL; + YPelsPerMeter = 0; + + MetaData1 = NULL; + SizeOfMetaData1 = 0; + MetaData2 = NULL; + SizeOfMetaData2 = 0; +} + +// BMP::BMP( const BMP& Input ) +BMP::BMP( BMP& Input ) +{ + // first, make the image empty. + + Width = 1; + Height = 1; + BitDepth = 24; + Pixels = new RGBApixel* [Width]; + Pixels[0] = new RGBApixel [Height]; + Colors = NULL; XPelsPerMeter = 0; - YPelsPerMeter = 0; - - MetaData1 = NULL; - SizeOfMetaData1 = 0; - MetaData2 = NULL; - SizeOfMetaData2 = 0; - - // now, set the correct bit depth - - SetBitDepth( Input.TellBitDepth() ); - - // set the correct pixel size - - SetSize( Input.TellWidth() , Input.TellHeight() ); - - // set the DPI information from Input - - SetDPI( Input.TellHorizontalDPI() , Input.TellVerticalDPI() ); - - // if there is a color table, get all the colors - - if( BitDepth == 1 || BitDepth == 4 || - BitDepth == 8 ) - { - for( int k=0 ; k < TellNumberOfColors() ; k++ ) - { - SetColor( k, Input.GetColor( k )); - } - } - - // get all the pixels - - for( int j=0; j < Height ; j++ ) - { - for( int i=0; i < Width ; i++ ) - { - Pixels[i][j] = *Input(i,j); -// Pixels[i][j] = Input.GetPixel(i,j); // *Input(i,j); - } - } -} - -BMP::~BMP() -{ - int i; - for(i=0;i<Width;i++) - { delete [] Pixels[i]; } - delete [] Pixels; - if( Colors ) - { delete [] Colors; } - - if( MetaData1 ) - { delete [] MetaData1; } - if( MetaData2 ) - { delete [] MetaData2; } -} - -RGBApixel* BMP::operator()(int i, int j) -{ - using namespace std; - bool Warn = false; + YPelsPerMeter = 0; + + MetaData1 = NULL; + SizeOfMetaData1 = 0; + MetaData2 = NULL; + SizeOfMetaData2 = 0; + + // now, set the correct bit depth + + SetBitDepth( Input.TellBitDepth() ); + + // set the correct pixel size + + SetSize( Input.TellWidth() , Input.TellHeight() ); + + // set the DPI information from Input + + SetDPI( Input.TellHorizontalDPI() , Input.TellVerticalDPI() ); + + // if there is a color table, get all the colors + + if( BitDepth == 1 || BitDepth == 4 || + BitDepth == 8 ) + { + for( int k=0 ; k < TellNumberOfColors() ; k++ ) + { + SetColor( k, Input.GetColor( k )); + } + } + + // get all the pixels + + for( int j=0; j < Height ; j++ ) + { + for( int i=0; i < Width ; i++ ) + { + Pixels[i][j] = *Input(i,j); +// Pixels[i][j] = Input.GetPixel(i,j); // *Input(i,j); + } + } +} + +BMP::~BMP() +{ + int i; + for(i=0;i<Width;i++) + { delete [] Pixels[i]; } + delete [] Pixels; + if( Colors ) + { delete [] Colors; } + + if( MetaData1 ) + { delete [] MetaData1; } + if( MetaData2 ) + { delete [] MetaData2; } +} + +RGBApixel* BMP::operator()(int i, int j) +{ + using namespace std; + bool Warn = false; if( i >= Width ) - { i = Width-1; Warn = true; } + { i = Width-1; Warn = true; } if( i < 0 ) - { i = 0; Warn = true; } + { i = 0; Warn = true; } if( j >= Height ) - { j = Height-1; Warn = true; } + { j = Height-1; Warn = true; } if( j < 0 ) - { j = 0; Warn = true; } - if( Warn && EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Attempted to access non-existent pixel;" << endl - << " Truncating request to fit in the range [0," - << Width-1 << "] x [0," << Height-1 << "]." << endl; - } - return &(Pixels[i][j]); -} - -// int BMP::TellBitDepth( void ) const -int BMP::TellBitDepth( void ) -{ return BitDepth; } - -// int BMP::TellHeight( void ) const -int BMP::TellHeight( void ) -{ return Height; } - -// int BMP::TellWidth( void ) const -int BMP::TellWidth( void ) -{ return Width; } - -// int BMP::TellNumberOfColors( void ) const -int BMP::TellNumberOfColors( void ) -{ - int output = IntPow( 2, BitDepth ); - if( BitDepth == 32 ) - { output = IntPow( 2, 24 ); } - return output; -} - -bool BMP::SetBitDepth( int NewDepth ) -{ - using namespace std; - if( NewDepth != 1 && NewDepth != 4 && - NewDepth != 8 && NewDepth != 16 && - NewDepth != 24 && NewDepth != 32 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: User attempted to set unsupported bit depth " - << NewDepth << "." << endl - << " Bit depth remains unchanged at " - << BitDepth << "." << endl; - } - return false; - } - - BitDepth = NewDepth; - if( Colors ) - { delete [] Colors; } - int NumberOfColors = IntPow( 2, BitDepth ); - if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) - { Colors = new RGBApixel [NumberOfColors]; } - else - { Colors = NULL; } - if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) - { CreateStandardColorTable(); } - - return true; -} - -bool BMP::SetSize(int NewWidth , int NewHeight ) -{ - using namespace std; - if( NewWidth <= 0 || NewHeight <= 0 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: User attempted to set a non-positive width or height." << endl - << " Size remains unchanged at " - << Width << " x " << Height << "." << endl; - } - return false; - } - - int i,j; - - for(i=0;i<Width;i++) - { delete [] Pixels[i]; } - delete [] Pixels; - - Width = NewWidth; - Height = NewHeight; - Pixels = new RGBApixel* [ Width ]; - - for(i=0; i<Width; i++) - { Pixels[i] = new RGBApixel [ Height ]; } - - for( i=0 ; i < Width ; i++) - { - for( j=0 ; j < Height ; j++ ) - { - Pixels[i][j].Red = 255; - Pixels[i][j].Green = 255; - Pixels[i][j].Blue = 255; - Pixels[i][j].Alpha = 0; - } - } - - return true; -} - -bool BMP::WriteToFile( const char* FileName ) -{ - using namespace std; - if( !EasyBMPcheckDataSize() ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: Data types are wrong size!" << endl - << " You may need to mess with EasyBMP_DataTypes.h" << endl - << " to fix these errors, and then recompile." << endl - << " All 32-bit and 64-bit machines should be" << endl - << " supported, however." << endl << endl; - } - return false; - } - - FILE* fp = fopen( FileName, "wb" ); - if( fp == NULL ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: Cannot open file " - << FileName << " for output." << endl; - } - fclose( fp ); - return false; - } - - // some preliminaries - - double dBytesPerPixel = ( (double) BitDepth ) / 8.0; - double dBytesPerRow = dBytesPerPixel * (Width+0.0); - dBytesPerRow = ceil(dBytesPerRow); - - int BytePaddingPerRow = 4 - ( (int) (dBytesPerRow) )% 4; - if( BytePaddingPerRow == 4 ) - { BytePaddingPerRow = 0; } - - double dActualBytesPerRow = dBytesPerRow + BytePaddingPerRow; - - double dTotalPixelBytes = Height * dActualBytesPerRow; - - double dPaletteSize = 0; - if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) - { dPaletteSize = IntPow(2,BitDepth)*4.0; } - - // leave some room for 16-bit masks - if( BitDepth == 16 ) - { dPaletteSize = 3*4; } - - double dTotalFileSize = 14 + 40 + dPaletteSize + dTotalPixelBytes; - - // write the file header - - BMFH bmfh; - bmfh.bfSize = (ebmpDWORD) dTotalFileSize; - bmfh.bfReserved1 = 0; - bmfh.bfReserved2 = 0; - bmfh.bfOffBits = (ebmpDWORD) (14+40+dPaletteSize); - - if( IsBigEndian() ) - { bmfh.SwitchEndianess(); } - - fwrite( (char*) &(bmfh.bfType) , sizeof(ebmpWORD) , 1 , fp ); - fwrite( (char*) &(bmfh.bfSize) , sizeof(ebmpDWORD) , 1 , fp ); - fwrite( (char*) &(bmfh.bfReserved1) , sizeof(ebmpWORD) , 1 , fp ); - fwrite( (char*) &(bmfh.bfReserved2) , sizeof(ebmpWORD) , 1 , fp ); - fwrite( (char*) &(bmfh.bfOffBits) , sizeof(ebmpDWORD) , 1 , fp ); - - // write the info header - - BMIH bmih; - bmih.biSize = 40; - bmih.biWidth = Width; - bmih.biHeight = Height; - bmih.biPlanes = 1; - bmih.biBitCount = BitDepth; - bmih.biCompression = 0; - bmih.biSizeImage = (ebmpDWORD) dTotalPixelBytes; - if( XPelsPerMeter ) - { bmih.biXPelsPerMeter = XPelsPerMeter; } - else - { bmih.biXPelsPerMeter = DefaultXPelsPerMeter; } - if( YPelsPerMeter ) - { bmih.biYPelsPerMeter = YPelsPerMeter; } - else - { bmih.biYPelsPerMeter = DefaultYPelsPerMeter; } - - bmih.biClrUsed = 0; - bmih.biClrImportant = 0; - - // indicates that we'll be using bit fields for 16-bit files - if( BitDepth == 16 ) - { bmih.biCompression = 3; } - - if( IsBigEndian() ) - { bmih.SwitchEndianess(); } - - fwrite( (char*) &(bmih.biSize) , sizeof(ebmpDWORD) , 1 , fp ); - fwrite( (char*) &(bmih.biWidth) , sizeof(ebmpDWORD) , 1 , fp ); - fwrite( (char*) &(bmih.biHeight) , sizeof(ebmpDWORD) , 1 , fp ); - fwrite( (char*) &(bmih.biPlanes) , sizeof(ebmpWORD) , 1 , fp ); - fwrite( (char*) &(bmih.biBitCount) , sizeof(ebmpWORD) , 1 , fp ); - fwrite( (char*) &(bmih.biCompression) , sizeof(ebmpDWORD) , 1 , fp ); - fwrite( (char*) &(bmih.biSizeImage) , sizeof(ebmpDWORD) , 1 , fp ); - fwrite( (char*) &(bmih.biXPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp ); - fwrite( (char*) &(bmih.biYPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp ); - fwrite( (char*) &(bmih.biClrUsed) , sizeof(ebmpDWORD) , 1 , fp); - fwrite( (char*) &(bmih.biClrImportant) , sizeof(ebmpDWORD) , 1 , fp); - - // write the palette - if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) - { - int NumberOfColors = IntPow(2,BitDepth); - - // if there is no palette, create one - if( !Colors ) - { - if( !Colors ) - { Colors = new RGBApixel [NumberOfColors]; } - CreateStandardColorTable(); - } - - int n; - for( n=0 ; n < NumberOfColors ; n++ ) - { fwrite( (char*) &(Colors[n]) , 4 , 1 , fp ); } - } - - // write the pixels - int i,j; - if( BitDepth != 16 ) - { - ebmpBYTE* Buffer; - int BufferSize = (int) ( (Width*BitDepth)/8.0 ); - while( 8*BufferSize < Width*BitDepth ) - { BufferSize++; } - while( BufferSize % 4 ) - { BufferSize++; } - - Buffer = new ebmpBYTE [BufferSize]; - for( j=0 ; j < BufferSize; j++ ) - { Buffer[j] = 0; } - - j=Height-1; - - while( j > -1 ) - { - bool Success = false; - if( BitDepth == 32 ) - { Success = Write32bitRow( Buffer, BufferSize, j ); } - if( BitDepth == 24 ) - { Success = Write24bitRow( Buffer, BufferSize, j ); } - if( BitDepth == 8 ) - { Success = Write8bitRow( Buffer, BufferSize, j ); } - if( BitDepth == 4 ) - { Success = Write4bitRow( Buffer, BufferSize, j ); } - if( BitDepth == 1 ) - { Success = Write1bitRow( Buffer, BufferSize, j ); } - if( Success ) - { - int BytesWritten = (int) fwrite( (char*) Buffer, 1, BufferSize, fp ); - if( BytesWritten != BufferSize ) - { Success = false; } - } - if( !Success ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: Could not write proper amount of data." << endl; - } - j = -1; - } - j--; - } - - delete [] Buffer; - } - - if( BitDepth == 16 ) - { - // write the bit masks - - ebmpWORD BlueMask = 31; // bits 12-16 - ebmpWORD GreenMask = 2016; // bits 6-11 - ebmpWORD RedMask = 63488; // bits 1-5 - ebmpWORD ZeroWORD; - - if( IsBigEndian() ) - { RedMask = FlipWORD( RedMask ); } - fwrite( (char*) &RedMask , 2 , 1 , fp ); - fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); - - if( IsBigEndian() ) - { GreenMask = FlipWORD( GreenMask ); } - fwrite( (char*) &GreenMask , 2 , 1 , fp ); - fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); - - if( IsBigEndian() ) - { BlueMask = FlipWORD( BlueMask ); } - fwrite( (char*) &BlueMask , 2 , 1 , fp ); - fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); - - int DataBytes = Width*2; - int PaddingBytes = ( 4 - DataBytes % 4 ) % 4; - - // write the actual pixels - - for( j=Height-1 ; j >= 0 ; j-- ) - { - // write all row pixel data - i=0; - int WriteNumber = 0; - while( WriteNumber < DataBytes ) - { - ebmpWORD TempWORD; - - ebmpWORD RedWORD = (ebmpWORD) ((Pixels[i][j]).Red / 8); - ebmpWORD GreenWORD = (ebmpWORD) ((Pixels[i][j]).Green / 4); - ebmpWORD BlueWORD = (ebmpWORD) ((Pixels[i][j]).Blue / 8); - - TempWORD = (RedWORD<<11) + (GreenWORD<<5) + BlueWORD; - if( IsBigEndian() ) - { TempWORD = FlipWORD( TempWORD ); } - - fwrite( (char*) &TempWORD , 2, 1, fp); - WriteNumber += 2; + { j = 0; Warn = true; } + if( Warn && EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to access non-existent pixel;" << endl + << " Truncating request to fit in the range [0," + << Width-1 << "] x [0," << Height-1 << "]." << endl; + } + return &(Pixels[i][j]); +} + +// int BMP::TellBitDepth( void ) const +int BMP::TellBitDepth( void ) +{ return BitDepth; } + +// int BMP::TellHeight( void ) const +int BMP::TellHeight( void ) +{ return Height; } + +// int BMP::TellWidth( void ) const +int BMP::TellWidth( void ) +{ return Width; } + +// int BMP::TellNumberOfColors( void ) const +int BMP::TellNumberOfColors( void ) +{ + int output = IntPow( 2, BitDepth ); + if( BitDepth == 32 ) + { output = IntPow( 2, 24 ); } + return output; +} + +bool BMP::SetBitDepth( int NewDepth ) +{ + using namespace std; + if( NewDepth != 1 && NewDepth != 4 && + NewDepth != 8 && NewDepth != 16 && + NewDepth != 24 && NewDepth != 32 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: User attempted to set unsupported bit depth " + << NewDepth << "." << endl + << " Bit depth remains unchanged at " + << BitDepth << "." << endl; + } + return false; + } + + BitDepth = NewDepth; + if( Colors ) + { delete [] Colors; } + int NumberOfColors = IntPow( 2, BitDepth ); + if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) + { Colors = new RGBApixel [NumberOfColors]; } + else + { Colors = NULL; } + if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) + { CreateStandardColorTable(); } + + return true; +} + +bool BMP::SetSize(int NewWidth , int NewHeight ) +{ + using namespace std; + if( NewWidth <= 0 || NewHeight <= 0 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: User attempted to set a non-positive width or height." << endl + << " Size remains unchanged at " + << Width << " x " << Height << "." << endl; + } + return false; + } + + int i,j; + + for(i=0;i<Width;i++) + { delete [] Pixels[i]; } + delete [] Pixels; + + Width = NewWidth; + Height = NewHeight; + Pixels = new RGBApixel* [ Width ]; + + for(i=0; i<Width; i++) + { Pixels[i] = new RGBApixel [ Height ]; } + + for( i=0 ; i < Width ; i++) + { + for( j=0 ; j < Height ; j++ ) + { + Pixels[i][j].Red = 255; + Pixels[i][j].Green = 255; + Pixels[i][j].Blue = 255; + Pixels[i][j].Alpha = 0; + } + } + + return true; +} + +bool BMP::WriteToFile( const char* FileName ) +{ + using namespace std; + if( !EasyBMPcheckDataSize() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Data types are wrong size!" << endl + << " You may need to mess with EasyBMP_DataTypes.h" << endl + << " to fix these errors, and then recompile." << endl + << " All 32-bit and 64-bit machines should be" << endl + << " supported, however." << endl << endl; + } + return false; + } + + FILE* fp = fopen( FileName, "wb" ); + if( fp == NULL ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Cannot open file " + << FileName << " for output." << endl; + } + fclose( fp ); + return false; + } + + // some preliminaries + + double dBytesPerPixel = ( (double) BitDepth ) / 8.0; + double dBytesPerRow = dBytesPerPixel * (Width+0.0); + dBytesPerRow = ceil(dBytesPerRow); + + int BytePaddingPerRow = 4 - ( (int) (dBytesPerRow) )% 4; + if( BytePaddingPerRow == 4 ) + { BytePaddingPerRow = 0; } + + double dActualBytesPerRow = dBytesPerRow + BytePaddingPerRow; + + double dTotalPixelBytes = Height * dActualBytesPerRow; + + double dPaletteSize = 0; + if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) + { dPaletteSize = IntPow(2,BitDepth)*4.0; } + + // leave some room for 16-bit masks + if( BitDepth == 16 ) + { dPaletteSize = 3*4; } + + double dTotalFileSize = 14 + 40 + dPaletteSize + dTotalPixelBytes; + + // write the file header + + BMFH bmfh; + bmfh.bfSize = (ebmpDWORD) dTotalFileSize; + bmfh.bfReserved1 = 0; + bmfh.bfReserved2 = 0; + bmfh.bfOffBits = (ebmpDWORD) (14+40+dPaletteSize); + + if( IsBigEndian() ) + { bmfh.SwitchEndianess(); } + + fwrite( (char*) &(bmfh.bfType) , sizeof(ebmpWORD) , 1 , fp ); + fwrite( (char*) &(bmfh.bfSize) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmfh.bfReserved1) , sizeof(ebmpWORD) , 1 , fp ); + fwrite( (char*) &(bmfh.bfReserved2) , sizeof(ebmpWORD) , 1 , fp ); + fwrite( (char*) &(bmfh.bfOffBits) , sizeof(ebmpDWORD) , 1 , fp ); + + // write the info header + + BMIH bmih; + bmih.biSize = 40; + bmih.biWidth = Width; + bmih.biHeight = Height; + bmih.biPlanes = 1; + bmih.biBitCount = BitDepth; + bmih.biCompression = 0; + bmih.biSizeImage = (ebmpDWORD) dTotalPixelBytes; + if( XPelsPerMeter ) + { bmih.biXPelsPerMeter = XPelsPerMeter; } + else + { bmih.biXPelsPerMeter = DefaultXPelsPerMeter; } + if( YPelsPerMeter ) + { bmih.biYPelsPerMeter = YPelsPerMeter; } + else + { bmih.biYPelsPerMeter = DefaultYPelsPerMeter; } + + bmih.biClrUsed = 0; + bmih.biClrImportant = 0; + + // indicates that we'll be using bit fields for 16-bit files + if( BitDepth == 16 ) + { bmih.biCompression = 3; } + + if( IsBigEndian() ) + { bmih.SwitchEndianess(); } + + fwrite( (char*) &(bmih.biSize) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biWidth) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biHeight) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biPlanes) , sizeof(ebmpWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biBitCount) , sizeof(ebmpWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biCompression) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biSizeImage) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biXPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biYPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biClrUsed) , sizeof(ebmpDWORD) , 1 , fp); + fwrite( (char*) &(bmih.biClrImportant) , sizeof(ebmpDWORD) , 1 , fp); + + // write the palette + if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) + { + int NumberOfColors = IntPow(2,BitDepth); + + // if there is no palette, create one + if( !Colors ) + { + if( !Colors ) + { Colors = new RGBApixel [NumberOfColors]; } + CreateStandardColorTable(); + } + + int n; + for( n=0 ; n < NumberOfColors ; n++ ) + { fwrite( (char*) &(Colors[n]) , 4 , 1 , fp ); } + } + + // write the pixels + int i,j; + if( BitDepth != 16 ) + { + ebmpBYTE* Buffer; + int BufferSize = (int) ( (Width*BitDepth)/8.0 ); + while( 8*BufferSize < Width*BitDepth ) + { BufferSize++; } + while( BufferSize % 4 ) + { BufferSize++; } + + Buffer = new ebmpBYTE [BufferSize]; + for( j=0 ; j < BufferSize; j++ ) + { Buffer[j] = 0; } + + j=Height-1; + + while( j > -1 ) + { + bool Success = false; + if( BitDepth == 32 ) + { Success = Write32bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 24 ) + { Success = Write24bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 8 ) + { Success = Write8bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 4 ) + { Success = Write4bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 1 ) + { Success = Write1bitRow( Buffer, BufferSize, j ); } + if( Success ) + { + int BytesWritten = (int) fwrite( (char*) Buffer, 1, BufferSize, fp ); + if( BytesWritten != BufferSize ) + { Success = false; } + } + if( !Success ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Could not write proper amount of data." << endl; + } + j = -1; + } + j--; + } + + delete [] Buffer; + } + + if( BitDepth == 16 ) + { + // write the bit masks + + ebmpWORD BlueMask = 31; // bits 12-16 + ebmpWORD GreenMask = 2016; // bits 6-11 + ebmpWORD RedMask = 63488; // bits 1-5 + ebmpWORD ZeroWORD; + + if( IsBigEndian() ) + { RedMask = FlipWORD( RedMask ); } + fwrite( (char*) &RedMask , 2 , 1 , fp ); + fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); + + if( IsBigEndian() ) + { GreenMask = FlipWORD( GreenMask ); } + fwrite( (char*) &GreenMask , 2 , 1 , fp ); + fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); + + if( IsBigEndian() ) + { BlueMask = FlipWORD( BlueMask ); } + fwrite( (char*) &BlueMask , 2 , 1 , fp ); + fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); + + int DataBytes = Width*2; + int PaddingBytes = ( 4 - DataBytes % 4 ) % 4; + + // write the actual pixels + + for( j=Height-1 ; j >= 0 ; j-- ) + { + // write all row pixel data + i=0; + int WriteNumber = 0; + while( WriteNumber < DataBytes ) + { + ebmpWORD TempWORD; + + ebmpWORD RedWORD = (ebmpWORD) ((Pixels[i][j]).Red / 8); + ebmpWORD GreenWORD = (ebmpWORD) ((Pixels[i][j]).Green / 4); + ebmpWORD BlueWORD = (ebmpWORD) ((Pixels[i][j]).Blue / 8); + + TempWORD = (RedWORD<<11) + (GreenWORD<<5) + BlueWORD; + if( IsBigEndian() ) + { TempWORD = FlipWORD( TempWORD ); } + + fwrite( (char*) &TempWORD , 2, 1, fp); + WriteNumber += 2; i++; - } - // write any necessary row padding - WriteNumber = 0; - while( WriteNumber < PaddingBytes ) - { - ebmpBYTE TempBYTE; - fwrite( (char*) &TempBYTE , 1, 1, fp); - WriteNumber++; - } - } - - } - - fclose(fp); - return true; -} - -bool BMP::ReadFromFile( const char* FileName ) -{ - using namespace std; - if( !EasyBMPcheckDataSize() ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: Data types are wrong size!" << endl - << " You may need to mess with EasyBMP_DataTypes.h" << endl - << " to fix these errors, and then recompile." << endl - << " All 32-bit and 64-bit machines should be" << endl - << " supported, however." << endl << endl; - } - return false; - } - - FILE* fp = fopen( FileName, "rb" ); - if( fp == NULL ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: Cannot open file " - << FileName << " for input." << endl; - } - SetBitDepth(1); - SetSize(1,1); - return false; - } - - // read the file header - - BMFH bmfh; - bool NotCorrupted = true; - - NotCorrupted &= SafeFread( (char*) &(bmfh.bfType) , sizeof(ebmpWORD), 1, fp); - - bool IsBitmap = false; - - if( IsBigEndian() && bmfh.bfType == 16973 ) - { IsBitmap = true; } - if( !IsBigEndian() && bmfh.bfType == 19778 ) - { IsBitmap = true; } - - if( !IsBitmap ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: " << FileName - << " is not a Windows BMP file!" << endl; - } - fclose( fp ); - return false; - } - - NotCorrupted &= SafeFread( (char*) &(bmfh.bfSize) , sizeof(ebmpDWORD) , 1, fp); - NotCorrupted &= SafeFread( (char*) &(bmfh.bfReserved1) , sizeof(ebmpWORD) , 1, fp); - NotCorrupted &= SafeFread( (char*) &(bmfh.bfReserved2) , sizeof(ebmpWORD) , 1, fp); - NotCorrupted &= SafeFread( (char*) &(bmfh.bfOffBits) , sizeof(ebmpDWORD) , 1 , fp); - - if( IsBigEndian() ) - { bmfh.SwitchEndianess(); } - - // read the info header - - BMIH bmih; - - NotCorrupted &= SafeFread( (char*) &(bmih.biSize) , sizeof(ebmpDWORD) , 1 , fp); - NotCorrupted &= SafeFread( (char*) &(bmih.biWidth) , sizeof(ebmpDWORD) , 1 , fp); - NotCorrupted &= SafeFread( (char*) &(bmih.biHeight) , sizeof(ebmpDWORD) , 1 , fp); - NotCorrupted &= SafeFread( (char*) &(bmih.biPlanes) , sizeof(ebmpWORD) , 1, fp); - NotCorrupted &= SafeFread( (char*) &(bmih.biBitCount) , sizeof(ebmpWORD) , 1, fp); - - NotCorrupted &= SafeFread( (char*) &(bmih.biCompression) , sizeof(ebmpDWORD) , 1 , fp); - NotCorrupted &= SafeFread( (char*) &(bmih.biSizeImage) , sizeof(ebmpDWORD) , 1 , fp); - NotCorrupted &= SafeFread( (char*) &(bmih.biXPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp); - NotCorrupted &= SafeFread( (char*) &(bmih.biYPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp); - NotCorrupted &= SafeFread( (char*) &(bmih.biClrUsed) , sizeof(ebmpDWORD) , 1 , fp); - NotCorrupted &= SafeFread( (char*) &(bmih.biClrImportant) , sizeof(ebmpDWORD) , 1 , fp); - - if( IsBigEndian() ) - { bmih.SwitchEndianess(); } - - // a safety catch: if any of the header information didn't read properly, abort - // future idea: check to see if at least most is self-consistent - - if( !NotCorrupted ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: " << FileName - << " is obviously corrupted." << endl; - } - SetSize(1,1); - SetBitDepth(1); - fclose(fp); - return false; - } - - XPelsPerMeter = bmih.biXPelsPerMeter; - YPelsPerMeter = bmih.biYPelsPerMeter; - - // if bmih.biCompression 1 or 2, then the file is RLE compressed - - if( bmih.biCompression == 1 || bmih.biCompression == 2 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: " << FileName << " is (RLE) compressed." << endl - << " EasyBMP does not support compression." << endl; - } - SetSize(1,1); - SetBitDepth(1); - fclose(fp); - return false; - } - - // if bmih.biCompression > 3, then something strange is going on - // it's probably an OS2 bitmap file. - - if( bmih.biCompression > 3 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: " << FileName << " is in an unsupported format." - << endl - << " (bmih.biCompression = " - << bmih.biCompression << ")" << endl - << " The file is probably an old OS2 bitmap or corrupted." - << endl; - } - SetSize(1,1); - SetBitDepth(1); - fclose(fp); - return false; - } - - if( bmih.biCompression == 3 && bmih.biBitCount != 16 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: " << FileName - << " uses bit fields and is not a" << endl - << " 16-bit file. This is not supported." << endl; - } - SetSize(1,1); - SetBitDepth(1); - fclose(fp); - return false; - } - - // set the bit depth - - int TempBitDepth = (int) bmih.biBitCount; - if( TempBitDepth != 1 && TempBitDepth != 4 - && TempBitDepth != 8 && TempBitDepth != 16 - && TempBitDepth != 24 && TempBitDepth != 32 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: " << FileName << " has unrecognized bit depth." << endl; - } - SetSize(1,1); - SetBitDepth(1); - fclose(fp); - return false; - } - SetBitDepth( (int) bmih.biBitCount ); - - // set the size - - if( (int) bmih.biWidth <= 0 || (int) bmih.biHeight <= 0 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: " << FileName - << " has a non-positive width or height." << endl; - } - SetSize(1,1); - SetBitDepth(1); - fclose(fp); - return false; - } - SetSize( (int) bmih.biWidth , (int) bmih.biHeight ); - - // some preliminaries - - double dBytesPerPixel = ( (double) BitDepth ) / 8.0; - double dBytesPerRow = dBytesPerPixel * (Width+0.0); - dBytesPerRow = ceil(dBytesPerRow); - - int BytePaddingPerRow = 4 - ( (int) (dBytesPerRow) )% 4; - if( BytePaddingPerRow == 4 ) - { BytePaddingPerRow = 0; } - - // if < 16 bits, read the palette - - if( BitDepth < 16 ) - { - // determine the number of colors specified in the - // color table - - int NumberOfColorsToRead = ((int) bmfh.bfOffBits - 54 )/4; - if( NumberOfColorsToRead > IntPow(2,BitDepth) ) - { NumberOfColorsToRead = IntPow(2,BitDepth); } - - if( NumberOfColorsToRead < TellNumberOfColors() ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: file " << FileName << " has an underspecified" << endl - << " color table. The table will be padded with extra" << endl - << " white (255,255,255,0) entries." << endl; - } - } - - int n; - for( n=0; n < NumberOfColorsToRead ; n++ ) - { - SafeFread( (char*) &(Colors[n]) , 4 , 1 , fp); - } - for( n=NumberOfColorsToRead ; n < TellNumberOfColors() ; n++ ) - { - RGBApixel WHITE; - WHITE.Red = 255; - WHITE.Green = 255; - WHITE.Blue = 255; - WHITE.Alpha = 0; - SetColor( n , WHITE ); - } - - - } - - // skip blank data if bfOffBits so indicates - - int BytesToSkip = bmfh.bfOffBits - 54;; - if( BitDepth < 16 ) - { BytesToSkip -= 4*IntPow(2,BitDepth); } - if( BitDepth == 16 && bmih.biCompression == 3 ) - { BytesToSkip -= 3*4; } - if( BytesToSkip < 0 ) - { BytesToSkip = 0; } - if( BytesToSkip > 0 && BitDepth != 16 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Extra meta data detected in file " << FileName << endl - << " Data will be skipped." << endl; - } - ebmpBYTE* TempSkipBYTE; - TempSkipBYTE = new ebmpBYTE [BytesToSkip]; + } + // write any necessary row padding + WriteNumber = 0; + while( WriteNumber < PaddingBytes ) + { + ebmpBYTE TempBYTE; + fwrite( (char*) &TempBYTE , 1, 1, fp); + WriteNumber++; + } + } + + } + + fclose(fp); + return true; +} + +bool BMP::ReadFromFile( const char* FileName ) +{ + using namespace std; + if( !EasyBMPcheckDataSize() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Data types are wrong size!" << endl + << " You may need to mess with EasyBMP_DataTypes.h" << endl + << " to fix these errors, and then recompile." << endl + << " All 32-bit and 64-bit machines should be" << endl + << " supported, however." << endl << endl; + } + return false; + } + + FILE* fp = fopen( FileName, "rb" ); + if( fp == NULL ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Cannot open file " + << FileName << " for input." << endl; + } + SetBitDepth(1); + SetSize(1,1); + return false; + } + + // read the file header + + BMFH bmfh; + bool NotCorrupted = true; + + NotCorrupted &= SafeFread( (char*) &(bmfh.bfType) , sizeof(ebmpWORD), 1, fp); + + bool IsBitmap = false; + + if( IsBigEndian() && bmfh.bfType == 16973 ) + { IsBitmap = true; } + if( !IsBigEndian() && bmfh.bfType == 19778 ) + { IsBitmap = true; } + + if( !IsBitmap ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName + << " is not a Windows BMP file!" << endl; + } + fclose( fp ); + return false; + } + + NotCorrupted &= SafeFread( (char*) &(bmfh.bfSize) , sizeof(ebmpDWORD) , 1, fp); + NotCorrupted &= SafeFread( (char*) &(bmfh.bfReserved1) , sizeof(ebmpWORD) , 1, fp); + NotCorrupted &= SafeFread( (char*) &(bmfh.bfReserved2) , sizeof(ebmpWORD) , 1, fp); + NotCorrupted &= SafeFread( (char*) &(bmfh.bfOffBits) , sizeof(ebmpDWORD) , 1 , fp); + + if( IsBigEndian() ) + { bmfh.SwitchEndianess(); } + + // read the info header + + BMIH bmih; + + NotCorrupted &= SafeFread( (char*) &(bmih.biSize) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biWidth) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biHeight) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biPlanes) , sizeof(ebmpWORD) , 1, fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biBitCount) , sizeof(ebmpWORD) , 1, fp); + + NotCorrupted &= SafeFread( (char*) &(bmih.biCompression) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biSizeImage) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biXPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biYPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biClrUsed) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biClrImportant) , sizeof(ebmpDWORD) , 1 , fp); + + if( IsBigEndian() ) + { bmih.SwitchEndianess(); } + + // a safety catch: if any of the header information didn't read properly, abort + // future idea: check to see if at least most is self-consistent + + if( !NotCorrupted ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName + << " is obviously corrupted." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + + XPelsPerMeter = bmih.biXPelsPerMeter; + YPelsPerMeter = bmih.biYPelsPerMeter; + + // if bmih.biCompression 1 or 2, then the file is RLE compressed + + if( bmih.biCompression == 1 || bmih.biCompression == 2 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName << " is (RLE) compressed." << endl + << " EasyBMP does not support compression." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + + // if bmih.biCompression > 3, then something strange is going on + // it's probably an OS2 bitmap file. + + if( bmih.biCompression > 3 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName << " is in an unsupported format." + << endl + << " (bmih.biCompression = " + << bmih.biCompression << ")" << endl + << " The file is probably an old OS2 bitmap or corrupted." + << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + + if( bmih.biCompression == 3 && bmih.biBitCount != 16 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName + << " uses bit fields and is not a" << endl + << " 16-bit file. This is not supported." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + + // set the bit depth + + int TempBitDepth = (int) bmih.biBitCount; + if( TempBitDepth != 1 && TempBitDepth != 4 + && TempBitDepth != 8 && TempBitDepth != 16 + && TempBitDepth != 24 && TempBitDepth != 32 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName << " has unrecognized bit depth." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + SetBitDepth( (int) bmih.biBitCount ); + + // set the size + + if( (int) bmih.biWidth <= 0 || (int) bmih.biHeight <= 0 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName + << " has a non-positive width or height." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + SetSize( (int) bmih.biWidth , (int) bmih.biHeight ); + + // some preliminaries + + double dBytesPerPixel = ( (double) BitDepth ) / 8.0; + double dBytesPerRow = dBytesPerPixel * (Width+0.0); + dBytesPerRow = ceil(dBytesPerRow); + + int BytePaddingPerRow = 4 - ( (int) (dBytesPerRow) )% 4; + if( BytePaddingPerRow == 4 ) + { BytePaddingPerRow = 0; } + + // if < 16 bits, read the palette + + if( BitDepth < 16 ) + { + // determine the number of colors specified in the + // color table + + int NumberOfColorsToRead = ((int) bmfh.bfOffBits - 54 )/4; + if( NumberOfColorsToRead > IntPow(2,BitDepth) ) + { NumberOfColorsToRead = IntPow(2,BitDepth); } + + if( NumberOfColorsToRead < TellNumberOfColors() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: file " << FileName << " has an underspecified" << endl + << " color table. The table will be padded with extra" << endl + << " white (255,255,255,0) entries." << endl; + } + } + + int n; + for( n=0; n < NumberOfColorsToRead ; n++ ) + { + SafeFread( (char*) &(Colors[n]) , 4 , 1 , fp); + } + for( n=NumberOfColorsToRead ; n < TellNumberOfColors() ; n++ ) + { + RGBApixel WHITE; + WHITE.Red = 255; + WHITE.Green = 255; + WHITE.Blue = 255; + WHITE.Alpha = 0; + SetColor( n , WHITE ); + } + + + } + + // skip blank data if bfOffBits so indicates + + int BytesToSkip = bmfh.bfOffBits - 54;; + if( BitDepth < 16 ) + { BytesToSkip -= 4*IntPow(2,BitDepth); } + if( BitDepth == 16 && bmih.biCompression == 3 ) + { BytesToSkip -= 3*4; } + if( BytesToSkip < 0 ) + { BytesToSkip = 0; } + if( BytesToSkip > 0 && BitDepth != 16 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Extra meta data detected in file " << FileName << endl + << " Data will be skipped." << endl; + } + ebmpBYTE* TempSkipBYTE; + TempSkipBYTE = new ebmpBYTE [BytesToSkip]; SafeFread( (char*) TempSkipBYTE , BytesToSkip , 1 , fp); - delete [] TempSkipBYTE; - } - - // This code reads 1, 4, 8, 24, and 32-bpp files - // with a more-efficient buffered technique. - - int i,j; - if( BitDepth != 16 ) - { - int BufferSize = (int) ( (Width*BitDepth) / 8.0 ); - while( 8*BufferSize < Width*BitDepth ) - { BufferSize++; } - while( BufferSize % 4 ) - { BufferSize++; } - ebmpBYTE* Buffer; - Buffer = new ebmpBYTE [BufferSize]; - j= Height-1; - while( j > -1 ) - { - int BytesRead = (int) fread( (char*) Buffer, 1, BufferSize, fp ); - if( BytesRead < BufferSize ) - { - j = -1; - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: Could not read proper amount of data." << endl; - } - } - else - { - bool Success = false; - if( BitDepth == 1 ) - { Success = Read1bitRow( Buffer, BufferSize, j ); } - if( BitDepth == 4 ) - { Success = Read4bitRow( Buffer, BufferSize, j ); } - if( BitDepth == 8 ) - { Success = Read8bitRow( Buffer, BufferSize, j ); } - if( BitDepth == 24 ) - { Success = Read24bitRow( Buffer, BufferSize, j ); } - if( BitDepth == 32 ) - { Success = Read32bitRow( Buffer, BufferSize, j ); } - if( !Success ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Error: Could not read enough pixel data!" << endl; - } - j = -1; - } - } - j--; - } - delete [] Buffer; - } - - if( BitDepth == 16 ) - { - int DataBytes = Width*2; - int PaddingBytes = ( 4 - DataBytes % 4 ) % 4; - - // set the default mask - - ebmpWORD BlueMask = 31; // bits 12-16 - ebmpWORD GreenMask = 992; // bits 7-11 - ebmpWORD RedMask = 31744; // bits 2-6 - - // read the bit fields, if necessary, to - // override the default 5-5-5 mask - - if( bmih.biCompression != 0 ) - { - // read the three bit masks - - ebmpWORD TempMaskWORD; - ebmpWORD ZeroWORD; - - SafeFread( (char*) &RedMask , 2 , 1 , fp ); - if( IsBigEndian() ) - { RedMask = FlipWORD(RedMask); } - SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); - - SafeFread( (char*) &GreenMask , 2 , 1 , fp ); - if( IsBigEndian() ) - { GreenMask = FlipWORD(GreenMask); } - SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); - - SafeFread( (char*) &BlueMask , 2 , 1 , fp ); - if( IsBigEndian() ) - { BlueMask = FlipWORD(BlueMask); } - SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); - } - - // read and skip any meta data - - if( BytesToSkip > 0 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Extra meta data detected in file " - << FileName << endl - << " Data will be skipped." << endl; - } - ebmpBYTE* TempSkipBYTE; - TempSkipBYTE = new ebmpBYTE [BytesToSkip]; + delete [] TempSkipBYTE; + } + + // This code reads 1, 4, 8, 24, and 32-bpp files + // with a more-efficient buffered technique. + + int i,j; + if( BitDepth != 16 ) + { + int BufferSize = (int) ( (Width*BitDepth) / 8.0 ); + while( 8*BufferSize < Width*BitDepth ) + { BufferSize++; } + while( BufferSize % 4 ) + { BufferSize++; } + ebmpBYTE* Buffer; + Buffer = new ebmpBYTE [BufferSize]; + j= Height-1; + while( j > -1 ) + { + int BytesRead = (int) fread( (char*) Buffer, 1, BufferSize, fp ); + if( BytesRead < BufferSize ) + { + j = -1; + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Could not read proper amount of data." << endl; + } + } + else + { + bool Success = false; + if( BitDepth == 1 ) + { Success = Read1bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 4 ) + { Success = Read4bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 8 ) + { Success = Read8bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 24 ) + { Success = Read24bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 32 ) + { Success = Read32bitRow( Buffer, BufferSize, j ); } + if( !Success ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Could not read enough pixel data!" << endl; + } + j = -1; + } + } + j--; + } + delete [] Buffer; + } + + if( BitDepth == 16 ) + { + int DataBytes = Width*2; + int PaddingBytes = ( 4 - DataBytes % 4 ) % 4; + + // set the default mask + + ebmpWORD BlueMask = 31; // bits 12-16 + ebmpWORD GreenMask = 992; // bits 7-11 + ebmpWORD RedMask = 31744; // bits 2-6 + + // read the bit fields, if necessary, to + // override the default 5-5-5 mask + + if( bmih.biCompression != 0 ) + { + // read the three bit masks + + ebmpWORD TempMaskWORD; + ebmpWORD ZeroWORD; + + SafeFread( (char*) &RedMask , 2 , 1 , fp ); + if( IsBigEndian() ) + { RedMask = FlipWORD(RedMask); } + SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); + + SafeFread( (char*) &GreenMask , 2 , 1 , fp ); + if( IsBigEndian() ) + { GreenMask = FlipWORD(GreenMask); } + SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); + + SafeFread( (char*) &BlueMask , 2 , 1 , fp ); + if( IsBigEndian() ) + { BlueMask = FlipWORD(BlueMask); } + SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); + } + + // read and skip any meta data + + if( BytesToSkip > 0 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Extra meta data detected in file " + << FileName << endl + << " Data will be skipped." << endl; + } + ebmpBYTE* TempSkipBYTE; + TempSkipBYTE = new ebmpBYTE [BytesToSkip]; SafeFread( (char*) TempSkipBYTE , BytesToSkip , 1 , fp); - delete [] TempSkipBYTE; - } - - // determine the red, green and blue shifts - - int GreenShift = 0; - ebmpWORD TempShiftWORD = GreenMask; - while( TempShiftWORD > 31 ) - { TempShiftWORD = TempShiftWORD>>1; GreenShift++; } - int BlueShift = 0; - TempShiftWORD = BlueMask; - while( TempShiftWORD > 31 ) - { TempShiftWORD = TempShiftWORD>>1; BlueShift++; } - int RedShift = 0; - TempShiftWORD = RedMask; - while( TempShiftWORD > 31 ) - { TempShiftWORD = TempShiftWORD>>1; RedShift++; } - - // read the actual pixels - - for( j=Height-1 ; j >= 0 ; j-- ) - { - i=0; - int ReadNumber = 0; - while( ReadNumber < DataBytes ) - { - ebmpWORD TempWORD; - SafeFread( (char*) &TempWORD , 2 , 1 , fp ); - if( IsBigEndian() ) - { TempWORD = FlipWORD(TempWORD); } - ReadNumber += 2; - - ebmpWORD Red = RedMask & TempWORD; - ebmpWORD Green = GreenMask & TempWORD; - ebmpWORD Blue = BlueMask & TempWORD; - - ebmpBYTE BlueBYTE = (ebmpBYTE) 8*(Blue>>BlueShift); - ebmpBYTE GreenBYTE = (ebmpBYTE) 8*(Green>>GreenShift); - ebmpBYTE RedBYTE = (ebmpBYTE) 8*(Red>>RedShift); - - (Pixels[i][j]).Red = RedBYTE; - (Pixels[i][j]).Green = GreenBYTE; - (Pixels[i][j]).Blue = BlueBYTE; - - i++; - } - ReadNumber = 0; - while( ReadNumber < PaddingBytes ) - { - ebmpBYTE TempBYTE; - SafeFread( (char*) &TempBYTE , 1, 1, fp); - ReadNumber++; - } - } - - } - - fclose(fp); - return true; -} - -bool BMP::CreateStandardColorTable( void ) -{ - using namespace std; - if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) - { - if( EasyBMPwarnings ) - { - cout << "EasyBMP Warning: Attempted to create color table at a bit" << endl - << " depth that does not require a color table." << endl - << " Ignoring request." << endl; - } - return false; - } - - if( BitDepth == 1 ) - { - int i; - for( i=0 ; i < 2 ; i++ ) - { - Colors[i].Red = i*255; - Colors[i].Green = i*255; - Colors[i].Blue = i*255; - Colors[i].Alpha = 0; - } - return true; - } - - if( BitDepth == 4 ) - { - int i = 0; - int j,k,ell; - - // simplify the code for the first 8 colors - for( ell=0 ; ell < 2 ; ell++ ) - { - for( k=0 ; k < 2 ; k++ ) - { - for( j=0 ; j < 2 ; j++ ) - { - Colors[i].Red = j*128; - Colors[i].Green = k*128; - Colors[i].Blue = ell*128; - i++; - } - } - } - - // simplify the code for the last 8 colors - for( ell=0 ; ell < 2 ; ell++ ) - { - for( k=0 ; k < 2 ; k++ ) - { - for( j=0 ; j < 2 ; j++ ) - { - Colors[i].Red = j*255; - Colors[i].Green = k*255; - Colors[i].Blue = ell*255; - i++; - } - } - } - - // overwrite the duplicate color - i=8; - Colors[i].Red = 192; - Colors[i].Green = 192; - Colors[i].Blue = 192; - - for( i=0 ; i < 16 ; i++ ) - { Colors[i].Alpha = 0; } - return true; - } - - if( BitDepth == 8 ) - { - int i=0; - int j,k,ell; - - // do an easy loop, which works for all but colors - // 0 to 9 and 246 to 255 - for( ell=0 ; ell < 4 ; ell++ ) - { - for( k=0 ; k < 8 ; k++ ) - { - for( j=0; j < 8 ; j++ ) - { - Colors[i].Red = j*32; - Colors[i].Green = k*32; - Colors[i].Blue = ell*64; - Colors[i].Alpha = 0; - i++; - } - } - } - - // now redo the first 8 colors - i=0; - for( ell=0 ; ell < 2 ; ell++ ) - { - for( k=0 ; k < 2 ; k++ ) - { - for( j=0; j < 2 ; j++ ) - { - Colors[i].Red = j*128; - Colors[i].Green = k*128; - Colors[i].Blue = ell*128; - i++; - } - } - } - - // overwrite colors 7, 8, 9 - i=7; - Colors[i].Red = 192; - Colors[i].Green = 192; - Colors[i].Blue = 192; - i++; // 8 - Colors[i].Red = 192; - Colors[i].Green = 220; - Colors[i].Blue = 192; - i++; // 9 - Colors[i].Red = 166; - Colors[i].Green = 202; - Colors[i].Blue = 240; - - // overwrite colors 246 to 255 - i=246; - Colors[i].Red = 255; - Colors[i].Green = 251; - Colors[i].Blue = 240; - i++; // 247 - Colors[i].Red = 160; - Colors[i].Green = 160; - Colors[i].Blue = 164; - i++; // 248 - Colors[i].Red = 128; - Colors[i].Gre... [truncated message content] |
From: <rom...@us...> - 2009-01-03 07:28:38
|
Revision: 1519 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1519&view=rev Author: roman_yakovenko Date: 2009-01-03 07:28:24 +0000 (Sat, 03 Jan 2009) Log Message: ----------- .map files generate using different "undecorate" options. Modified Paths: -------------- pygccxml_dev/pygccxml/msvc/common_utils.py Modified: pygccxml_dev/pygccxml/msvc/common_utils.py =================================================================== --- pygccxml_dev/pygccxml/msvc/common_utils.py 2009-01-01 19:39:29 UTC (rev 1518) +++ pygccxml_dev/pygccxml/msvc/common_utils.py 2009-01-03 07:28:24 UTC (rev 1519) @@ -88,17 +88,29 @@ , ( 'long int', 'long' ) , ( 'long unsigned int', 'unsigned long' ) ) + self.__calling_conventions = re.compile( r'(?:(^|\s))(?:__(cdecl|clrcall|stdcall|fastcall|thiscall)\s)' ) + def normalize_undecorated( self, undname, options=None ): + if options is None: + options = UNDECORATE_NAME_OPTIONS.SHORT_UNIQUE_NAME + if UNDECORATE_NAME_OPTIONS.UNDNAME_NO_ECSU & options: + undname = self.__clean_ecsu.sub( '', undname ) + if UNDECORATE_NAME_OPTIONS.UNDNAME_NO_ACCESS_SPECIFIERS & options: + for prefix in ( 'public: ', 'private: ', 'protected: ' ): + if undname.startswith( prefix ): + undname = undname[ len(prefix): ] + break + if UNDECORATE_NAME_OPTIONS.UNDNAME_NO_MS_KEYWORDS & options: + undname = self.__calling_conventions.sub( ' ', undname) + return undname.strip() + def undecorate_blob( self, name, options=None ): if options is None: options = UNDECORATE_NAME_OPTIONS.SHORT_UNIQUE_NAME buffer = ctypes.create_string_buffer(1024*16) res = self.__undname( str(name), buffer, ctypes.sizeof(buffer), options) if res: - undname = str(buffer[:res]) - if UNDECORATE_NAME_OPTIONS.UNDNAME_NO_ECSU & options: - undname = self.__clean_ecsu.sub( '', undname ) - return undname.strip() + return self.normalize_undecorated_blob( str(buffer[:res]) ) else: return name @@ -188,6 +200,7 @@ undecorate_blob = undname_creator().undecorate_blob undecorate_decl = undname_creator().undecorated_decl undecorate_argtypes = undname_creator().undecorate_argtypes + normalize_undecorated = undname_creator().normalize_undecorated else: def undecorate_blob( x ): raise NotImplementedError() @@ -195,6 +208,8 @@ raise NotImplementedError() def undecorate_argtypes( x ): raise NotImplementedError() + def normalize_undecorated( *args ): + raise NotImplementedError() import exceptions class LicenseWarning( exceptions.UserWarning ): @@ -220,11 +235,12 @@ else: pass index = 0 + while index < len( lines ): line = lines[index].rstrip() found = exported_symbols.map_file_re_cpp.match( line ) if found: - result[ found.group( 'decorated' ) ] = found.group( 'undecorated' ) + result[ found.group( 'decorated' ) ] = normalize_undecorated( found.group( 'undecorated' ) ) elif index + 1 < len( lines ): two_lines = line + lines[index+1].rstrip() found = exported_symbols.map_file_re_c.match( two_lines ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2009-01-01 19:39:32
|
Revision: 1518 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1518&view=rev Author: roman_yakovenko Date: 2009-01-01 19:39:29 +0000 (Thu, 01 Jan 2009) Log Message: ----------- adding environment Added Paths: ----------- pyplusplus_dev/examples/pyeasybmp_dev/environment.py Added: pyplusplus_dev/examples/pyeasybmp_dev/environment.py =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/environment.py (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/environment.py 2009-01-01 19:39:29 UTC (rev 1518) @@ -0,0 +1,28 @@ +#! /usr/bin/python +# Copyright 2004-2008 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 + +this_module_dir_path = os.path.abspath ( os.path.dirname( sys.modules[__name__].__file__) ) +project_root = os.path.abspath( os.path.join( this_module_dir_path, '..','..', '..' ) ) +print project_root +complete_path = lambda *args: os.path.join( project_root, *args ) + +class settings: + module_name = 'easybmp' + gccxml_path = complete_path( 'gccxml_bin', 'v09', sys.platform, 'bin' ) + pygccxml_path = complete_path( 'pygccxml_dev' ) + pyplusplus_path = complete_path( 'pyplusplus_dev' ) + easybmp_path = complete_path( 'pyplusplus_dev', 'examples', 'pyeasybmp_dev', 'easybmp' ) + working_dir = easybmp_path + + @staticmethod + def setup_environment(): + sys.path.append( settings.pygccxml_path ) + sys.path.append( settings.pyplusplus_path ) + +settings.setup_environment() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2008-12-31 14:07:45
|
Revision: 1517 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1517&view=rev Author: roman_yakovenko Date: 2008-12-31 14:07:37 +0000 (Wed, 31 Dec 2008) Log Message: ----------- adding ctypes functionality Modified Paths: -------------- pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sconscript Added Paths: ----------- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/ pyplusplus_dev/examples/pyeasybmp_dev/ctypes/generate_code.py Added: pyplusplus_dev/examples/pyeasybmp_dev/ctypes/generate_code.py =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/ctypes/generate_code.py (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/ctypes/generate_code.py 2008-12-31 14:07:37 UTC (rev 1517) @@ -0,0 +1,21 @@ +import os +import sys +sys.path.append( '..' ) + +from environment import settings + +from pygccxml import parser +from pyplusplus.module_builder import ctypes_module_builder_t + +symbols_file = os.path.join( settings.easybmp_path, 'binaries', 'easybmp.map' ) +shared_library = os.path.join( settings.easybmp_path, 'binaries', 'easybmp.dll' ) + + +gccxml_cfg = parser.gccxml_configuration_t( working_directory=settings.working_dir + , compiler='msvc71' + , gccxml_path=settings.gccxml_path ) + +mb = ctypes_module_builder_t( ['EasyBMP.h'], symbols_file, gccxml_cfg ) + +mb.build_code_creator( shared_library ) +mb.write_module( 'easybmp.py' ) Modified: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sconscript =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sconscript 2008-12-31 13:21:01 UTC (rev 1516) +++ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sconscript 2008-12-31 14:07:37 UTC (rev 1517) @@ -3,5 +3,5 @@ t = env.SharedLibrary( target=r'easybmp' , source=[ r'EasyBMP.cpp' ] , CCFLAGS=[ r"/MD",r"/EHsc",r"/GR",r"/Zc:wchar_t",r"/Zc:forScope" ] - , LINKFLAGS=[r"/MAP"] + , LINKFLAGS=[r"/MAP:binaries\easybmp.map", r"/MAPINFO:EXPORTS"] , SHLIBSUFFIX='.dll' ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2008-12-31 13:21:07
|
Revision: 1516 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1516&view=rev Author: roman_yakovenko Date: 2008-12-31 13:21:01 +0000 (Wed, 31 Dec 2008) Log Message: ----------- preparing easybmp example for new functionality Added Paths: ----------- pyplusplus_dev/examples/pyeasybmp_dev/boost.python/ pyplusplus_dev/examples/pyeasybmp_dev/boost.python/pyeasybmp/ pyplusplus_dev/examples/pyeasybmp_dev/boost.python/unittests/ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/BSD_(revised)_license.txt pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.cpp pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.h pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_BMP.h pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_ChangeLog.txt pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_DataStructures.h pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_VariousBMPutilities.h pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sample/ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sample/EasyBMPbackground.bmp pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sample/EasyBMPsample.cpp pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sample/EasyBMPtext.bmp pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sample/makefile pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sconscript pyplusplus_dev/examples/pyeasybmp_dev/easybmp/sconstruct Removed Paths: ------------- pyplusplus_dev/examples/pyeasybmp_dev/pyeasybmp/ pyplusplus_dev/examples/pyeasybmp_dev/unittests/ Added: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/BSD_(revised)_license.txt =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/easybmp/BSD_(revised)_license.txt (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/BSD_(revised)_license.txt 2008-12-31 13:21:01 UTC (rev 1516) @@ -0,0 +1,10 @@ +Copyright (c) 2005, The EasyBMP Project (http://easybmp.sourceforge.net) +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file Added: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.cpp =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.cpp (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.cpp 2008-12-31 13:21:01 UTC (rev 1516) @@ -0,0 +1,1905 @@ +/************************************************* +* * +* EasyBMP Cross-Platform Windows Bitmap Library * +* * +* Author: Paul Macklin * +* email: mac...@us... * +* support: http://easybmp.sourceforge.net * +* * +* file: EasyBMP.cpp * +* date added: 03-31-2006 * +* date modified: 12-01-2006 * +* version: 1.06 * +* * +* License: BSD (revised/modified) * +* Copyright: 2005-6 by the EasyBMP Project * +* * +* description: Actual source file * +* * +*************************************************/ + +#include "EasyBMP.h" + +/* These functions are defined in EasyBMP.h */ + +bool EasyBMPwarnings = true; + +void SetEasyBMPwarningsOff( void ) +{ EasyBMPwarnings = false; } +void SetEasyBMPwarningsOn( void ) +{ EasyBMPwarnings = true; } +bool GetEasyBMPwarningState( void ) +{ return EasyBMPwarnings; } + +/* These functions are defined in EasyBMP_DataStructures.h */ + +int IntPow( int base, int exponent ) +{ + int i; + int output = 1; + for( i=0 ; i < exponent ; i++ ) + { output *= base; } + return output; +} + +BMFH::BMFH() +{ + bfType = 19778; + bfReserved1 = 0; + bfReserved2 = 0; +} + +void BMFH::SwitchEndianess( void ) +{ + bfType = FlipWORD( bfType ); + bfSize = FlipDWORD( bfSize ); + bfReserved1 = FlipWORD( bfReserved1 ); + bfReserved2 = FlipWORD( bfReserved2 ); + bfOffBits = FlipDWORD( bfOffBits ); + return; +} + +BMIH::BMIH() +{ + biPlanes = 1; + biCompression = 0; + biXPelsPerMeter = DefaultXPelsPerMeter; + biYPelsPerMeter = DefaultYPelsPerMeter; + biClrUsed = 0; + biClrImportant = 0; +} + +void BMIH::SwitchEndianess( void ) +{ + biSize = FlipDWORD( biSize ); + biWidth = FlipDWORD( biWidth ); + biHeight = FlipDWORD( biHeight ); + biPlanes = FlipWORD( biPlanes ); + biBitCount = FlipWORD( biBitCount ); + biCompression = FlipDWORD( biCompression ); + biSizeImage = FlipDWORD( biSizeImage ); + biXPelsPerMeter = FlipDWORD( biXPelsPerMeter ); + biYPelsPerMeter = FlipDWORD( biYPelsPerMeter ); + biClrUsed = FlipDWORD( biClrUsed ); + biClrImportant = FlipDWORD( biClrImportant ); + return; +} + +void BMIH::display( void ) +{ + using namespace std; + cout << "biSize: " << (int) biSize << endl + << "biWidth: " << (int) biWidth << endl + << "biHeight: " << (int) biHeight << endl + << "biPlanes: " << (int) biPlanes << endl + << "biBitCount: " << (int) biBitCount << endl + << "biCompression: " << (int) biCompression << endl + << "biSizeImage: " << (int) biSizeImage << endl + << "biXPelsPerMeter: " << (int) biXPelsPerMeter << endl + << "biYPelsPerMeter: " << (int) biYPelsPerMeter << endl + << "biClrUsed: " << (int) biClrUsed << endl + << "biClrImportant: " << (int) biClrImportant << endl << endl; +} + +void BMFH::display( void ) +{ + using namespace std; + cout << "bfType: " << (int) bfType << endl + << "bfSize: " << (int) bfSize << endl + << "bfReserved1: " << (int) bfReserved1 << endl + << "bfReserved2: " << (int) bfReserved2 << endl + << "bfOffBits: " << (int) bfOffBits << endl << endl; +} + +/* These functions are defined in EasyBMP_BMP.h */ + +RGBApixel BMP::GetPixel( int i, int j ) const +{ + using namespace std; + bool Warn = false; + if( i >= Width ) + { i = Width-1; Warn = true; } + if( i < 0 ) + { i = 0; Warn = true; } + if( j >= Height ) + { j = Height-1; Warn = true; } + if( j < 0 ) + { j = 0; Warn = true; } + if( Warn && EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to access non-existent pixel;" << endl + << " Truncating request to fit in the range [0," + << Width-1 << "] x [0," << Height-1 << "]." << endl; + } + return Pixels[i][j]; +} + +bool BMP::SetPixel( int i, int j, RGBApixel NewPixel ) +{ + Pixels[i][j] = NewPixel; + return true; +} + + +bool BMP::SetColor( int ColorNumber , RGBApixel NewColor ) +{ + using namespace std; + if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to change color table for a BMP object" << endl + << " that lacks a color table. Ignoring request." << endl; + } + return false; + } + if( !Colors ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to set a color, but the color table" << endl + << " is not defined. Ignoring request." << endl; + } + return false; + } + if( ColorNumber >= TellNumberOfColors() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Requested color number " + << ColorNumber << " is outside the allowed" << endl + << " range [0," << TellNumberOfColors()-1 + << "]. Ignoring request to set this color." << endl; + } + return false; + } + Colors[ColorNumber] = NewColor; + return true; +} + +// RGBApixel BMP::GetColor( int ColorNumber ) const +RGBApixel BMP::GetColor( int ColorNumber ) +{ + RGBApixel Output; + Output.Red = 255; + Output.Green = 255; + Output.Blue = 255; + Output.Alpha = 0; + + using namespace std; + if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to access color table for a BMP object" << endl + << " that lacks a color table. Ignoring request." << endl; + } + return Output; + } + if( !Colors ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Requested a color, but the color table" << endl + << " is not defined. Ignoring request." << endl; + } + return Output; + } + if( ColorNumber >= TellNumberOfColors() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Requested color number " + << ColorNumber << " is outside the allowed" << endl + << " range [0," << TellNumberOfColors()-1 + << "]. Ignoring request to get this color." << endl; + } + return Output; + } + Output = Colors[ColorNumber]; + return Output; +} + +BMP::BMP() +{ + Width = 1; + Height = 1; + BitDepth = 24; + Pixels = new RGBApixel* [Width]; + Pixels[0] = new RGBApixel [Height]; + Colors = NULL; + + XPelsPerMeter = 0; + YPelsPerMeter = 0; + + MetaData1 = NULL; + SizeOfMetaData1 = 0; + MetaData2 = NULL; + SizeOfMetaData2 = 0; +} + +// BMP::BMP( const BMP& Input ) +BMP::BMP( BMP& Input ) +{ + // first, make the image empty. + + Width = 1; + Height = 1; + BitDepth = 24; + Pixels = new RGBApixel* [Width]; + Pixels[0] = new RGBApixel [Height]; + Colors = NULL; + XPelsPerMeter = 0; + YPelsPerMeter = 0; + + MetaData1 = NULL; + SizeOfMetaData1 = 0; + MetaData2 = NULL; + SizeOfMetaData2 = 0; + + // now, set the correct bit depth + + SetBitDepth( Input.TellBitDepth() ); + + // set the correct pixel size + + SetSize( Input.TellWidth() , Input.TellHeight() ); + + // set the DPI information from Input + + SetDPI( Input.TellHorizontalDPI() , Input.TellVerticalDPI() ); + + // if there is a color table, get all the colors + + if( BitDepth == 1 || BitDepth == 4 || + BitDepth == 8 ) + { + for( int k=0 ; k < TellNumberOfColors() ; k++ ) + { + SetColor( k, Input.GetColor( k )); + } + } + + // get all the pixels + + for( int j=0; j < Height ; j++ ) + { + for( int i=0; i < Width ; i++ ) + { + Pixels[i][j] = *Input(i,j); +// Pixels[i][j] = Input.GetPixel(i,j); // *Input(i,j); + } + } +} + +BMP::~BMP() +{ + int i; + for(i=0;i<Width;i++) + { delete [] Pixels[i]; } + delete [] Pixels; + if( Colors ) + { delete [] Colors; } + + if( MetaData1 ) + { delete [] MetaData1; } + if( MetaData2 ) + { delete [] MetaData2; } +} + +RGBApixel* BMP::operator()(int i, int j) +{ + using namespace std; + bool Warn = false; + if( i >= Width ) + { i = Width-1; Warn = true; } + if( i < 0 ) + { i = 0; Warn = true; } + if( j >= Height ) + { j = Height-1; Warn = true; } + if( j < 0 ) + { j = 0; Warn = true; } + if( Warn && EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to access non-existent pixel;" << endl + << " Truncating request to fit in the range [0," + << Width-1 << "] x [0," << Height-1 << "]." << endl; + } + return &(Pixels[i][j]); +} + +// int BMP::TellBitDepth( void ) const +int BMP::TellBitDepth( void ) +{ return BitDepth; } + +// int BMP::TellHeight( void ) const +int BMP::TellHeight( void ) +{ return Height; } + +// int BMP::TellWidth( void ) const +int BMP::TellWidth( void ) +{ return Width; } + +// int BMP::TellNumberOfColors( void ) const +int BMP::TellNumberOfColors( void ) +{ + int output = IntPow( 2, BitDepth ); + if( BitDepth == 32 ) + { output = IntPow( 2, 24 ); } + return output; +} + +bool BMP::SetBitDepth( int NewDepth ) +{ + using namespace std; + if( NewDepth != 1 && NewDepth != 4 && + NewDepth != 8 && NewDepth != 16 && + NewDepth != 24 && NewDepth != 32 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: User attempted to set unsupported bit depth " + << NewDepth << "." << endl + << " Bit depth remains unchanged at " + << BitDepth << "." << endl; + } + return false; + } + + BitDepth = NewDepth; + if( Colors ) + { delete [] Colors; } + int NumberOfColors = IntPow( 2, BitDepth ); + if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) + { Colors = new RGBApixel [NumberOfColors]; } + else + { Colors = NULL; } + if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) + { CreateStandardColorTable(); } + + return true; +} + +bool BMP::SetSize(int NewWidth , int NewHeight ) +{ + using namespace std; + if( NewWidth <= 0 || NewHeight <= 0 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: User attempted to set a non-positive width or height." << endl + << " Size remains unchanged at " + << Width << " x " << Height << "." << endl; + } + return false; + } + + int i,j; + + for(i=0;i<Width;i++) + { delete [] Pixels[i]; } + delete [] Pixels; + + Width = NewWidth; + Height = NewHeight; + Pixels = new RGBApixel* [ Width ]; + + for(i=0; i<Width; i++) + { Pixels[i] = new RGBApixel [ Height ]; } + + for( i=0 ; i < Width ; i++) + { + for( j=0 ; j < Height ; j++ ) + { + Pixels[i][j].Red = 255; + Pixels[i][j].Green = 255; + Pixels[i][j].Blue = 255; + Pixels[i][j].Alpha = 0; + } + } + + return true; +} + +bool BMP::WriteToFile( const char* FileName ) +{ + using namespace std; + if( !EasyBMPcheckDataSize() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Data types are wrong size!" << endl + << " You may need to mess with EasyBMP_DataTypes.h" << endl + << " to fix these errors, and then recompile." << endl + << " All 32-bit and 64-bit machines should be" << endl + << " supported, however." << endl << endl; + } + return false; + } + + FILE* fp = fopen( FileName, "wb" ); + if( fp == NULL ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Cannot open file " + << FileName << " for output." << endl; + } + fclose( fp ); + return false; + } + + // some preliminaries + + double dBytesPerPixel = ( (double) BitDepth ) / 8.0; + double dBytesPerRow = dBytesPerPixel * (Width+0.0); + dBytesPerRow = ceil(dBytesPerRow); + + int BytePaddingPerRow = 4 - ( (int) (dBytesPerRow) )% 4; + if( BytePaddingPerRow == 4 ) + { BytePaddingPerRow = 0; } + + double dActualBytesPerRow = dBytesPerRow + BytePaddingPerRow; + + double dTotalPixelBytes = Height * dActualBytesPerRow; + + double dPaletteSize = 0; + if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) + { dPaletteSize = IntPow(2,BitDepth)*4.0; } + + // leave some room for 16-bit masks + if( BitDepth == 16 ) + { dPaletteSize = 3*4; } + + double dTotalFileSize = 14 + 40 + dPaletteSize + dTotalPixelBytes; + + // write the file header + + BMFH bmfh; + bmfh.bfSize = (ebmpDWORD) dTotalFileSize; + bmfh.bfReserved1 = 0; + bmfh.bfReserved2 = 0; + bmfh.bfOffBits = (ebmpDWORD) (14+40+dPaletteSize); + + if( IsBigEndian() ) + { bmfh.SwitchEndianess(); } + + fwrite( (char*) &(bmfh.bfType) , sizeof(ebmpWORD) , 1 , fp ); + fwrite( (char*) &(bmfh.bfSize) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmfh.bfReserved1) , sizeof(ebmpWORD) , 1 , fp ); + fwrite( (char*) &(bmfh.bfReserved2) , sizeof(ebmpWORD) , 1 , fp ); + fwrite( (char*) &(bmfh.bfOffBits) , sizeof(ebmpDWORD) , 1 , fp ); + + // write the info header + + BMIH bmih; + bmih.biSize = 40; + bmih.biWidth = Width; + bmih.biHeight = Height; + bmih.biPlanes = 1; + bmih.biBitCount = BitDepth; + bmih.biCompression = 0; + bmih.biSizeImage = (ebmpDWORD) dTotalPixelBytes; + if( XPelsPerMeter ) + { bmih.biXPelsPerMeter = XPelsPerMeter; } + else + { bmih.biXPelsPerMeter = DefaultXPelsPerMeter; } + if( YPelsPerMeter ) + { bmih.biYPelsPerMeter = YPelsPerMeter; } + else + { bmih.biYPelsPerMeter = DefaultYPelsPerMeter; } + + bmih.biClrUsed = 0; + bmih.biClrImportant = 0; + + // indicates that we'll be using bit fields for 16-bit files + if( BitDepth == 16 ) + { bmih.biCompression = 3; } + + if( IsBigEndian() ) + { bmih.SwitchEndianess(); } + + fwrite( (char*) &(bmih.biSize) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biWidth) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biHeight) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biPlanes) , sizeof(ebmpWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biBitCount) , sizeof(ebmpWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biCompression) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biSizeImage) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biXPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biYPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp ); + fwrite( (char*) &(bmih.biClrUsed) , sizeof(ebmpDWORD) , 1 , fp); + fwrite( (char*) &(bmih.biClrImportant) , sizeof(ebmpDWORD) , 1 , fp); + + // write the palette + if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) + { + int NumberOfColors = IntPow(2,BitDepth); + + // if there is no palette, create one + if( !Colors ) + { + if( !Colors ) + { Colors = new RGBApixel [NumberOfColors]; } + CreateStandardColorTable(); + } + + int n; + for( n=0 ; n < NumberOfColors ; n++ ) + { fwrite( (char*) &(Colors[n]) , 4 , 1 , fp ); } + } + + // write the pixels + int i,j; + if( BitDepth != 16 ) + { + ebmpBYTE* Buffer; + int BufferSize = (int) ( (Width*BitDepth)/8.0 ); + while( 8*BufferSize < Width*BitDepth ) + { BufferSize++; } + while( BufferSize % 4 ) + { BufferSize++; } + + Buffer = new ebmpBYTE [BufferSize]; + for( j=0 ; j < BufferSize; j++ ) + { Buffer[j] = 0; } + + j=Height-1; + + while( j > -1 ) + { + bool Success = false; + if( BitDepth == 32 ) + { Success = Write32bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 24 ) + { Success = Write24bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 8 ) + { Success = Write8bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 4 ) + { Success = Write4bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 1 ) + { Success = Write1bitRow( Buffer, BufferSize, j ); } + if( Success ) + { + int BytesWritten = (int) fwrite( (char*) Buffer, 1, BufferSize, fp ); + if( BytesWritten != BufferSize ) + { Success = false; } + } + if( !Success ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Could not write proper amount of data." << endl; + } + j = -1; + } + j--; + } + + delete [] Buffer; + } + + if( BitDepth == 16 ) + { + // write the bit masks + + ebmpWORD BlueMask = 31; // bits 12-16 + ebmpWORD GreenMask = 2016; // bits 6-11 + ebmpWORD RedMask = 63488; // bits 1-5 + ebmpWORD ZeroWORD; + + if( IsBigEndian() ) + { RedMask = FlipWORD( RedMask ); } + fwrite( (char*) &RedMask , 2 , 1 , fp ); + fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); + + if( IsBigEndian() ) + { GreenMask = FlipWORD( GreenMask ); } + fwrite( (char*) &GreenMask , 2 , 1 , fp ); + fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); + + if( IsBigEndian() ) + { BlueMask = FlipWORD( BlueMask ); } + fwrite( (char*) &BlueMask , 2 , 1 , fp ); + fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); + + int DataBytes = Width*2; + int PaddingBytes = ( 4 - DataBytes % 4 ) % 4; + + // write the actual pixels + + for( j=Height-1 ; j >= 0 ; j-- ) + { + // write all row pixel data + i=0; + int WriteNumber = 0; + while( WriteNumber < DataBytes ) + { + ebmpWORD TempWORD; + + ebmpWORD RedWORD = (ebmpWORD) ((Pixels[i][j]).Red / 8); + ebmpWORD GreenWORD = (ebmpWORD) ((Pixels[i][j]).Green / 4); + ebmpWORD BlueWORD = (ebmpWORD) ((Pixels[i][j]).Blue / 8); + + TempWORD = (RedWORD<<11) + (GreenWORD<<5) + BlueWORD; + if( IsBigEndian() ) + { TempWORD = FlipWORD( TempWORD ); } + + fwrite( (char*) &TempWORD , 2, 1, fp); + WriteNumber += 2; + i++; + } + // write any necessary row padding + WriteNumber = 0; + while( WriteNumber < PaddingBytes ) + { + ebmpBYTE TempBYTE; + fwrite( (char*) &TempBYTE , 1, 1, fp); + WriteNumber++; + } + } + + } + + fclose(fp); + return true; +} + +bool BMP::ReadFromFile( const char* FileName ) +{ + using namespace std; + if( !EasyBMPcheckDataSize() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Data types are wrong size!" << endl + << " You may need to mess with EasyBMP_DataTypes.h" << endl + << " to fix these errors, and then recompile." << endl + << " All 32-bit and 64-bit machines should be" << endl + << " supported, however." << endl << endl; + } + return false; + } + + FILE* fp = fopen( FileName, "rb" ); + if( fp == NULL ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Cannot open file " + << FileName << " for input." << endl; + } + SetBitDepth(1); + SetSize(1,1); + return false; + } + + // read the file header + + BMFH bmfh; + bool NotCorrupted = true; + + NotCorrupted &= SafeFread( (char*) &(bmfh.bfType) , sizeof(ebmpWORD), 1, fp); + + bool IsBitmap = false; + + if( IsBigEndian() && bmfh.bfType == 16973 ) + { IsBitmap = true; } + if( !IsBigEndian() && bmfh.bfType == 19778 ) + { IsBitmap = true; } + + if( !IsBitmap ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName + << " is not a Windows BMP file!" << endl; + } + fclose( fp ); + return false; + } + + NotCorrupted &= SafeFread( (char*) &(bmfh.bfSize) , sizeof(ebmpDWORD) , 1, fp); + NotCorrupted &= SafeFread( (char*) &(bmfh.bfReserved1) , sizeof(ebmpWORD) , 1, fp); + NotCorrupted &= SafeFread( (char*) &(bmfh.bfReserved2) , sizeof(ebmpWORD) , 1, fp); + NotCorrupted &= SafeFread( (char*) &(bmfh.bfOffBits) , sizeof(ebmpDWORD) , 1 , fp); + + if( IsBigEndian() ) + { bmfh.SwitchEndianess(); } + + // read the info header + + BMIH bmih; + + NotCorrupted &= SafeFread( (char*) &(bmih.biSize) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biWidth) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biHeight) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biPlanes) , sizeof(ebmpWORD) , 1, fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biBitCount) , sizeof(ebmpWORD) , 1, fp); + + NotCorrupted &= SafeFread( (char*) &(bmih.biCompression) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biSizeImage) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biXPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biYPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biClrUsed) , sizeof(ebmpDWORD) , 1 , fp); + NotCorrupted &= SafeFread( (char*) &(bmih.biClrImportant) , sizeof(ebmpDWORD) , 1 , fp); + + if( IsBigEndian() ) + { bmih.SwitchEndianess(); } + + // a safety catch: if any of the header information didn't read properly, abort + // future idea: check to see if at least most is self-consistent + + if( !NotCorrupted ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName + << " is obviously corrupted." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + + XPelsPerMeter = bmih.biXPelsPerMeter; + YPelsPerMeter = bmih.biYPelsPerMeter; + + // if bmih.biCompression 1 or 2, then the file is RLE compressed + + if( bmih.biCompression == 1 || bmih.biCompression == 2 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName << " is (RLE) compressed." << endl + << " EasyBMP does not support compression." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + + // if bmih.biCompression > 3, then something strange is going on + // it's probably an OS2 bitmap file. + + if( bmih.biCompression > 3 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName << " is in an unsupported format." + << endl + << " (bmih.biCompression = " + << bmih.biCompression << ")" << endl + << " The file is probably an old OS2 bitmap or corrupted." + << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + + if( bmih.biCompression == 3 && bmih.biBitCount != 16 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName + << " uses bit fields and is not a" << endl + << " 16-bit file. This is not supported." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + + // set the bit depth + + int TempBitDepth = (int) bmih.biBitCount; + if( TempBitDepth != 1 && TempBitDepth != 4 + && TempBitDepth != 8 && TempBitDepth != 16 + && TempBitDepth != 24 && TempBitDepth != 32 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName << " has unrecognized bit depth." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + SetBitDepth( (int) bmih.biBitCount ); + + // set the size + + if( (int) bmih.biWidth <= 0 || (int) bmih.biHeight <= 0 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName + << " has a non-positive width or height." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + SetSize( (int) bmih.biWidth , (int) bmih.biHeight ); + + // some preliminaries + + double dBytesPerPixel = ( (double) BitDepth ) / 8.0; + double dBytesPerRow = dBytesPerPixel * (Width+0.0); + dBytesPerRow = ceil(dBytesPerRow); + + int BytePaddingPerRow = 4 - ( (int) (dBytesPerRow) )% 4; + if( BytePaddingPerRow == 4 ) + { BytePaddingPerRow = 0; } + + // if < 16 bits, read the palette + + if( BitDepth < 16 ) + { + // determine the number of colors specified in the + // color table + + int NumberOfColorsToRead = ((int) bmfh.bfOffBits - 54 )/4; + if( NumberOfColorsToRead > IntPow(2,BitDepth) ) + { NumberOfColorsToRead = IntPow(2,BitDepth); } + + if( NumberOfColorsToRead < TellNumberOfColors() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: file " << FileName << " has an underspecified" << endl + << " color table. The table will be padded with extra" << endl + << " white (255,255,255,0) entries." << endl; + } + } + + int n; + for( n=0; n < NumberOfColorsToRead ; n++ ) + { + SafeFread( (char*) &(Colors[n]) , 4 , 1 , fp); + } + for( n=NumberOfColorsToRead ; n < TellNumberOfColors() ; n++ ) + { + RGBApixel WHITE; + WHITE.Red = 255; + WHITE.Green = 255; + WHITE.Blue = 255; + WHITE.Alpha = 0; + SetColor( n , WHITE ); + } + + + } + + // skip blank data if bfOffBits so indicates + + int BytesToSkip = bmfh.bfOffBits - 54;; + if( BitDepth < 16 ) + { BytesToSkip -= 4*IntPow(2,BitDepth); } + if( BitDepth == 16 && bmih.biCompression == 3 ) + { BytesToSkip -= 3*4; } + if( BytesToSkip < 0 ) + { BytesToSkip = 0; } + if( BytesToSkip > 0 && BitDepth != 16 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Extra meta data detected in file " << FileName << endl + << " Data will be skipped." << endl; + } + ebmpBYTE* TempSkipBYTE; + TempSkipBYTE = new ebmpBYTE [BytesToSkip]; + SafeFread( (char*) TempSkipBYTE , BytesToSkip , 1 , fp); + delete [] TempSkipBYTE; + } + + // This code reads 1, 4, 8, 24, and 32-bpp files + // with a more-efficient buffered technique. + + int i,j; + if( BitDepth != 16 ) + { + int BufferSize = (int) ( (Width*BitDepth) / 8.0 ); + while( 8*BufferSize < Width*BitDepth ) + { BufferSize++; } + while( BufferSize % 4 ) + { BufferSize++; } + ebmpBYTE* Buffer; + Buffer = new ebmpBYTE [BufferSize]; + j= Height-1; + while( j > -1 ) + { + int BytesRead = (int) fread( (char*) Buffer, 1, BufferSize, fp ); + if( BytesRead < BufferSize ) + { + j = -1; + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Could not read proper amount of data." << endl; + } + } + else + { + bool Success = false; + if( BitDepth == 1 ) + { Success = Read1bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 4 ) + { Success = Read4bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 8 ) + { Success = Read8bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 24 ) + { Success = Read24bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 32 ) + { Success = Read32bitRow( Buffer, BufferSize, j ); } + if( !Success ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Could not read enough pixel data!" << endl; + } + j = -1; + } + } + j--; + } + delete [] Buffer; + } + + if( BitDepth == 16 ) + { + int DataBytes = Width*2; + int PaddingBytes = ( 4 - DataBytes % 4 ) % 4; + + // set the default mask + + ebmpWORD BlueMask = 31; // bits 12-16 + ebmpWORD GreenMask = 992; // bits 7-11 + ebmpWORD RedMask = 31744; // bits 2-6 + + // read the bit fields, if necessary, to + // override the default 5-5-5 mask + + if( bmih.biCompression != 0 ) + { + // read the three bit masks + + ebmpWORD TempMaskWORD; + ebmpWORD ZeroWORD; + + SafeFread( (char*) &RedMask , 2 , 1 , fp ); + if( IsBigEndian() ) + { RedMask = FlipWORD(RedMask); } + SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); + + SafeFread( (char*) &GreenMask , 2 , 1 , fp ); + if( IsBigEndian() ) + { GreenMask = FlipWORD(GreenMask); } + SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); + + SafeFread( (char*) &BlueMask , 2 , 1 , fp ); + if( IsBigEndian() ) + { BlueMask = FlipWORD(BlueMask); } + SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); + } + + // read and skip any meta data + + if( BytesToSkip > 0 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Extra meta data detected in file " + << FileName << endl + << " Data will be skipped." << endl; + } + ebmpBYTE* TempSkipBYTE; + TempSkipBYTE = new ebmpBYTE [BytesToSkip]; + SafeFread( (char*) TempSkipBYTE , BytesToSkip , 1 , fp); + delete [] TempSkipBYTE; + } + + // determine the red, green and blue shifts + + int GreenShift = 0; + ebmpWORD TempShiftWORD = GreenMask; + while( TempShiftWORD > 31 ) + { TempShiftWORD = TempShiftWORD>>1; GreenShift++; } + int BlueShift = 0; + TempShiftWORD = BlueMask; + while( TempShiftWORD > 31 ) + { TempShiftWORD = TempShiftWORD>>1; BlueShift++; } + int RedShift = 0; + TempShiftWORD = RedMask; + while( TempShiftWORD > 31 ) + { TempShiftWORD = TempShiftWORD>>1; RedShift++; } + + // read the actual pixels + + for( j=Height-1 ; j >= 0 ; j-- ) + { + i=0; + int ReadNumber = 0; + while( ReadNumber < DataBytes ) + { + ebmpWORD TempWORD; + SafeFread( (char*) &TempWORD , 2 , 1 , fp ); + if( IsBigEndian() ) + { TempWORD = FlipWORD(TempWORD); } + ReadNumber += 2; + + ebmpWORD Red = RedMask & TempWORD; + ebmpWORD Green = GreenMask & TempWORD; + ebmpWORD Blue = BlueMask & TempWORD; + + ebmpBYTE BlueBYTE = (ebmpBYTE) 8*(Blue>>BlueShift); + ebmpBYTE GreenBYTE = (ebmpBYTE) 8*(Green>>GreenShift); + ebmpBYTE RedBYTE = (ebmpBYTE) 8*(Red>>RedShift); + + (Pixels[i][j]).Red = RedBYTE; + (Pixels[i][j]).Green = GreenBYTE; + (Pixels[i][j]).Blue = BlueBYTE; + + i++; + } + ReadNumber = 0; + while( ReadNumber < PaddingBytes ) + { + ebmpBYTE TempBYTE; + SafeFread( (char*) &TempBYTE , 1, 1, fp); + ReadNumber++; + } + } + + } + + fclose(fp); + return true; +} + +bool BMP::CreateStandardColorTable( void ) +{ + using namespace std; + if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to create color table at a bit" << endl + << " depth that does not require a color table." << endl + << " Ignoring request." << endl; + } + return false; + } + + if( BitDepth == 1 ) + { + int i; + for( i=0 ; i < 2 ; i++ ) + { + Colors[i].Red = i*255; + Colors[i].Green = i*255; + Colors[i].Blue = i*255; + Colors[i].Alpha = 0; + } + return true; + } + + if( BitDepth == 4 ) + { + int i = 0; + int j,k,ell; + + // simplify the code for the first 8 colors + for( ell=0 ; ell < 2 ; ell++ ) + { + for( k=0 ; k < 2 ; k++ ) + { + for( j=0 ; j < 2 ; j++ ) + { + Colors[i].Red = j*128; + Colors[i].Green = k*128; + Colors[i].Blue = ell*128; + i++; + } + } + } + + // simplify the code for the last 8 colors + for( ell=0 ; ell < 2 ; ell++ ) + { + for( k=0 ; k < 2 ; k++ ) + { + for( j=0 ; j < 2 ; j++ ) + { + Colors[i].Red = j*255; + Colors[i].Green = k*255; + Colors[i].Blue = ell*255; + i++; + } + } + } + + // overwrite the duplicate color + i=8; + Colors[i].Red = 192; + Colors[i].Green = 192; + Colors[i].Blue = 192; + + for( i=0 ; i < 16 ; i++ ) + { Colors[i].Alpha = 0; } + return true; + } + + if( BitDepth == 8 ) + { + int i=0; + int j,k,ell; + + // do an easy loop, which works for all but colors + // 0 to 9 and 246 to 255 + for( ell=0 ; ell < 4 ; ell++ ) + { + for( k=0 ; k < 8 ; k++ ) + { + for( j=0; j < 8 ; j++ ) + { + Colors[i].Red = j*32; + Colors[i].Green = k*32; + Colors[i].Blue = ell*64; + Colors[i].Alpha = 0; + i++; + } + } + } + + // now redo the first 8 colors + i=0; + for( ell=0 ; ell < 2 ; ell++ ) + { + for( k=0 ; k < 2 ; k++ ) + { + for( j=0; j < 2 ; j++ ) + { + Colors[i].Red = j*128; + Colors[i].Green = k*128; + Colors[i].Blue = ell*128; + i++; + } + } + } + + // overwrite colors 7, 8, 9 + i=7; + Colors[i].Red = 192; + Colors[i].Green = 192; + Colors[i].Blue = 192; + i++; // 8 + Colors[i].Red = 192; + Colors[i].Green = 220; + Colors[i].Blue = 192; + i++; // 9 + Colors[i].Red = 166; + Colors[i].Green = 202; + Colors[i].Blue = 240; + + // overwrite colors 246 to 255 + i=246; + Colors[i].Red = 255; + Colors[i].Green = 251; + Colors[i].Blue = 240; + i++; // 247 + Colors[i].Red = 160; + Colors[i].Green = 160; + Colors[i].Blue = 164; + i++; // 248 + Colors[i].Red = 128; + Colors[i].Green = 128; + Colors[i].Blue = 128; + i++; // 249 + Colors[i].Red = 255; + Colors[i].Green = 0; + Colors[i].Blue = 0; + i++; // 250 + Colors[i].Red = 0; + Colors[i].Green = 255; + Colors[i].Blue = 0; + i++; // 251 + Colors[i].Red = 255; + Colors[i].Green = 255; + Colors[i].Blue = 0; + i++; // 252 + Colors[i].Red = 0; + Colors[i].Green = 0; + Colors[i].Blue = 255; + i++; // 253 + Colors[i].Red = 255; + Colors[i].Green = 0; + Colors[i].Blue = 255; + i++; // 254 + Colors[i].Red = 0; + Colors[i].Green = 255; + Colors[i].Blue = 255; + i++; // 255 + Colors[i].Red = 255; + Colors[i].Green = 255; + Colors[i].Blue = 255; + + return true; + } + return true; +} + +bool SafeFread( char* buffer, int size, int number, FILE* fp ) +{ + using namespace std; + int ItemsRead; + if( feof(fp) ) + { return false; } + ItemsRead = (int) fread( buffer , size , number , fp ); + if( ItemsRead < number ) + { return false; } + return true; +} + +void BMP::SetDPI( int HorizontalDPI, int VerticalDPI ) +{ + XPelsPerMeter = (int) ( HorizontalDPI * 39.37007874015748 ); + YPelsPerMeter = (int) ( VerticalDPI * 39.37007874015748 ); +} + +// int BMP::TellVerticalDPI( void ) const +int BMP::TellVerticalDPI( void ) +{ + if( !YPelsPerMeter ) + { YPelsPerMeter = DefaultYPelsPerMeter; } + return (int) ( YPelsPerMeter / (double) 39.37007874015748 ); +} + +// int BMP::TellHorizontalDPI( void ) const +int BMP::TellHorizontalDPI( void ) +{ + if( !XPelsPerMeter ) + { XPelsPerMeter = DefaultXPelsPerMeter; } + return (int) ( XPelsPerMeter / (double) 39.37007874015748 ); +} + +/* These functions are defined in EasyBMP_VariousBMPutilities.h */ + +BMFH GetBMFH( const char* szFileNameIn ) +{ + using namespace std; + BMFH bmfh; + + FILE* fp; + fp = fopen( szFileNameIn,"rb"); + + if( !fp ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Cannot initialize from file " + << szFileNameIn << "." << endl + << " File cannot be opened or does not exist." + << endl; + } + bmfh.bfType = 0; + return bmfh; + } + + SafeFread( (char*) &(bmfh.bfType) , sizeof(ebmpWORD) , 1 , fp ); + SafeFread( (char*) &(bmfh.bfSize) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmfh.bfReserved1) , sizeof(ebmpWORD) , 1 , fp ); + SafeFread( (char*) &(bmfh.bfReserved2) , sizeof(ebmpWORD) , 1 , fp ); + SafeFread( (char*) &(bmfh.bfOffBits) , sizeof(ebmpDWORD) , 1 , fp ); + + fclose( fp ); + + if( IsBigEndian() ) + { bmfh.SwitchEndianess(); } + + return bmfh; +} + +BMIH GetBMIH( const char* szFileNameIn ) +{ + using namespace std; + BMFH bmfh; + BMIH bmih; + + FILE* fp; + fp = fopen( szFileNameIn,"rb"); + + if( !fp ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Cannot initialize from file " + << szFileNameIn << "." << endl + << " File cannot be opened or does not exist." + << endl; + } + return bmih; + } + + // read the bmfh, i.e., first 14 bytes (just to get it out of the way); + + ebmpBYTE TempBYTE; + int i; + for( i = 14 ; i > 0 ; i-- ) + { SafeFread( (char*) &TempBYTE , sizeof(ebmpBYTE) , 1, fp ); } + + // read the bmih + + SafeFread( (char*) &(bmih.biSize) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biWidth) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biHeight) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biPlanes) , sizeof(ebmpWORD) , 1 , fp ); + + SafeFread( (char*) &(bmih.biBitCount) , sizeof(ebmpWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biCompression) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biSizeImage) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biXPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp ); + + SafeFread( (char*) &(bmih.biYPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biClrUsed) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biClrImportant) , sizeof(ebmpDWORD) , 1 , fp ); + + fclose( fp ); + + if( IsBigEndian() ) + { bmih.SwitchEndianess(); } + + return bmih; +} + +void DisplayBitmapInfo( const char* szFileNameIn ) +{ + using namespace std; + FILE* fp; + fp = fopen( szFileNameIn,"rb"); + + if( !fp ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Cannot initialize from file " + << szFileNameIn << "." << endl + << " File cannot be opened or does not exist." + << endl; + } + return; + } + fclose( fp ); + + // don't duplicate work! Just use the functions from above! + + BMFH bmfh = GetBMFH(szFileNameIn); + BMIH bmih = GetBMIH(szFileNameIn); + + cout << "File information for file " << szFileNameIn + << ":" << endl << endl; + + cout << "BITMAPFILEHEADER:" << endl + << "bfType: " << bmfh.bfType << endl + << "bfSize: " << bmfh.bfSize << endl + << "bfReserved1: " << bmfh.bfReserved1 << endl + << "bfReserved2: " << bmfh.bfReserved2 << endl + << "bfOffBits: " << bmfh.bfOffBits << endl << endl; + + cout << "BITMAPINFOHEADER:" << endl + << "biSize: " << bmih.biSize << endl + << "biWidth: " << bmih.biWidth << endl + << "biHeight: " << bmih.biHeight << endl + << "biPlanes: " << bmih.biPlanes << endl + << "biBitCount: " << bmih.biBitCount << endl + << "biCompression: " << bmih.biCompression << endl + << "biSizeImage: " << bmih.biSizeImage << endl + << "biXPelsPerMeter: " << bmih.biXPelsPerMeter << endl + << "biYPelsPerMeter: " << bmih.biYPelsPerMeter << endl + << "biClrUsed: " << bmih.biClrUsed << endl + << "biClrImportant: " << bmih.biClrImportant << endl << endl; + return; +} + +int GetBitmapColorDepth( const char* szFileNameIn ) +{ + BMIH bmih = GetBMIH( szFileNameIn ); + return (int) bmih.biBitCount; +} + +void PixelToPixelCopy( BMP& From, int FromX, int FromY, + BMP& To, int ToX, int ToY) +{ + *To(ToX,ToY) = *From(FromX,FromY); + return; +} + +void PixelToPixelCopyTransparent( BMP& From, int FromX, int FromY, + BMP& To, int ToX, int ToY, + RGBApixel& Transparent ) +{ + if( From(FromX,FromY)->Red != Transparent.Red || + From(FromX,FromY)->Green != Transparent.Green || + From(FromX,FromY)->Blue != Transparent.Blue ) + { *To(ToX,ToY) = *From(FromX,FromY); } + return; +} + +void RangedPixelToPixelCopy( BMP& From, int FromL , int FromR, int FromB, int FromT, + BMP& To, int ToX, int ToY ) +{ + // make sure the conventions are followed + if( FromB < FromT ) + { int Temp = FromT; FromT = FromB; FromB = Temp; } + + // make sure that the copied regions exist in both bitmaps + if( FromR >= From.TellWidth() ) + { FromR = From.TellWidth()-1; } + if( FromL < 0 ){ FromL = 0; } + + if( FromB >= From.TellHeight() ) + { FromB = From.TellHeight()-1; } + if( FromT < 0 ){ FromT = 0; } + + if( ToX+(FromR-FromL) >= To.TellWidth() ) + { FromR = To.TellWidth()-1+FromL-ToX; } + if( ToY+(FromB-FromT) >= To.TellHeight() ) + { FromB = To.TellHeight()-1+FromT-ToY; } + + int i,j; + for( j=FromT ; j <= FromB ; j++ ) + { + for( i=FromL ; i <= FromR ; i++ ) + { + PixelToPixelCopy( From, i,j, + To, ToX+(i-FromL), ToY+(j-FromT) ); + } + } + + return; +} + +void RangedPixelToPixelCopyTransparent( + BMP& From, int FromL , int FromR, int FromB, int FromT, + BMP& To, int ToX, int ToY , + RGBApixel& Transparent ) +{ + // make sure the conventions are followed + if( FromB < FromT ) + { int Temp = FromT; FromT = FromB; FromB = Temp; } + + // make sure that the copied regions exist in both bitmaps + if( FromR >= From.TellWidth() ) + { FromR = From.TellWidth()-1; } + if( FromL < 0 ){ FromL = 0; } + + if( FromB >= From.TellHeight() ) + { FromB = From.TellHeight()-1; } + if( FromT < 0 ){ FromT = 0; } + + if( ToX+(FromR-FromL) >= To.TellWidth() ) + { FromR = To.TellWidth()-1+FromL-ToX; } + if( ToY+(FromB-FromT) >= To.TellHeight() ) + { FromB = To.TellHeight()-1+FromT-ToY; } + + int i,j; + for( j=FromT ; j <= FromB ; j++ ) + { + for( i=FromL ; i <= FromR ; i++ ) + { + PixelToPixelCopyTransparent( From, i,j, + To, ToX+(i-FromL), ToY+(j-FromT) , + Transparent); + } + } + + return; +} + +bool CreateGrayscaleColorTable( BMP& InputImage ) +{ + using namespace std; + int BitDepth = InputImage.TellBitDepth(); + if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to create color table at a bit" << endl + << " depth that does not require a color table." << endl + << " Ignoring request." << endl; + } + return false; + } + int i; + int NumberOfColors = InputImage.TellNumberOfColors(); + + ebmpBYTE StepSize; + if( BitDepth != 1 ) + { StepSize = 255/(NumberOfColors-1); } + else + { StepSize = 255; } + + for( i=0 ; i < NumberOfColors ; i++ ) + { + ebmpBYTE TempBYTE = i*StepSize; + RGBApixel TempColor; + TempColor.Red = TempBYTE; + TempColor.Green = TempBYTE; + TempColor.Blue = TempBYTE; + TempColor.Alpha = 0; + InputImage.SetColor( i , TempColor ); + } + return true; +} + +bool BMP::Read32bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width*4 > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { memcpy( (char*) &(Pixels[i][Row]), (char*) Buffer+4*i, 4 ); } + return true; +} + +bool BMP::Read24bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width*3 > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { memcpy( (char*) &(Pixels[i][Row]), Buffer+3*i, 3 ); } + return true; +} + +bool BMP::Read8bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { + int Index = Buffer[i]; + *( this->operator()(i,Row) )= GetColor(Index); + } + return true; +} + +bool BMP::Read4bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int Shifts[2] = {4 ,0 }; + int Masks[2] = {240,15}; + + int i=0; + int j; + int k=0; + if( Width > 2*BufferSize ) + { return false; } + while( i < Width ) + { + j=0; + while( j < 2 && i < Width ) + { + int Index = (int) ( (Buffer[k]&Masks[j]) >> Shifts[j]); + *( this->operator()(i,Row) )= GetColor(Index); + i++; j++; + } + k++; + } + return true; +} +bool BMP::Read1bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int Shifts[8] = {7 ,6 ,5 ,4 ,3,2,1,0}; + int Masks[8] = {128,64,32,16,8,4,2,1}; + + int i=0; + int j; + int k=0; + + if( Width > 8*BufferSize ) + { return false; } + while( i < Width ) + { + j=0; + while( j < 8 && i < Width ) + { + int Index = (int) ( (Buffer[k]&Masks[j]) >> Shifts[j]); + *( this->operator()(i,Row) )= GetColor(Index); + i++; j++; + } + k++; + } + return true; +} + +bool BMP::Write32bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width*4 > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { memcpy( (char*) Buffer+4*i, (char*) &(Pixels[i][Row]), 4 ); } + return true; +} + +bool BMP::Write24bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width*3 > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { memcpy( (char*) Buffer+3*i, (char*) &(Pixels[i][Row]), 3 ); } + return true; +} + +bool BMP::Write8bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { Buffer[i] = FindClosestColor( Pixels[i][Row] ); } + return true; +} + +bool BMP::Write4bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int PositionWeights[2] = {16,1}; + + int i=0; + int j; + int k=0; + if( Width > 2*BufferSize ) + { return false; } + while( i < Width ) + { + j=0; + int Index = 0; + while( j < 2 && i < Width ) + { + Index += ( PositionWeights[j]* (int) FindClosestColor( Pixels[i][Row] ) ); + i++; j++; + } + Buffer[k] = (ebmpBYTE) Index; + k++; + } + return true; +} + +bool BMP::Write1bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int PositionWeights[8] = {128,64,32,16,8,4,2,1}; + + int i=0; + int j; + int k=0; + if( Width > 8*BufferSize ) + { return false; } + while( i < Width ) + { + j=0; + int Index = 0; + while( j < 8 && i < Width ) + { + Index += ( PositionWeights[j]* (int) FindClosestColor( Pixels[i][Row] ) ); + i++; j++; + } + Buffer[k] = (ebmpBYTE) Index; + k++; + } + return true; +} + +ebmpBYTE BMP::FindClosestColor( RGBApixel& input ) +{ + using namespace std; + + int i=0; + int NumberOfColors = TellNumberOfColors(); + ebmpBYTE BestI = 0; + int BestMatch = 999999; + + while( i < NumberOfColors ) + { + RGBApixel Attempt = GetColor( i ); + int TempMatch = IntSquare( (int) Attempt.Red - (int) input.Red ) + + IntSquare( (int) Attempt.Green - (int) input.Green ) + + IntSquare( (int) Attempt.Blue - (int) input.Blue ); + if( TempMatch < BestMatch ) + { BestI = (ebmpBYTE) i; BestMatch = TempMatch; } + if( BestMatch < 1 ) + { i = NumberOfColors; } + i++; + } + return BestI; +} + +bool EasyBMPcheckDataSize( void ) +{ + using namespace std; + bool ReturnValue = true; + if( sizeof( ebmpBYTE ) != 1 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: ebmpBYTE has the wrong size (" + << sizeof( ebmpBYTE ) << " bytes)," << endl + << " Compared to the expected 1 byte value" << endl; + } + ReturnValue = false; + } + if( sizeof( ebmpWORD ) != 2 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: ebmpWORD has the wrong size (" + << sizeof( ebmpWORD ) << " bytes)," << endl + << " Compared to the expected 2 byte value" << endl; + } + ReturnValue = false; + } + if( sizeof( ebmpDWORD ) != 4 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: ebmpDWORD has the wrong size (" + << sizeof( ebmpDWORD ) << " bytes)," << endl + << " Compared to the expected 4 byte value" << endl; + } + ReturnValue = false; + } + return ReturnValue; +} + +bool Rescale( BMP& InputImage , char mode, int NewDimension ) +{ + using namespace std; + int CapMode = toupper( mode ); + + BMP OldImage( InputImage ); + + if( CapMode != 'P' && + CapMode != 'W' && + CapMode != 'H' && + CapMode != 'F' ) + { + if( EasyBMPwarnings ) + { + char ErrorMessage [1024]; + sprintf( ErrorMessage, "EasyBMP Error: Unknown rescale mode %c requested\n" , mode ); + cout << ErrorMessage; + } + return false; + } + + int NewWidth =0; + int NewHeight =0; + + int OldWidth = OldImage.TellWidth(); + int OldHeight= OldImage.TellHeight(); + + if( CapMode == 'P' ) + { + NewWidth = (int) floor( OldWidth * NewDimension / 100.0 ); + NewHeight = (int) floor( OldHeight * NewDimension / 100.0 ); + } + if( CapMode == 'F' ) + { + if( OldWidth > OldHeight ) + { CapMode = 'W'; } + else + { CapMode = 'H'; } + } + + if( CapMode == 'W' ) + { + double percent = (double) NewDimension / (double) OldWidth; + NewWidth = NewDimension; + NewHeight = (int) floor( OldHeight * percent ); + } + if( CapMode == 'H' ) + { + double percent = (double) NewDimension / (double) OldHeight; + NewHeight = NewDimension; + NewWidth = (int) floor( OldWidth * percent ); + } + + if( NewWidth < 1 ) + { NewWidth = 1; } + if( NewHeight < 1 ) + { NewHeight = 1; } + + InputImage.SetSize( NewWidth, NewHeight ); + InputImage.SetBitDepth( 24 ); + + int I,J; + double ThetaI,ThetaJ; + + for( int j=0; j < NewHeight-1 ; j++ ) + { + ThetaJ = (double)(j*(OldHeight-1.0)) + /(double)(NewHeight-1.0); + J = (int) floor( ThetaJ ); + ThetaJ -= J; + + for( int i=0; i < NewWidth-1 ; i++ ) + { + ThetaI = (double)(i*(OldWidth-1.0)) + /(double)(NewWidth-1.0); + I = (int) floor( ThetaI ); + ThetaI -= I; + + InputImage(i,j)->Red = (ebmpBYTE) + ( (1.0-ThetaI-ThetaJ+ThetaI*ThetaJ)*(OldImage(I,J)->Red) + +(ThetaI-ThetaI*ThetaJ)*(OldImage(I+1,J)->Red) + +(ThetaJ-ThetaI*ThetaJ)*(OldImage(I,J+1)->Red) + +(ThetaI*ThetaJ)*(OldImage(I+1,J+1)->Red) ); + InputImage(i,j)->Green = (ebmpBYTE) + ( (1.0-ThetaI-ThetaJ+ThetaI*ThetaJ)*OldImage(I,J)->Green + +(ThetaI-ThetaI*ThetaJ)*OldImage(I+1,J)->Green + +(ThetaJ-ThetaI*ThetaJ)*OldImage(I,J+1)->Green + +(ThetaI*ThetaJ)*OldImage(I+1,J+1)->Green ); + InputImage(i,j)->Blue = (ebmpBYTE) + ( (1.0-ThetaI-ThetaJ+ThetaI*ThetaJ)*OldImage(I,J)->Blue + +(ThetaI-ThetaI*ThetaJ)*OldImage(I+1,J)->Blue + +(ThetaJ-ThetaI*ThetaJ)*OldImage(I,J+1)->Blue + +(ThetaI*ThetaJ)*OldImage(I+1,J+1)->Blue ); + } + InputImage(NewWidth-1,j)->Red = (ebmpBYTE) + ( (1.0-ThetaJ)*(OldImage(OldWidth-1,J)->Red) + + ThetaJ*(OldImage(OldWidth-1,J+1)->Red) ); + InputImage(NewWidth-1,j)->Green = (ebmpBYTE) + ( (1.0-ThetaJ)*(OldImage(OldWidth-1,J)->Green) + + ThetaJ*(OldImage(OldWidth-1,J+1)->Green) ); + InputImage(NewWidth-1,j)->Blue = (ebmpBYTE) + ( (1.0-ThetaJ)*(OldImage(OldWidth-1,J)->Blue) + + ThetaJ*(OldImage(OldWidth-1,J+1)->Blue) ); + } + + for( int i=0 ; i < NewWidth-1 ; i++ ) + { + ThetaI = (double)(i*(OldWidth-1.0)) + /(double)(NewWidth-1.0); + I = (int) floor( ThetaI ); + ThetaI -= I; + InputImage(i,NewHeight-1)->Red = (ebmpBYTE) + ( (1.0-ThetaI)*(OldImage(I,OldHeight-1)->Red) + + ThetaI*(OldImage(I,OldHeight-1)->Red) ); + InputImage(i,NewHeight-1)->Green = (ebmpBYTE) + ( (1.0-ThetaI)*(OldImage(I,OldHeight-1)->Green) + + ThetaI*(OldImage(I,OldHeight-1)->Green) ); + InputImage(i,NewHeight-1)->Blue = (ebmpBYTE) + ( (1.0-ThetaI)*(OldImage(I,OldHeight-1)->Blue) + + ThetaI*(OldImage(I,OldHeight-1)->Blue) ); + } + + *InputImage(NewWidth-1,NewHeight-1) = *OldImage(OldWidth-1,OldHeight-1); + return true; +} Added: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.h =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.h (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP.h 2008-12-31 13:21:01 UTC (rev 1516) @@ -0,0 +1,86 @@ +/************************************************* +* * +* EasyBMP Cross-Platform Windows Bitmap Library * +* * +* Author: Paul Macklin * +* email: mac...@us... * +* support: http://easybmp.sourceforge.net * +* * +* file: EasyBMP.h * +* date added: 01-31-2005 * +* date modified: 12-01-2006 * +* version: 1.06 * +* * +* License: BSD (revised/modified) * +* Copyright: 2005-6 by the EasyBMP Project * +* * +* description: Main include file * +* * +*************************************************/ + +#ifdef _MSC_VER +// MS Visual Studio gives warnings when using +// fopen. But fopen_s is not going to work well +// with most compilers, and fopen_s uses different +// syntax than fopen. (i.e., a macro won't work) +// So, we'lll use this: +#define _CRT_SECURE_NO_DEPRECATE +#endif + +#include <iostream> +#include <cmath> +#include <cctype> +#include <cstring> + +#ifndef EasyBMP +#define EasyBMP + +#ifdef __BCPLUSPLUS__ +// The Borland compiler must use this because something +// is wrong with their cstdio file. +#include <stdio.h> +#else +#include <cstdio> +#endif + +#ifdef __GNUC__ +// If g++ specific code is ever required, this is +// where it goes. +#endif + +#ifdef __INTEL_COMPILER +// If Intel specific code is ever required, this is +// where it goes. +#endif + +#ifndef _DefaultXPelsPerMeter_ +#define _DefaultXPelsPerMeter_ +#define DefaultXPelsPerMeter 3780 +// set to a default of 96 dpi +#endif + +#ifndef _DefaultYPelsPerMeter_ +#define _DefaultYPelsPerMeter_ +#define DefaultYPelsPerMeter 3780 +// set to a default of 96 dpi +#endif + +#include "EasyBMP_DataStructures.h" +#include "EasyBMP_BMP.h" +#include "EasyBMP_VariousBMPutilities.h" + +#ifndef _EasyBMP_Version_ +#define _EasyBMP_Version_ 1.06 +#define _EasyBMP_Version_Integer_ 106 +#define _EasyBMP_Version_String_ "1.06" +#endif + +#ifndef _EasyBMPwarnings_ +#define _EasyBMPwarnings_ +#endif + +void SetEasyBMPwarningsOff( void ); +void SetEasyBMPwarningsOn( void ); +bool GetEasyBMPwarningState( void ); + +#endif Added: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_BMP.h =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_BMP.h (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_BMP.h 2008-12-31 13:21:01 UTC (rev 1516) @@ -0,0 +1,86 @@ +/************************************************* +* * +* EasyBMP Cross-Platform Windows Bitmap Library * +* * +* Author: Paul Macklin * +* email: mac...@us... * +* support: http://easybmp.sourceforge.net * +* * +* file: EasyBMP_VariousBMPutilities.h * +* date added: 05-02-2005 * +* date modified: 12-01-2006 * +* version: 1.06 * +* * +* License: BSD (revised/modified) * +* Copyright: 2005-6 by the EasyBMP Project * +* * +* description: Defines BMP class * +* * +*************************************************/ + +#ifndef _EasyBMP_BMP_h_ +#define _EasyBMP_BMP_h_ + +bool SafeFread( char* buffer, int size, int number, FILE* fp ); +bool EasyBMPcheckDataSize( void ); + +class __declspec(dllexport) BMP{ +private: + + int BitDepth; + int Width; + int Height; + RGBApixel** Pixels; + RGBApixel* Colors; + int XPelsPerMeter; + int YPelsPerMeter; + + ebmpBYTE* MetaData1; + int SizeOfMetaData1; + ebmpBYTE* MetaData2; + int SizeOfMetaData2; + + bool Read32bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Read24bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Read8bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Read4bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Read1bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + + bool Write32bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Write24bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Write8bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Write4bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Write1bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + + ebmpBYTE FindClosestColor( RGBApixel& input ); + +public: + + int TellBitDepth( void ); + int TellWidth( void ); + int TellHeight( void ); + int TellNumberOfColors( void ); + void SetDPI( int HorizontalDPI, int VerticalDPI ); + int TellVerticalDPI( void ); + int TellHorizontalDPI( void ); + + BMP(); + BMP( BMP& Input ); + ~BMP(); + RGBApixel* operator()(int i,int j); + + RGBApixel GetPixel( int i, int j ) const; + bool SetPixel( int i, int j, RGBApixel NewPixel ); + + bool CreateStandardColorTable( void ); + + bool SetSize( int NewWidth, int NewHeight ); + bool SetBitDepth( int NewDepth ); + bool WriteToFile( const char* FileName ); + bool ReadFromFile( const char* FileName ); + + RGBApixel GetColor( int ColorNumber ); + bool SetColor( int ColorNumber, RGBApixel NewColor ); +}; + +#endif Added: pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_ChangeLog.txt =================================================================== --- pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_ChangeLog.txt (rev 0) +++ pyplusplus_dev/examples/pyeasybmp_dev/easybmp/EasyBMP_ChangeLog.txt 2008-12-31 13:21:01 UTC (rev 1516) @@ -0,0 +1,821 @@ +EasyBMP Cross-Platform Windows Bitmap Library: Change Log + +Library Author(s): Paul Macklin + Library License: BSD (revised). See the BSD_(revised)_license.txt + file for further information. + Copyright: 2005-6 by the EasyBMP Project + Email: ... [truncated message content] |
From: <rom...@us...> - 2008-12-30 11:27:04
|
Revision: 1515 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1515&view=rev Author: roman_yakovenko Date: 2008-12-30 11:27:00 +0000 (Tue, 30 Dec 2008) Log Message: ----------- another set of changes for ctypes code generator Modified Paths: -------------- pygccxml_dev/unittests/autoconfig.py pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/compound.py pyplusplus_dev/pyplusplus/code_creators/function_definition.py pyplusplus_dev/pyplusplus/code_creators/methods_definition.py pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py pyplusplus_dev/unittests/autoconfig.py pyplusplus_dev/unittests/ctypes_pof_tester.py Modified: pygccxml_dev/unittests/autoconfig.py =================================================================== --- pygccxml_dev/unittests/autoconfig.py 2008-12-29 22:22:45 UTC (rev 1514) +++ pygccxml_dev/unittests/autoconfig.py 2008-12-30 11:27:00 UTC (rev 1515) @@ -28,7 +28,7 @@ print 'unittests will run on DEVELOPMENT version' compiler = pygccxml.utils.native_compiler.get_gccxml_compiler() - +compiler = 'msvc71' print 'GCCXML configured to simulate compiler ', compiler pygccxml.declarations.class_t.USE_DEMANGLED_AS_NAME = True Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-29 22:22:45 UTC (rev 1514) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-30 11:27:00 UTC (rev 1515) @@ -155,12 +155,11 @@ from mem_fun_introduction import vmem_fun_introduction_t from mem_fun_introduction import init_introduction_t from mem_fun_introduction import del_introduction_t - - from fields_definition import fields_definition_t from embedded_code_repository import embedded_code_repository_t from methods_definition import methods_definition_t from function_definition import function_definition_t from function_definition import init_definition_t -from function_definition import multi_init_definition_t +from function_definition import multi_method_definition_t from function_definition import del_definition_t +from function_definition import mem_fun_definition_t Modified: pyplusplus_dev/pyplusplus/code_creators/compound.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/compound.py 2008-12-29 22:22:45 UTC (rev 1514) +++ pyplusplus_dev/pyplusplus/code_creators/compound.py 2008-12-30 11:27:00 UTC (rev 1515) @@ -87,3 +87,18 @@ if unique: files = self.unique_headers( files ) return files + + def find_by_creator_class( self, class_, unique=True, recursive=False ): + #I will add missing functionality later + assert recursive == False + found = filter( lambda cc: isinstance( cc, class_ ), self.creators ) + if not found: + return None + elif 1 == len( found ): + return found + else: + if unique: + raise LookupError( "Too many creators(%d) of type %s were found." + % ( len( found ), class_.__name__ ) ) + else: + return found Modified: pyplusplus_dev/pyplusplus/code_creators/function_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-29 22:22:45 UTC (rev 1514) +++ pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-30 11:27:00 UTC (rev 1515) @@ -12,105 +12,166 @@ #TODO - unable to call C function, if dll was loaded as CPPDLL -def join_arguments( args ): - args_str = '' - arg_separator = ', ' - if 1 == len( args ): - args_str = ' ' + args[0] + ' ' - else: - args_str = ' ' + arg_separator.join( args ) + ' ' - return '[%s]' % args_str -class function_definition_t(code_creator.code_creator_t, declaration_based.declaration_based_t): - def __init__( self, free_fun ): +class METHOD_MODE: + STAND_ALONE = "stand alone" + MULTI_METHOD = "multi method" + all = [ STAND_ALONE, MULTI_METHOD ] + + +def get_mem_fun_factory_var_name( cc ): + import methods_definition + while not isinstance( cc, methods_definition.methods_definition_t ): + cc = cc.parent + return cc.mem_fun_factory_var_name + +class callable_definition_t(code_creator.code_creator_t, declaration_based.declaration_based_t): + def __init__( self, callable ): code_creator.code_creator_t.__init__(self) - declaration_based.declaration_based_t.__init__( self, free_fun ) + declaration_based.declaration_based_t.__init__( self, callable ) + self.__mode = METHOD_MODE.STAND_ALONE + def __get_mode(self): + return self.__mode + def __set_mode(self, new_mode): + assert new_mode in METHOD_MODE.all + self.__mode = new_mode + method_mode = property( __get_mode, __set_mode ) + @property def ftype( self ): return self.declaration.function_type() + def join_arguments( self, args ): + args_str = '' + arg_separator = ', ' + if 1 == len( args ): + args_str = ' ' + args[0] + ' ' + else: + args_str = ' ' + arg_separator.join( args ) + ' ' + return '[%s]' % args_str + + @property + def mem_fun_factory_var_name( self ): + return get_mem_fun_factory_var_name( self ) + + def restype_code(self): + if not declarations.is_void( self.ftype.return_type ): + return ctypes_formatter.as_ctype( self.ftype.return_type ) + else: + return '' + + def argtypes_code(self): + if not self.ftype.arguments_types: + return '' + args = map( ctypes_formatter.as_ctype, self.ftype.arguments_types ) + return self.join_arguments( args ) + + def _get_system_headers_impl( self ): + return [] + + +class function_definition_t(callable_definition_t): + def __init__( self, free_fun ): + callable_definition_t.__init__( self, free_fun ) + def _create_impl(self): result = [] result.append( '%(alias)s = getattr( %(library_var_name)s, %(library_var_name)s.undecorated_names["%(undecorated_decl_name)s"] )' % dict( alias=self.declaration.alias , library_var_name=self.top_parent.library_var_name , undecorated_decl_name=self.undecorated_decl_name) ) - - if not declarations.is_void( self.ftype.return_type ): + restype = self.restype_code() + if restype: result.append( '%(alias)s.restype = %(restype)s' - % dict( alias=self.declaration.alias - , restype=ctypes_formatter.as_ctype( self.ftype.return_type ) ) ) + % dict( alias=self.declaration.alias, restype=restype ) ) - if self.ftype.arguments_types: - tmp = [] - tmp.append( '%(alias)s.argtypes = ' % dict( alias=self.declaration.alias ) ) - args = map( ctypes_formatter.as_ctype, self.ftype.arguments_types ) - tmp.append( join_arguments( args ) ) - result.append( ''.join( tmp ) ) + argtypes = self.argtypes_code() + if argtypes: + result.append( '%(alias)s.argtypes = %(argtypes)s' + % dict( alias=self.declaration.alias, argtypes=argtypes ) ) return os.linesep.join( result ) - def _get_system_headers_impl( self ): - return [] - -def mem_fun_factory_var_name( cc ): - import methods_definition - while not isinstance( cc, methods_definition.methods_definition_t ): - cc = cc.parent - return cc.mem_fun_factory_var_name - - -class METHOD_MODE: - STAND_ALONE = "stand alone" - MULTI_METHOD = "multi method" - all = [ STAND_ALONE, MULTI_METHOD ] - -class init_definition_t( code_creator.code_creator_t, declaration_based.declaration_based_t ): +class init_definition_t( callable_definition_t ): def __init__( self, constructor ): - code_creator.code_creator_t.__init__( self ) - declaration_based.declaration_based_t.__init__( self, constructor ) - self.__mode = METHOD_MODE.STAND_ALONE + callable_definition_t.__init__( self, constructor ) - def __get_mode(self): - return self.__mode - def __set_mode(self, new_mode): - assert new_mode in METHOD_MODE.all - self.__mode = new_mode - method_mode = property( __get_mode, __set_mode ) + def _get_alias_impl( self ): + return "__init__" def _create_impl(self): tmpl = '' - substitue_dict = dict( mfcreator=mem_fun_factory_var_name( self ) ) + substitue_dict = dict( mfcreator=self.mem_fun_factory_var_name ) if self.declaration.is_trivial_constructor: tmpl = '%(mfcreator)s.default_constructor()' elif self.declaration.is_copy_constructor: tmpl = '%(mfcreator)s.copy_constructor()' else: + tmpl = '"%(undecorated_decl_name)s", argtypes=%(args)s' if self.method_mode == METHOD_MODE.STAND_ALONE: - tmpl = '%(mfcreator)s( "%(undecorated_decl_name)s", argtypes=%(args)s )' - else: - tmpl = '"%(undecorated_decl_name)s", argtypes=%(args)s' - args = map( ctypes_formatter.as_ctype, self.declaration.function_type().arguments_types ) - substitue_dict['args'] = join_arguments( args ) + tmpl = '%(mfcreator)s( ' + tmpl + ' )' + + substitue_dict['args'] = self.argtypes_code() substitue_dict['undecorated_decl_name'] = self.undecorated_decl_name if self.method_mode == METHOD_MODE.STAND_ALONE: - tmp = '"__init__" : ' + tmpl + tmp = '"%s" : %s' % ( self.declaration.alias, tmpl ) return tmpl % substitue_dict - def _get_system_headers_impl( self ): - return [] +#TODO: aliases for a mem fun and const mem fun with the same name should be different -class multi_init_definition_t( compound.compound_t ): +class mem_fun_definition_t( callable_definition_t ): + def __init__( self, constructor ): + callable_definition_t.__init__( self, constructor ) + + def _create_impl(self): + result = [] + + result.append( '"%s"' % self.undecorated_decl_name ) + + restype = self.restype_code() + if self.method_mode == METHOD_MODE.STAND_ALONE and restype: + result.append( 'restype=%s' % restype ) + argtypes = self.argtypes_code() + if argtypes: + result.append( 'argtypes=%s' % argtypes ) + construction_code = ', '.join( result ) + if self.method_mode == METHOD_MODE.MULTI_METHOD: + return construction_code + else: + return '"%(alias)s" : %(mfcreator)s( %(construction_code)s ),' \ + % dict( alias=self.declaration.alias + , mfcreator=self.mem_fun_factory_var_name + , construction_code=construction_code ) + +class multi_method_definition_t( compound.compound_t ): def __init__( self ): compound.compound_t.__init__( self ) + def get_first_callable( self ): + return self.find_by_creator_class( callable_definition_t, unique=False )[0] + + @property + def multi_method_alias(self): + return self.get_first_callable().alias + def _create_impl(self): result = [] - result.append( '"__init__" : %s.multi_method()' % mem_fun_factory_var_name(self) ) + + return_type = self.get_first_callable().ftype.return_type + restype = '' + if return_type: + restype = self.iif( not declarations.is_void( return_type ) + , ctypes_formatter.as_ctype( return_type ) + , '' ) + + result.append( '"%(alias)s" : %(mfcreator)s.multi_method(%(restype)s)' + % dict( alias=self.multi_method_alias + , mfcreator=get_mem_fun_factory_var_name(self) + , restype=restype ) ) for creator in self.creators: code = '' - if isinstance( creator, init_definition_t ): + if isinstance( creator, callable_definition_t ): creator.method_mode = METHOD_MODE.MULTI_METHOD code = '.register( %s )' % creator.create() else: @@ -123,23 +184,13 @@ return [] -class del_definition_t( code_creator.code_creator_t, declaration_based.declaration_based_t ): +class del_definition_t( callable_definition_t ): def __init__( self, destructor ): - code_creator.code_creator_t.__init__( self ) - declaration_based.declaration_based_t.__init__( self, destructor ) + callable_definition_t.__init__( self, destructor ) def _create_impl(self): - return '"__del__" : %(mfcreator)s.destructor(is_virtual=%(virtual)s)' \ - % dict( mfcreator=mem_fun_factory_var_name( self ) + return '"__del__" : %(mfcreator)s.destructor(is_virtual=%(virtual)s),' \ + % dict( mfcreator=self.mem_fun_factory_var_name , virtual=self.iif( self.declaration.virtuality==declarations.VIRTUALITY_TYPES.NOT_VIRTUAL , 'False' , 'True' ) ) - - def _get_system_headers_impl( self ): - return [] - - - - - - Modified: pyplusplus_dev/pyplusplus/code_creators/methods_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/methods_definition.py 2008-12-29 22:22:45 UTC (rev 1514) +++ pyplusplus_dev/pyplusplus/code_creators/methods_definition.py 2008-12-30 11:27:00 UTC (rev 1515) @@ -17,6 +17,20 @@ def mem_fun_factory_var_name(self): return "mfcreator" + def find_mutli_method( self, alias ): + import function_definition + mmdef_t = function_definition.multi_method_definition_t + multi_method_defs = self.find_by_creator_class( mmdef_t, unique=False ) + if None is multi_method_defs: + return + multi_method_defs = filter( lambda cc: cc.multi_method_alias == alias + , multi_method_defs ) + if multi_method_defs: + return multi_method_defs[0] + else: + return None + + def _create_impl(self): result = [] scope = declarations.algorithm.declaration_path( self.declaration ) Modified: pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py 2008-12-29 22:22:45 UTC (rev 1514) +++ pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py 2008-12-30 11:27:00 UTC (rev 1515) @@ -72,7 +72,7 @@ self.this_type = ctypes.POINTER( wrapper ) def __call__( self, name, **keywd ): - if 'argtypes' not in keywd: + if 'argtypes' not in keywd or keywd['argtypes'] is None: keywd['argtypes'] = [ self.this_type ] else: keywd['argtypes'].insert( 0, self.this_type ) Modified: pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py =================================================================== --- pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-29 22:22:45 UTC (rev 1514) +++ pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-30 11:27:00 UTC (rev 1515) @@ -151,8 +151,26 @@ def visit_member_function( self ): self.__dependencies_manager.add_exported( self.curr_decl ) + md_cc = self.__class2methods_def[ self.curr_decl.parent ] cls_intro_cc = self.__class2introduction[ self.curr_decl.parent ] - cls_intro_cc.adopt_creator( code_creators.mem_fun_introduction_t( self.curr_decl ) ) + mem_fun_def_cc = code_creators.mem_fun_definition_t( self.curr_decl ) + #TODO: calculate only exported functions + if 0 == len( self.curr_decl.overloads): + #this is the first and the last and the only class constructor + md_cc.adopt_creator( mem_fun_def_cc ) + cls_intro_cc.adopt_creator( code_creators.mem_fun_introduction_t(self.curr_decl) ) + else: + has_introduction = cls_intro_cc.find_by_creator_class( code_creators.mem_fun_introduction_t, unique=False ) + has_introduction = filter( lambda cc: cc.alias == mem_fun_def_cc.alias, has_introduction ) + if not has_introduction: + cls_intro_cc.adopt_creator( code_creators.mem_fun_introduction_t(self.curr_decl) ) + + multi_method_def = md_cc.find_mutli_method( mem_fun_def_cc.alias ) + if not multi_method_def: + multi_method_def = code_creators.multi_method_definition_t () + md_cc.adopt_creator( multi_method_def ) + multi_method_def.adopt_creator( mem_fun_def_cc ) + #~ if self.curr_decl.virtuality == VIRTUALITY_TYPES.NOT_VIRTUAL: #~ cls_intro_cc.adopt_creator( code_creators.mem_fun_introduction_t( self.curr_decl ) ) #~ elif self.curr_decl.virtuality == VIRTUALITY_TYPES.VIRTUAL: @@ -166,24 +184,20 @@ cls_intro_cc = self.__class2introduction[ self.curr_decl.parent ] init_def_cc = code_creators.init_definition_t( self.curr_decl ) #TODO: calculate only exported constructors - if 1 == len( self.curr_decl.parent.constructors(recursive=False, allow_empty=True ) ): + if 0 == len( self.curr_decl.overloads): #this is the first and the last and the only class constructor - md_cc.adopt_creator( code_creators.init_definition_t( self.curr_decl ) ) + md_cc.adopt_creator( init_def_cc ) cls_intro_cc.adopt_creator( code_creators.init_introduction_t(self.curr_decl) ) else: - has_constructor = filter( lambda cc: isinstance( cc, code_creators.init_introduction_t ) - , cls_intro_cc.creators ) + has_constructor = cls_intro_cc.find_by_creator_class( code_creators.init_introduction_t ) if not has_constructor: cls_intro_cc.adopt_creator( code_creators.init_introduction_t(self.curr_decl) ) - multi_init_def = filter( lambda cc: isinstance( cc, code_creators.multi_init_definition_t ) - , md_cc.creators ) - if not multi_init_def: - multi_init_def = code_creators.multi_init_definition_t() - md_cc.adopt_creator( multi_init_def ) - multi_init_def.adopt_creator( init_def_cc ) - else: - multi_init_def[0].adopt_creator( init_def_cc ) + multi_method_def = md_cc.find_mutli_method( init_def_cc.alias ) + if not multi_method_def: + multi_method_def = code_creators.multi_method_definition_t () + md_cc.adopt_creator( multi_method_def ) + multi_method_def.adopt_creator( init_def_cc ) def visit_destructor( self ): self.__dependencies_manager.add_exported( self.curr_decl ) Modified: pyplusplus_dev/unittests/autoconfig.py =================================================================== --- pyplusplus_dev/unittests/autoconfig.py 2008-12-29 22:22:45 UTC (rev 1514) +++ pyplusplus_dev/unittests/autoconfig.py 2008-12-30 11:27:00 UTC (rev 1515) @@ -29,7 +29,7 @@ class cxx_parsers_cfg: keywd = { 'working_directory' : data_directory , 'define_symbols' : [ gccxml_version ] - , 'compiler' : compiler + , 'compiler' : "msvc71" , 'gccxml_path': gccxml.executable } if 'win' in sys.platform: Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-29 22:22:45 UTC (rev 1514) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-30 11:27:00 UTC (rev 1515) @@ -26,14 +26,38 @@ #mb.code_creator.create() sys.path.append( autoconfig.build_directory ) import ctypes_pof + #the following code fails - difference in the calling conventions #TODO: the following test failes, because of the wrong calling convention used #self.failUnless( ctypes_pof.identity_cpp( int(111) ) == 111 ) + + #testing constructors n0 = ctypes_pof.pof.number_t() - n1 = ctypes_pof.pof.number_t( ctypes.c_long(1) ) - n2 = ctypes_pof.pof.number_t( ctypes.pointer(n1), 1 ) + self.failUnless( 0 == n0.get_value() ) + n1 = ctypes_pof.pof.number_t( ctypes.c_long(32) ) + self.failUnless( 32 == n1.get_value() ) + n2 = ctypes_pof.pof.number_t( ctypes.pointer(n1) ) + self.failUnless( 32 == n2.get_value() ) + #testing get/set value + n0.set_value( 1977 ) + self.failUnless( 1977 == n0.get_value() ) + #the following functionality is still missing + #~ def test_operator_assign( self ): + #~ obj1 = number_t(1) + #~ obj2 = number_t(2) + #~ x = obj1.operator_assign( obj2 ) + #~ #there are special cases, where ctypes could introduce "optimized" behaviour and not create new python object + #~ self.failUnless( x is obj1 ) + #~ self.failUnless( obj1.m_value == obj2.m_value ) + + #~ def test_clone( self ): + #~ obj1 = number_t(1) + #~ obj2 = obj1.clone() + #~ self.fail( obj1.get_value() == obj2.get_value() ) + + #~ def test_bsc( self ): #~ root = r'E:\Documents and Settings\romany\Desktop\ToInstall\bsckit70\bscsdk' #~ mb = ctypes_module_builder_t( [os.path.join( root, 'bsc.h' )] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2008-12-29 22:22:49
|
Revision: 1514 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1514&view=rev Author: roman_yakovenko Date: 2008-12-29 22:22:45 +0000 (Mon, 29 Dec 2008) Log Message: ----------- adding multi-method support Modified Paths: -------------- pygccxml_dev/pygccxml/msvc/common_utils.py pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/class_introduction.py pyplusplus_dev/pyplusplus/code_creators/function_definition.py pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py pyplusplus_dev/unittests/ctypes_pof_tester.py Modified: pygccxml_dev/pygccxml/msvc/common_utils.py =================================================================== --- pygccxml_dev/pygccxml/msvc/common_utils.py 2008-12-29 14:02:40 UTC (rev 1513) +++ pygccxml_dev/pygccxml/msvc/common_utils.py 2008-12-29 22:22:45 UTC (rev 1514) @@ -126,7 +126,7 @@ name = name.replace( ', ', ',' ) return name - def __format_args_as_undecorated( self, argtypes ): + def undecorate_argtypes( self, argtypes ): if not argtypes: return 'void' else: @@ -153,7 +153,7 @@ and declarations.templates.is_instantiation( calldef.parent.name ): result.append( '<%s>' % ','.join( declarations.templates.args( calldef.parent.name ) ) ) - result.append( '(%s)' % self.__format_args_as_undecorated( calldef_type.arguments_types ) ) + result.append( '(%s)' % self.undecorate_argtypes( calldef_type.arguments_types ) ) if is_mem_fun and calldef.has_const: result.append( 'const' ) return ''.join( result ) @@ -187,11 +187,14 @@ if 'win' in sys.platform: undecorate_blob = undname_creator().undecorate_blob undecorate_decl = undname_creator().undecorated_decl + undecorate_argtypes = undname_creator().undecorate_argtypes else: def undecorate_blob( x ): raise NotImplementedError() def undecorate_decl( x ): raise NotImplementedError() + def undecorate_argtypes( x ): + raise NotImplementedError() import exceptions class LicenseWarning( exceptions.UserWarning ): Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-29 14:02:40 UTC (rev 1513) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-29 22:22:45 UTC (rev 1514) @@ -153,11 +153,14 @@ from class_introduction import class_declaration_introduction_t from mem_fun_introduction import mem_fun_introduction_t from mem_fun_introduction import vmem_fun_introduction_t -from mem_fun_introduction import constructor_introduction_t -from mem_fun_introduction import destructor_introduction_t +from mem_fun_introduction import init_introduction_t +from mem_fun_introduction import del_introduction_t from fields_definition import fields_definition_t from embedded_code_repository import embedded_code_repository_t from methods_definition import methods_definition_t from function_definition import function_definition_t +from function_definition import init_definition_t +from function_definition import multi_init_definition_t +from function_definition import del_definition_t Modified: pyplusplus_dev/pyplusplus/code_creators/class_introduction.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/class_introduction.py 2008-12-29 14:02:40 UTC (rev 1513) +++ pyplusplus_dev/pyplusplus/code_creators/class_introduction.py 2008-12-29 22:22:45 UTC (rev 1514) @@ -24,6 +24,7 @@ if isinstance( self.declaration.parent, declarations.namespace_t ) \ and self.declaration.parent is not self.declaration.top_parent: #not a global namespace + result.append("") result.append( '%(ns_full_name)s = %(name)s' % dict( ns_full_name=self.complete_py_name, name=self.alias )) return os.linesep.join( result ) Modified: pyplusplus_dev/pyplusplus/code_creators/function_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-29 14:02:40 UTC (rev 1513) +++ pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-29 22:22:45 UTC (rev 1514) @@ -4,6 +4,7 @@ # http://www.boost.org/LICENSE_1_0.txt) import os +import compound import code_creator import ctypes_formatter import declaration_based @@ -11,6 +12,15 @@ #TODO - unable to call C function, if dll was loaded as CPPDLL +def join_arguments( args ): + args_str = '' + arg_separator = ', ' + if 1 == len( args ): + args_str = ' ' + args[0] + ' ' + else: + args_str = ' ' + arg_separator.join( args ) + ' ' + return '[%s]' % args_str + class function_definition_t(code_creator.code_creator_t, declaration_based.declaration_based_t): def __init__( self, free_fun ): code_creator.code_creator_t.__init__(self) @@ -20,16 +30,6 @@ def ftype( self ): return self.declaration.function_type() - def __join_args( self, args ): - args_str = '' - arg_separator = ', ' - if 1 == len( args ): - args_str = ' ' + args[0] + ' ' - else: - args_str = ' ' + arg_separator.join( args ) + ' ' - return '[%s]' % args_str - - def _create_impl(self): result = [] result.append( '%(alias)s = getattr( %(library_var_name)s, %(library_var_name)s.undecorated_names["%(undecorated_decl_name)s"] )' @@ -46,10 +46,100 @@ tmp = [] tmp.append( '%(alias)s.argtypes = ' % dict( alias=self.declaration.alias ) ) args = map( ctypes_formatter.as_ctype, self.ftype.arguments_types ) - tmp.append( self.__join_args( args ) ) + tmp.append( join_arguments( args ) ) result.append( ''.join( tmp ) ) return os.linesep.join( result ) def _get_system_headers_impl( self ): return [] + +def mem_fun_factory_var_name( cc ): + import methods_definition + while not isinstance( cc, methods_definition.methods_definition_t ): + cc = cc.parent + return cc.mem_fun_factory_var_name + + +class METHOD_MODE: + STAND_ALONE = "stand alone" + MULTI_METHOD = "multi method" + all = [ STAND_ALONE, MULTI_METHOD ] + +class init_definition_t( code_creator.code_creator_t, declaration_based.declaration_based_t ): + def __init__( self, constructor ): + code_creator.code_creator_t.__init__( self ) + declaration_based.declaration_based_t.__init__( self, constructor ) + self.__mode = METHOD_MODE.STAND_ALONE + + def __get_mode(self): + return self.__mode + def __set_mode(self, new_mode): + assert new_mode in METHOD_MODE.all + self.__mode = new_mode + method_mode = property( __get_mode, __set_mode ) + + def _create_impl(self): + tmpl = '' + substitue_dict = dict( mfcreator=mem_fun_factory_var_name( self ) ) + if self.declaration.is_trivial_constructor: + tmpl = '%(mfcreator)s.default_constructor()' + elif self.declaration.is_copy_constructor: + tmpl = '%(mfcreator)s.copy_constructor()' + else: + if self.method_mode == METHOD_MODE.STAND_ALONE: + tmpl = '%(mfcreator)s( "%(undecorated_decl_name)s", argtypes=%(args)s )' + else: + tmpl = '"%(undecorated_decl_name)s", argtypes=%(args)s' + args = map( ctypes_formatter.as_ctype, self.declaration.function_type().arguments_types ) + substitue_dict['args'] = join_arguments( args ) + substitue_dict['undecorated_decl_name'] = self.undecorated_decl_name + if self.method_mode == METHOD_MODE.STAND_ALONE: + tmp = '"__init__" : ' + tmpl + return tmpl % substitue_dict + + def _get_system_headers_impl( self ): + return [] + +class multi_init_definition_t( compound.compound_t ): + def __init__( self ): + compound.compound_t.__init__( self ) + + def _create_impl(self): + result = [] + result.append( '"__init__" : %s.multi_method()' % mem_fun_factory_var_name(self) ) + for creator in self.creators: + code = '' + if isinstance( creator, init_definition_t ): + creator.method_mode = METHOD_MODE.MULTI_METHOD + code = '.register( %s )' % creator.create() + else: + code = creator.create() + result.append( self.indent( code, 4 ) ) + result.append( self.indent( '.finalize(),', 4 ) ) + return os.linesep.join( result ) + + def _get_system_headers_impl( self ): + return [] + + +class del_definition_t( code_creator.code_creator_t, declaration_based.declaration_based_t ): + def __init__( self, destructor ): + code_creator.code_creator_t.__init__( self ) + declaration_based.declaration_based_t.__init__( self, destructor ) + + def _create_impl(self): + return '"__del__" : %(mfcreator)s.destructor(is_virtual=%(virtual)s)' \ + % dict( mfcreator=mem_fun_factory_var_name( self ) + , virtual=self.iif( self.declaration.virtuality==declarations.VIRTUALITY_TYPES.NOT_VIRTUAL + , 'False' + , 'True' ) ) + + def _get_system_headers_impl( self ): + return [] + + + + + + Modified: pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py 2008-12-29 14:02:40 UTC (rev 1513) +++ pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py 2008-12-29 22:22:45 UTC (rev 1514) @@ -16,7 +16,7 @@ def _create_impl(self): tmpl = ['def %(alias)s( self, *args ):'] tmpl.append( self.indent('"""%(name)s"""') ) - tmpl.append( self.indent("return self._methods_['%(alias)s']( ctypes.byref( self ), *args )") ) + tmpl.append( self.indent("return self._methods_['%(alias)s']( ctypes.pointer( self ), *args )") ) return os.linesep.join( tmpl ) \ % dict( alias=self.declaration.alias, name=self.undecorated_decl_name ) @@ -31,7 +31,7 @@ def _create_impl(self): tmpl = ['def %(alias)s( self, *args ):'] tmpl.append( self.indent('"""%(name)s"""') ) - tmpl.append( self.indent("return self._vtable_['%(ordinal)d'].%(alias)s( ctypes.byref( self ), *args )") ) + tmpl.append( self.indent("return self._vtable_['%(ordinal)d'].%(alias)s( ctypes.pointer( self ), *args )") ) return os.linesep.join( tmpl ) \ % dict( alias=self.declaration.alias , name=self.undecorated_decl_name @@ -40,7 +40,7 @@ def _get_system_headers_impl( self ): return [] -class constructor_introduction_t(code_creator.code_creator_t, declaration_based.declaration_based_t): +class init_introduction_t(code_creator.code_creator_t, declaration_based.declaration_based_t): def __init__( self, constructor ): code_creator.code_creator_t.__init__(self) declaration_based.declaration_based_t.__init__( self, constructor ) @@ -48,14 +48,14 @@ def _create_impl(self): tmpl = ['def __init__( self, *args ):'] tmpl.append( self.indent('"""%(name)s"""') ) - tmpl.append( self.indent("return self._methods_['__init__']( ctypes.byref( self ), *args )") ) + tmpl.append( self.indent("return self._methods_['__init__']( ctypes.pointer( self ), *args )") ) return os.linesep.join( tmpl ) \ % dict( alias=self.declaration.alias, name=self.undecorated_decl_name ) def _get_system_headers_impl( self ): return [] -class destructor_introduction_t(code_creator.code_creator_t, declaration_based.declaration_based_t): +class del_introduction_t(code_creator.code_creator_t, declaration_based.declaration_based_t): def __init__( self, constructor ): code_creator.code_creator_t.__init__(self) declaration_based.declaration_based_t.__init__( self, constructor ) @@ -63,7 +63,7 @@ def _create_impl(self): tmpl = ['def __del__( self ):'] tmpl.append( self.indent('"""%(name)s"""') ) - tmpl.append( self.indent("return self._methods_['__del__']( ctypes.byref( self ) )") ) + tmpl.append( self.indent("return self._methods_['__del__']( ctypes.pointer( self ) )") ) return os.linesep.join( tmpl ) \ % dict( name=self.undecorated_decl_name ) Modified: pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py 2008-12-29 14:02:40 UTC (rev 1513) +++ pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py 2008-12-29 22:22:45 UTC (rev 1514) @@ -11,6 +11,7 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +import os import ctypes # what is the best way to treat overloaded constructors @@ -25,35 +26,44 @@ return self.func( *args, **keywd ) class native_overloaded_callable( object ): - def __init__(self, restype=None ): - self.__functions = {} # argtypes : function - self.restype = restype + def __init__(self, functions ): + self.__functions = functions - def register( self, dll, name, argtypes=None ): - f = getattr( dll, dll.undecorated_names[name] ) - f.restype = self.restype - f.argtypes = argtypes - self.__functions[ argtypes ] = f - return self - - def register_callable( self, callable ): - #TODO: check restype - self.__functions[ tuple(callable.func.argtypes) ] = callable.func - return self - def __call__( self, *args ): types = None if args: types = tuple(arg.__class__ for arg in args) f = self.__functions.get(types) if f is None: + msg = ['Unable to find a function that match the arguments you passed.'] + msg.append( 'First argument type is "this" type.' ) + msg.append( 'This function call argument types: ' + str( types ) ) + msg.append( 'Registered methods argument types: ' ) + for key in self.__functions.iterkeys(): + msg.append(' ' + str(key)) + raise TypeError(os.linesep.join(msg)) + else: return f(*args) + +class multi_method_registry_t: + def __init__( self, factory, restype ): + self.factory = factory + self.restype = restype + self.__functions = {} + + def register( self, callable_or_name, argtypes=None ): + if isinstance( callable_or_name, native_callable ): + callable = callable_or_name else: - raise TypeError("no match") + name = callable_or_name + callable = self.factory( name, restype=self.restype, argtypes=argtypes ) + self.__functions[ tuple(callable.func.argtypes) ] = callable.func + return self -def multi_method( restype=None ): - return native_overloaded_callable( restype ) + def finalize(self): + return native_overloaded_callable( self.__functions ) + class mem_fun_factory( object ): def __init__( self, dll, wrapper, class_name, namespace='' ): self.dll = dll @@ -92,9 +102,13 @@ , class_name=self.class_name ) , argtypes=[self.this_type] ) - def destructor( self ): - return self( '%(ns)s%(class_name)s::~%(class_name)s(void)' + def destructor( self, is_virtual=False ): + virtuality = '' + if is_virtual: + virtuality = 'virtual ' + return self( '%(virtuality)s%(ns)s%(class_name)s::~%(class_name)s(void)' % dict( ns=self.__get_ns_name() + , virtuality=virtuality , class_name=self.class_name ) ) def operator_assign( self ): @@ -118,4 +132,6 @@ , args=argtypes_str ) , **keywd ) + def multi_method( self, restype=None ): + return multi_method_registry_t( self, restype ) """ Modified: pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py =================================================================== --- pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-29 14:02:40 UTC (rev 1513) +++ pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-29 22:22:45 UTC (rev 1514) @@ -43,6 +43,8 @@ self.curr_code_creator = self.module #mapping between class declaration and class introduction code creator self.__class2introduction = {} + #mapping between classs and its methods definition dictionary + self.__class2methods_def = {} #mapping between namespace and its code creator self.__namespace2pyclass = {} #set of all included namespaces @@ -160,17 +162,37 @@ def visit_constructor( self ): self.__dependencies_manager.add_exported( self.curr_decl ) + md_cc = self.__class2methods_def[ self.curr_decl.parent ] cls_intro_cc = self.__class2introduction[ self.curr_decl.parent ] - has_constructor = filter( lambda cc: isinstance( cc, code_creators.constructor_introduction_t ) - , cls_intro_cc.creators ) - if not has_constructor: - cls_intro_cc.adopt_creator( code_creators.constructor_introduction_t( self.curr_decl ) ) + init_def_cc = code_creators.init_definition_t( self.curr_decl ) + #TODO: calculate only exported constructors + if 1 == len( self.curr_decl.parent.constructors(recursive=False, allow_empty=True ) ): + #this is the first and the last and the only class constructor + md_cc.adopt_creator( code_creators.init_definition_t( self.curr_decl ) ) + cls_intro_cc.adopt_creator( code_creators.init_introduction_t(self.curr_decl) ) + else: + has_constructor = filter( lambda cc: isinstance( cc, code_creators.init_introduction_t ) + , cls_intro_cc.creators ) + if not has_constructor: + cls_intro_cc.adopt_creator( code_creators.init_introduction_t(self.curr_decl) ) + multi_init_def = filter( lambda cc: isinstance( cc, code_creators.multi_init_definition_t ) + , md_cc.creators ) + if not multi_init_def: + multi_init_def = code_creators.multi_init_definition_t() + md_cc.adopt_creator( multi_init_def ) + multi_init_def.adopt_creator( init_def_cc ) + else: + multi_init_def[0].adopt_creator( init_def_cc ) + def visit_destructor( self ): self.__dependencies_manager.add_exported( self.curr_decl ) cls_intro_cc = self.__class2introduction[ self.curr_decl.parent ] - cls_intro_cc.adopt_creator( code_creators.destructor_introduction_t( self.curr_decl ) ) + cls_intro_cc.adopt_creator( code_creators.del_introduction_t( self.curr_decl ) ) + md_cc = self.__class2methods_def[ self.curr_decl.parent ] + md_cc.adopt_creator( code_creators.del_definition_t( self.curr_decl ) ) + def visit_member_operator( self ): self.__dependencies_manager.add_exported( self.curr_decl ) @@ -197,7 +219,9 @@ self.__dependencies_manager.add_exported( self.curr_decl ) #fields definition should be recursive using the visitor self.__class_defs_ccs.adopt_creator( code_creators.fields_definition_t( self.curr_decl ) ) - self.__class_defs_ccs.adopt_creator( code_creators.methods_definition_t( self.curr_decl ) ) + md_cc = code_creators.methods_definition_t( self.curr_decl ) + self.__class2methods_def[ self.curr_decl ] = md_cc + self.__class_defs_ccs.adopt_creator( md_cc ) class_ = self.curr_decl for decl in self.curr_decl.decls( recursive=False, allow_empty=True ): if self.__should_generate_code( decl ): Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-29 14:02:40 UTC (rev 1513) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-29 22:22:45 UTC (rev 1514) @@ -27,21 +27,19 @@ sys.path.append( autoconfig.build_directory ) import ctypes_pof #the following code fails - difference in the calling conventions - print ctypes_pof.identity_cpp( int(111) ) - self.failUnless( ctypes_pof.identity_cpp( int(111) ) == 111 ) + #TODO: the following test failes, because of the wrong calling convention used + #self.failUnless( ctypes_pof.identity_cpp( int(111) ) == 111 ) + n0 = ctypes_pof.pof.number_t() + n1 = ctypes_pof.pof.number_t( ctypes.c_long(1) ) + n2 = ctypes_pof.pof.number_t( ctypes.pointer(n1), 1 ) + #~ def test_bsc( self ): #~ root = r'E:\Documents and Settings\romany\Desktop\ToInstall\bsckit70\bscsdk' #~ mb = ctypes_module_builder_t( [os.path.join( root, 'bsc.h' )] #~ , os.path.join( root, 'msbsc70.dll' ), autoconfig.cxx_parsers_cfg.gccxml ) - mb.print_declarations() #~ mb.build_code_creator( self.symbols_file ) #~ mb.write_module( os.path.join( root, 'bsc.py' ) ) - #~ #mb.code_creator.create() - sys.path.append( autoconfig.build_directory ) - import ctypes_pof - print ctypes_pof.identity( 23 ) - self.failUnless( ctypes_pof.identity( 23 ) == 23 ) def create_suite(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2008-12-29 14:02:43
|
Revision: 1513 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1513&view=rev Author: roman_yakovenko Date: 2008-12-29 14:02:40 +0000 (Mon, 29 Dec 2008) Log Message: ----------- adding few basic ctypes code creators Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/class_introduction.py pyplusplus_dev/pyplusplus/code_creators/fields_definition.py pyplusplus_dev/pyplusplus/code_creators/function_definition.py pyplusplus_dev/pyplusplus/code_creators/import_.py pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py pyplusplus_dev/pyplusplus/code_creators/methods_definition.py pyplusplus_dev/pyplusplus/code_repository/__init__.py pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py pyplusplus_dev/pyplusplus/file_writers/writer.py pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py pyplusplus_dev/unittests/ctypes_pof_tester.py pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp pyplusplus_dev/unittests/data/ctypes_pof/mydll.h Added Paths: ----------- pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj Removed Paths: ------------- pyplusplus_dev/pyplusplus/code_repository/ctypes_cpp_utils.py pyplusplus_dev/unittests/data/ctypes_pof/mydll.vcproj Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -150,9 +150,14 @@ from name_mappings import name_mappings_t from namespace_as_pyclass import namespace_as_pyclass_t from class_introduction import class_introduction_t +from class_introduction import class_declaration_introduction_t from mem_fun_introduction import mem_fun_introduction_t from mem_fun_introduction import vmem_fun_introduction_t +from mem_fun_introduction import constructor_introduction_t +from mem_fun_introduction import destructor_introduction_t + + from fields_definition import fields_definition_t from embedded_code_repository import embedded_code_repository_t from methods_definition import methods_definition_t -from function_definition import c_function_definition_t +from function_definition import function_definition_t Modified: pyplusplus_dev/pyplusplus/code_creators/class_introduction.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/class_introduction.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/class_introduction.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -5,6 +5,7 @@ import os import compound +import code_creator import declaration_based from pygccxml import declarations @@ -17,8 +18,6 @@ result = [] result.append( "class %s(ctypes.Structure):" % self.alias ) result.append( self.indent( '"""class %s"""' % self.decl_identifier ) ) - result.append( self.indent( '#_fields_ = [] <-- class member variables definition list' ) ) - result.append( self.indent( '#_methods_ = {} <-- class non-virtual member functions definition list' ) ) if self.creators: result.append( self.indent( '' ) ) result.append( compound.compound_t.create_internal_code( self.creators ) ) @@ -31,3 +30,24 @@ def _get_system_headers_impl( self ): return [] + + +class class_declaration_introduction_t(code_creator.code_creator_t, declaration_based.declaration_based_t): + def __init__( self, class_declaration ): + code_creator.code_creator_t.__init__(self) + declaration_based.declaration_based_t.__init__( self, class_declaration ) + + def _create_impl(self): + result = [] + result.append( "class %s(ctypes.Structure):" % self.alias ) + result.append( self.indent( '"""class declaration %s"""' % self.decl_identifier ) ) + result.append( self.indent( '_fields_ = []' ) ) + + if isinstance( self.declaration.parent, declarations.namespace_t ) \ + and self.declaration.parent is not self.declaration.top_parent: #not a global namespace + result.append( '%(ns_full_name)s = %(name)s' + % dict( ns_full_name=self.complete_py_name, name=self.alias )) + return os.linesep.join( result ) + + def _get_system_headers_impl( self ): + return [] Modified: pyplusplus_dev/pyplusplus/code_creators/fields_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/fields_definition.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/fields_definition.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -8,6 +8,11 @@ import declaration_based from pygccxml import declarations +#TODO: don't hide public member variables +#TODO: how _fields_ should be defined in a class hierarchy +#TODO: fix 64bit issue with calculating vtable pointer size + + class fields_definition_t(code_creator.code_creator_t, declaration_based.declaration_based_t): def __init__( self, class_ ): code_creator.code_creator_t.__init__(self) @@ -15,13 +20,11 @@ def _create_impl(self): result = [] - result.append( '%(complete_py_name)s._fields_ = [ #class member variables definition list' - % dict( complete_py_name=self.complete_py_name ) ) + result.append( '%(complete_py_name)s._fields_ = [ #class %(decl_identifier)s' + % dict( complete_py_name=self.complete_py_name + , decl_identifier=self.decl_identifier) ) if self.declaration.has_vtable: result.append( self.indent( '("_vtable_", ctypes.POINTER(ctypes.c_void_p)),' ) ) - result.append( self.indent( "#TODO: don't hide public member variables" ) ) - result.append( self.indent( "#TODO: how _fields_ should be defined in a class hierarchy" ) ) - result.append( self.indent( "#TODO: fix 64bit issue with calculating vtable pointer size" ) ) result.append( self.indent( '("__hidden__", ctypes.c_char * %d),' % ( self.declaration.byte_size - 4*int(self.declaration.has_vtable) ) ) ) result.append( ']' ) Modified: pyplusplus_dev/pyplusplus/code_creators/function_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -9,14 +9,9 @@ import declaration_based from pygccxml import declarations -""" -BSCGetBaseArray = _libraries['msbsc70.dll'].BSCGetBaseArray -BSCGetBaseArray.restype = BOOL -BSCGetBaseArray.argtypes = [POINTER(Bsc), IINST, POINTER(POINTER(IINST)), POINTER(ULONG)] +#TODO - unable to call C function, if dll was loaded as CPPDLL -""" - -class c_function_definition_t(code_creator.code_creator_t, declaration_based.declaration_based_t): +class function_definition_t(code_creator.code_creator_t, declaration_based.declaration_based_t): def __init__( self, free_fun ): code_creator.code_creator_t.__init__(self) declaration_based.declaration_based_t.__init__( self, free_fun ) @@ -37,11 +32,10 @@ def _create_impl(self): result = [] - result.append( '#%s' % self.undecorated_decl_name ) - result.append( '#TODO - unable to call C function, if dll was loaded as CPPDLL' ) - result.append( '%(alias)s = %(library_var_name)s.%(alias)s' + result.append( '%(alias)s = getattr( %(library_var_name)s, %(library_var_name)s.undecorated_names["%(undecorated_decl_name)s"] )' % dict( alias=self.declaration.alias - , library_var_name=self.top_parent.library_var_name ) ) + , library_var_name=self.top_parent.library_var_name + , undecorated_decl_name=self.undecorated_decl_name) ) if not declarations.is_void( self.ftype.return_type ): result.append( '%(alias)s.restype = %(restype)s' Modified: pyplusplus_dev/pyplusplus/code_creators/import_.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/import_.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/import_.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -3,6 +3,7 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +import os import code_creator import include_directories @@ -14,7 +15,7 @@ self._module_name = module_name def _create_impl(self): - return 'import %(module)s' % dict( module=self._module_name ) + return 'import %(module)s' % dict( module=os.path.splitext(self._module_name)[0] ) def _get_system_headers_impl( self ): return [] Modified: pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/mem_fun_introduction.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -39,3 +39,33 @@ def _get_system_headers_impl( self ): return [] + +class constructor_introduction_t(code_creator.code_creator_t, declaration_based.declaration_based_t): + def __init__( self, constructor ): + code_creator.code_creator_t.__init__(self) + declaration_based.declaration_based_t.__init__( self, constructor ) + + def _create_impl(self): + tmpl = ['def __init__( self, *args ):'] + tmpl.append( self.indent('"""%(name)s"""') ) + tmpl.append( self.indent("return self._methods_['__init__']( ctypes.byref( self ), *args )") ) + return os.linesep.join( tmpl ) \ + % dict( alias=self.declaration.alias, name=self.undecorated_decl_name ) + + def _get_system_headers_impl( self ): + return [] + +class destructor_introduction_t(code_creator.code_creator_t, declaration_based.declaration_based_t): + def __init__( self, constructor ): + code_creator.code_creator_t.__init__(self) + declaration_based.declaration_based_t.__init__( self, constructor ) + + def _create_impl(self): + tmpl = ['def __del__( self ):'] + tmpl.append( self.indent('"""%(name)s"""') ) + tmpl.append( self.indent("return self._methods_['__del__']( ctypes.byref( self ) )") ) + return os.linesep.join( tmpl ) \ + % dict( name=self.undecorated_decl_name ) + + def _get_system_headers_impl( self ): + return [] Modified: pyplusplus_dev/pyplusplus/code_creators/methods_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/methods_definition.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_creators/methods_definition.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -21,9 +21,9 @@ result = [] scope = declarations.algorithm.declaration_path( self.declaration ) del scope[0] #del :: from the global namespace + del scope[-1] #del self from the list - - result.append( '%(mem_fun_factory_var_name)s = mem_fun_factory( %(library_var_name)s, %(complete_py_name)s, "%(class_name)s", "%(ns)s" )' + result.append( '%(mem_fun_factory_var_name)s = ctypes_utils.mem_fun_factory( %(library_var_name)s, %(complete_py_name)s, "%(class_name)s", "%(ns)s" )' % dict( mem_fun_factory_var_name=self.mem_fun_factory_var_name , library_var_name=self.top_parent.library_var_name , complete_py_name=self.complete_py_name Modified: pyplusplus_dev/pyplusplus/code_repository/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/__init__.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_repository/__init__.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -19,7 +19,7 @@ import convenience import return_range import call_policies -import ctypes_cpp_utils +import ctypes_utils import ctypes_integration all = [ array_1 @@ -28,7 +28,7 @@ , call_policies , named_tuple , return_range - , ctypes_cpp_utils + , ctypes_utils , ctypes_integration ] headers = map( lambda f: f.file_name, all ) Deleted: pyplusplus_dev/pyplusplus/code_repository/ctypes_cpp_utils.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/ctypes_cpp_utils.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/code_repository/ctypes_cpp_utils.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -1,92 +0,0 @@ -# Copyright 2004-2008 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) - -file_name = "ctypes_cpp_utils.py" - -license = \ -"""# Copyright 2004-2008 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) -""" - - -code = \ -""" -# what is the best way to treat overloaded constructors -class mem_fun_callable( object ): - def __init__(self, dll, name, restype=None, argtypes=None ): - self.name = name - self.func = getattr( dll, dll.undecorated_names[name] ) - self.func.restype = restype - self.func.argtypes = argtypes - - def __call__(self, *args, **keywd ): - return self.func( *args, **keywd ) - -class mem_fun_factory( object ): - def __init__( self, dll, wrapper, class_name, namespace='' ): - self.dll = dll - self.namespace = namespace - self.class_name = class_name - self.this_type = ctypes.POINTER( wrapper ) - - def __call__( self, name, **keywd ): - if 'argtypes' not in keywd: - keywd['argtypes'] = [ self.this_type ] - else: - keywd['argtypes'].insert( 0, self.this_type ) - return mem_fun_callable( self.dll, name, **keywd ) - - def __get_ns_name(self): - if self.namespace: - return self.namespace + '::' - else: - return '' - - def default_constructor( self ): - return self( '%(ns)s%(class_name)s::%(class_name)s(void)' - % dict( ns=self.__get_ns_name() - , class_name=self.class_name ) ) - - def constructor( self, argtypes_str, **keywd ): - return self( '%(ns)s%(class_name)s::%(class_name)s(%(args)s)' - % dict( ns=self.__get_ns_name() - , class_name=self.class_name - , args=argtypes_str ) - , **keywd ) - - def copy_constructor( self ): - return self( '%(ns)s%(class_name)s::%(class_name)s(%(class_name)s const &)' - % dict( ns=self.__get_ns_name() - , class_name=self.class_name ) - , argtypes=[self.this_type] ) - - def destructor( self ): - return self( '%(ns)s%(class_name)s::~%(class_name)s(void)' - % dict( ns=self.__get_ns_name() - , class_name=self.class_name ) ) - - def operator_assign( self ): - return self( '%(ns)s%(class_name)s & %(class_name)s::operator=(%(class_name)s const &)' - % dict( ns=self.__get_ns_name() - , class_name=self.class_name ) - , restype=self.this_type - , argtypes=[self.this_type] ) - - def method( self, name, restype_str=None, argtypes_str=None, **keywd ): - if None is restype_str: - restype_str = 'void' - if None is argtypes_str: - argtypes_str = 'void' - - return self( '%(return_)s %(ns)s%(class_name)s::%(method_name)s(%(args)s)' - % dict( return_=restype_str - , ns=self.__get_ns_name() - , class_name=self.class_name - , method_name=name - , args=argtypes_str ) - , **keywd ) -""" Copied: pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py (from rev 1512, pyplusplus_dev/pyplusplus/code_repository/ctypes_cpp_utils.py) =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_repository/ctypes_utils.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -0,0 +1,121 @@ +# Copyright 2004-2008 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) + +file_name = "ctypes_utils.py" + +code = \ +"""# Copyright 2004-2008 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 ctypes + +# what is the best way to treat overloaded constructors +class native_callable( object ): + def __init__(self, dll, name, restype=None, argtypes=None ): + self.name = name + self.func = getattr( dll, dll.undecorated_names[name] ) + self.func.restype = restype + self.func.argtypes = argtypes + + def __call__(self, *args, **keywd ): + return self.func( *args, **keywd ) + +class native_overloaded_callable( object ): + def __init__(self, restype=None ): + self.__functions = {} # argtypes : function + self.restype = restype + + def register( self, dll, name, argtypes=None ): + f = getattr( dll, dll.undecorated_names[name] ) + f.restype = self.restype + f.argtypes = argtypes + self.__functions[ argtypes ] = f + return self + + def register_callable( self, callable ): + #TODO: check restype + self.__functions[ tuple(callable.func.argtypes) ] = callable.func + return self + + def __call__( self, *args ): + types = None + if args: + types = tuple(arg.__class__ for arg in args) + f = self.__functions.get(types) + if f is None: + return f(*args) + else: + raise TypeError("no match") + +def multi_method( restype=None ): + return native_overloaded_callable( restype ) + +class mem_fun_factory( object ): + def __init__( self, dll, wrapper, class_name, namespace='' ): + self.dll = dll + self.namespace = namespace + self.class_name = class_name + self.this_type = ctypes.POINTER( wrapper ) + + def __call__( self, name, **keywd ): + if 'argtypes' not in keywd: + keywd['argtypes'] = [ self.this_type ] + else: + keywd['argtypes'].insert( 0, self.this_type ) + return native_callable( self.dll, name, **keywd ) + + def __get_ns_name(self): + if self.namespace: + return self.namespace + '::' + else: + return '' + + def default_constructor( self ): + return self( '%(ns)s%(class_name)s::%(class_name)s(void)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) ) + + def constructor( self, argtypes_str, **keywd ): + return self( '%(ns)s%(class_name)s::%(class_name)s(%(args)s)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name + , args=argtypes_str ) + , **keywd ) + + def copy_constructor( self ): + return self( '%(ns)s%(class_name)s::%(class_name)s(%(ns)s%(class_name)s const &)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) + , argtypes=[self.this_type] ) + + def destructor( self ): + return self( '%(ns)s%(class_name)s::~%(class_name)s(void)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) ) + + def operator_assign( self ): + return self( '%(ns)s%(class_name)s & %(class_name)s::operator=(%(class_name)s const &)' + % dict( ns=self.__get_ns_name() + , class_name=self.class_name ) + , restype=self.this_type + , argtypes=[self.this_type] ) + + def method( self, name, restype_str=None, argtypes_str=None, **keywd ): + if None is restype_str: + restype_str = 'void' + if None is argtypes_str: + argtypes_str = 'void' + + return self( '%(return_)s %(ns)s%(class_name)s::%(method_name)s(%(args)s)' + % dict( return_=restype_str + , ns=self.__get_ns_name() + , class_name=self.class_name + , method_name=name + , args=argtypes_str ) + , **keywd ) + +""" Modified: pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py =================================================================== --- pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -32,14 +32,22 @@ self.module = code_creators.ctypes_module_t( global_ns ) self.__dependencies_manager = dependencies_manager.manager_t(self.decl_logger) + #bookmark for class introductions self.__class_ccs = code_creators.bookmark_t() + #bookmark for class deinitions + self.__class_defs_ccs = code_creators.bookmark_t() #~ prepared_decls = self.__prepare_decls( global_ns, doc_extractor ) #~ self.__decls = sort_algorithms.sort( prepared_decls ) self.curr_decl = global_ns self.curr_code_creator = self.module + #mapping between class declaration and class introduction code creator self.__class2introduction = {} + #mapping between namespace and its code creator self.__namespace2pyclass = {} + #set of all included namespaces + #~ self.__included_nss = set() + #~ for decl in self.global_ns def __print_readme( self, decl ): readme = decl.readme() @@ -109,9 +117,13 @@ # Invoke the appropriate visit_*() method on all decls ccc = self.curr_code_creator ccc.adopt_creator( code_creators.import_t( 'ctypes' ) ) + ccc.adopt_creator( code_creators.import_t( code_repository.ctypes_utils.file_name ) ) + ccc.adopt_creator( code_creators.separator_t() ) + ccc.adopt_creator( code_creators.library_reference_t( self.__library_path ) ) ccc.adopt_creator( code_creators.name_mappings_t( self.__exported_symbols ) ) + ccc.adopt_creator( code_creators.separator_t() ) #adding namespaces global_ns_cc = code_creators.bookmark_t() @@ -127,7 +139,7 @@ if self.__contains_exported( class_ ): self.__add_class_introductions( self.__class_ccs, class_ ) - ccc.adopt_creator( code_creators.embedded_code_repository_t( code_repository.ctypes_cpp_utils ) ) + ccc.adopt_creator( self.__class_defs_ccs ) declarations.apply_visitor( self, self.curr_decl ) @@ -148,9 +160,16 @@ def visit_constructor( self ): self.__dependencies_manager.add_exported( self.curr_decl ) + cls_intro_cc = self.__class2introduction[ self.curr_decl.parent ] + has_constructor = filter( lambda cc: isinstance( cc, code_creators.constructor_introduction_t ) + , cls_intro_cc.creators ) + if not has_constructor: + cls_intro_cc.adopt_creator( code_creators.constructor_introduction_t( self.curr_decl ) ) def visit_destructor( self ): self.__dependencies_manager.add_exported( self.curr_decl ) + cls_intro_cc = self.__class2introduction[ self.curr_decl.parent ] + cls_intro_cc.adopt_creator( code_creators.destructor_introduction_t( self.curr_decl ) ) def visit_member_operator( self ): self.__dependencies_manager.add_exported( self.curr_decl ) @@ -162,22 +181,23 @@ self.__dependencies_manager.add_exported( self.curr_decl ) if self.curr_decl.name in self.__exported_symbols \ and self.curr_decl.name == self.__exported_symbols[ self.curr_decl.name ]: - #we deal with c function - self.curr_code_creator.adopt_creator( code_creators.c_function_definition_t( self.curr_decl ) ) + return #it is notpossible to call C function from CPPDLL + else: + self.curr_code_creator.adopt_creator( code_creators.function_definition_t( self.curr_decl ) ) def visit_free_operator( self ): self.__dependencies_manager.add_exported( self.curr_decl ) def visit_class_declaration(self ): self.__dependencies_manager.add_exported( self.curr_decl ) - ci_creator = code_creators.class_introduction_t( self.curr_decl ) - self.curr_code_creator.adopt_creator( ci_creator ) + ci_creator = code_creators.class_declaration_introduction_t( self.curr_decl ) + self.__class_ccs.adopt_creator( ci_creator ) def visit_class(self): self.__dependencies_manager.add_exported( self.curr_decl ) #fields definition should be recursive using the visitor - self.curr_code_creator.adopt_creator( code_creators.fields_definition_t( self.curr_decl ) ) - self.curr_code_creator.adopt_creator( code_creators.methods_definition_t( self.curr_decl ) ) + self.__class_defs_ccs.adopt_creator( code_creators.fields_definition_t( self.curr_decl ) ) + self.__class_defs_ccs.adopt_creator( code_creators.methods_definition_t( self.curr_decl ) ) class_ = self.curr_decl for decl in self.curr_decl.decls( recursive=False, allow_empty=True ): if self.__should_generate_code( decl ): @@ -195,6 +215,8 @@ self.__dependencies_manager.add_exported( self.curr_decl ) def visit_namespace(self ): + if not self.__contains_exported( self.curr_decl ): + return if self.global_ns is not self.curr_decl: ns_creator = code_creators.namespace_as_pyclass_t( self.curr_decl ) self.__namespace2pyclass[ self.curr_decl ] = ns_creator Modified: pyplusplus_dev/pyplusplus/file_writers/writer.py =================================================================== --- pyplusplus_dev/pyplusplus/file_writers/writer.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/file_writers/writer.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -71,9 +71,14 @@ if cr.file_name in system_headers: #check whether file from code repository is used self.write_file( os.path.join( dir, cr.file_name ), cr.code ) - #named_tuple.py is a special case :-( - self.write_file( os.path.join( dir, code_repository.named_tuple.file_name ) - , code_repository.named_tuple.code ) + #Python files are a special case + if isinstance( self.extmodule, code_creators.bpmodule_t ): + self.write_file( os.path.join( dir, code_repository.named_tuple.file_name ) + , code_repository.named_tuple.code ) + else: + self.write_file( os.path.join( dir, code_repository.ctypes_utils.file_name ) + , code_repository.ctypes_utils.code ) + @staticmethod def write_file( fpath, content, files_sum_repository=None, encoding='ascii' ): """Write a source file. Modified: pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -92,7 +92,6 @@ they_depend_on_us = decls_package.dependency_info_t.they_depend_on_us included_decls.update( they_depend_on_us( included_decls ) ) for d in included_decls: - print str(d) d.include() if isinstance( d, decls_package.class_t ): d.top_class.include() Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-29 14:02:40 UTC (rev 1513) @@ -27,8 +27,23 @@ sys.path.append( autoconfig.build_directory ) import ctypes_pof #the following code fails - difference in the calling conventions - self.failUnless( ctypes_pof.identity( int(111) ) == 111 ) + print ctypes_pof.identity_cpp( int(111) ) + self.failUnless( ctypes_pof.identity_cpp( int(111) ) == 111 ) + #~ def test_bsc( self ): + #~ root = r'E:\Documents and Settings\romany\Desktop\ToInstall\bsckit70\bscsdk' + #~ mb = ctypes_module_builder_t( [os.path.join( root, 'bsc.h' )] + #~ , os.path.join( root, 'msbsc70.dll' ), autoconfig.cxx_parsers_cfg.gccxml ) + mb.print_declarations() + #~ mb.build_code_creator( self.symbols_file ) + #~ mb.write_module( os.path.join( root, 'bsc.py' ) ) + #~ #mb.code_creator.create() + sys.path.append( autoconfig.build_directory ) + import ctypes_pof + print ctypes_pof.identity( 23 ) + self.failUnless( ctypes_pof.identity( 23 ) == 23 ) + + def create_suite(): suite = unittest.TestSuite() if 'win' in sys.platform: Added: pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj (rev 0) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.80.vcproj 2008-12-29 14:02:40 UTC (rev 1513) @@ -0,0 +1,187 @@ +<?xml version="1.0" encoding="windows-1255"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="mydll" + ProjectGUID="{0B9466BC-60F8-4FC2-A1A9-6A01577690E5}" + RootNamespace="mydll" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + BrowseInformation="1" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="true" + GenerateMapFile="true" + MapFileName="$(TargetDir)$(TargetName).map" + MapExports="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <File + RelativePath=".\mydll.cpp" + > + </File> + <File + RelativePath=".\mydll.h" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Copied: pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj (from rev 1512, pyplusplus_dev/unittests/data/ctypes_pof/mydll.vcproj) =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj (rev 0) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.90.vcproj 2008-12-29 14:02:40 UTC (rev 1513) @@ -0,0 +1,182 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="9.00" + Name="mydll" + ProjectGUID="{E7A34C45-534F-43A6-AF95-3CA2428619E2}" + RootNamespace="mydll" + Keyword="Win32Proj" + TargetFrameworkVersion="196613" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="2" + WarningLevel="3" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="2" + EnableIntrinsicFunctions="true" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" + RuntimeLibrary="2" + EnableFunctionLevelLinking="true" + UsePrecompiledHeader="0" + BrowseInformation="1" + WarningLevel="3" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="true" + GenerateMapFile="true" + MapExports="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <File + RelativePath=".\mydll.cpp" + > + </File> + <File + RelativePath=".\mydll.h" + > + </File> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Modified: pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2008-12-29 14:02:40 UTC (rev 1513) @@ -49,6 +49,8 @@ int identity( int some_data){ return some_data;} +int identity_cpp( int data){ return data; } + BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved Modified: pyplusplus_dev/unittests/data/ctypes_pof/mydll.h =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.h 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.h 2008-12-29 14:02:40 UTC (rev 1513) @@ -31,4 +31,6 @@ int __declspec(dllexport) identity( int ); -} \ No newline at end of file +} + +int __declspec(dllexport) identity_cpp( int ); \ No newline at end of file Deleted: pyplusplus_dev/unittests/data/ctypes_pof/mydll.vcproj =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.vcproj 2008-12-28 20:45:32 UTC (rev 1512) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.vcproj 2008-12-29 14:02:40 UTC (rev 1513) @@ -1,182 +0,0 @@ -<?xml version="1.0" encoding="Windows-1252"?> -<VisualStudioProject - ProjectType="Visual C++" - Version="9.00" - Name="mydll" - ProjectGUID="{E7A34C45-534F-43A6-AF95-3CA2428619E2}" - RootNamespace="mydll" - Keyword="Win32Proj" - TargetFrameworkVersion="196613" - > - <Platforms> - <Platform - Name="Win32" - /> - </Platforms> - <ToolFiles> - </ToolFiles> - <Configurations> - <Configuration - Name="Debug|Win32" - OutputDirectory="$(SolutionDir)$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="2" - CharacterSet="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" - MinimalRebuild="true" - BasicRuntimeChecks="3" - RuntimeLibrary="3" - UsePrecompiledHeader="2" - WarningLevel="3" - DebugInformationFormat="4" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - LinkIncremental="2" - GenerateDebugInformation="true" - SubSystem="2" - TargetMachine="1" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - <Configuration - Name="Release|Win32" - OutputDirectory="$(SolutionDir)$(ConfigurationName)" - IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="2" - CharacterSet="1" - WholeProgramOptimization="1" - > - <Tool - Name="VCPreBuildEventTool" - /> - <Tool - Name="VCCustomBuildTool" - /> - <Tool - Name="VCXMLDataGeneratorTool" - /> - <Tool - Name="VCWebServiceProxyGeneratorTool" - /> - <Tool - Name="VCMIDLTool" - /> - <Tool - Name="VCCLCompilerTool" - Optimization="2" - EnableIntrinsicFunctions="true" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MYDLL_EXPORTS" - RuntimeLibrary="2" - EnableFunctionLevelLinking="true" - UsePrecompiledHeader="0" - BrowseInformation="1" - WarningLevel="3" - DebugInformationFormat="3" - /> - <Tool - Name="VCManagedResourceCompilerTool" - /> - <Tool - Name="VCResourceCompilerTool" - /> - <Tool - Name="VCPreLinkEventTool" - /> - <Tool - Name="VCLinkerTool" - LinkIncremental="1" - GenerateDebugInformation="true" - GenerateMapFile="true" - MapExports="true" - SubSystem="2" - OptimizeReferences="2" - EnableCOMDATFolding="2" - TargetMachine="1" - /> - <Tool - Name="VCALinkTool" - /> - <Tool - Name="VCManifestTool" - /> - <Tool - Name="VCXDCMakeTool" - /> - <Tool - Name="VCBscMakeTool" - /> - <Tool - Name="VCFxCopTool" - /> - <Tool - Name="VCAppVerifierTool" - /> - <Tool - Name="VCPostBuildEventTool" - /> - </Configuration> - </Configurations> - <References> - </References> - <Files> - <File - RelativePath=".\mydll.cpp" - > - </File> - <File - RelativePath=".\mydll.h" - > - </File> - </Files> - <Globals> - </Globals> -</VisualStudioProject> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2008-12-28 20:45:37
|
Revision: 1512 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1512&view=rev Author: roman_yakovenko Date: 2008-12-28 20:45:32 +0000 (Sun, 28 Dec 2008) Log Message: ----------- ctypes - another set of changes Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/class_declaration.py pygccxml_dev/pygccxml/declarations/dependencies.py pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/function_definition.py pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py pyplusplus_dev/unittests/ctypes_pof_tester.py pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp Added Paths: ----------- pyplusplus_dev/pyplusplus/code_creators/bookmark.py Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/class_declaration.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -537,4 +537,17 @@ , recursive=False , allow_empty=True ) ) + @property + def top_class( self ): + """reference to a parent class, which contains this class and defined + within a namespace + + if this class is defined under a namespace, self will be returned""" + curr = self + parent = self.parent + while isinstance( parent, class_t ): + curr = parent + parent = parent.parent + return curr + class_types = ( class_t, class_declaration_t ) Modified: pygccxml_dev/pygccxml/declarations/dependencies.py =================================================================== --- pygccxml_dev/pygccxml/declarations/dependencies.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pygccxml_dev/pygccxml/declarations/dependencies.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -19,21 +19,21 @@ self._depend_on_it = depend_on_it self._access_type = access_type self._hint = hint - + @property def declaration( self ): return self._declaration #short name decl = declaration - @property + @property def depend_on_it( self ): return self._depend_on_it - + def _get_access_type( self ): return self._access_type def _set_access_type( self, access_type ): - self._access_type = access_type + self._access_type = access_type access_type = property( _get_access_type, _set_access_type ) def __str__( self ): @@ -52,10 +52,27 @@ """ #prevent recursive import from pygccxml import declarations - + if isinstance( self.depend_on_it, declarations.declaration_t ): return self.depend_on_it base_type = declarations.base_type( declarations.remove_alias( self.depend_on_it ) ) if isinstance( base_type, cpptypes.declarated_t ): return base_type.declaration return None + + @staticmethod + def they_depend_on_us( decls ): + """returns set of declarations. every item in the returned set, depends on a + declaration from the input""" + import class_declaration #prevent cyclic imports + to_be_included = set() + for decl in decls: + for dependency_info in decl.i_depend_on_them(): + ddecl = dependency_info.find_out_depend_on_declaration() + if ddecl: + to_be_included.add( ddecl ) + + if isinstance( decl.parent, class_declaration.class_t ): + to_be_included.add( decl.parent ) + return to_be_included + Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -141,6 +141,8 @@ from ctypes_integration_creators import expose_this_t from ctypes_integration_creators import expose_sizeof_t +from bookmark import bookmark_t + #pure ctypes from ctypes_module import ctypes_module_t from import_ import import_t Added: pyplusplus_dev/pyplusplus/code_creators/bookmark.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/bookmark.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_creators/bookmark.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -0,0 +1,18 @@ +# Copyright 2004-2008 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 compound + +class bookmark_t(compound.compound_t): + def __init__( self, comment='' ): + compound.compound_t.__init__(self ) + self.comment = '' + + def _create_impl(self): + return compound.compound_t.create_internal_code( self.creators, indent_code=False ) + + def _get_system_headers_impl( self ): + return [] Modified: pyplusplus_dev/pyplusplus/code_creators/function_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -38,6 +38,7 @@ def _create_impl(self): result = [] result.append( '#%s' % self.undecorated_decl_name ) + result.append( '#TODO - unable to call C function, if dll was loaded as CPPDLL' ) result.append( '%(alias)s = %(library_var_name)s.%(alias)s' % dict( alias=self.declaration.alias , library_var_name=self.top_parent.library_var_name ) ) Modified: pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py =================================================================== --- pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -32,11 +32,14 @@ self.module = code_creators.ctypes_module_t( global_ns ) self.__dependencies_manager = dependencies_manager.manager_t(self.decl_logger) + self.__class_ccs = code_creators.bookmark_t() + #~ prepared_decls = self.__prepare_decls( global_ns, doc_extractor ) #~ self.__decls = sort_algorithms.sort( prepared_decls ) self.curr_decl = global_ns self.curr_code_creator = self.module self.__class2introduction = {} + self.__namespace2pyclass = {} def __print_readme( self, decl ): readme = decl.readme() @@ -97,14 +100,6 @@ if self.__contains_exported( internal_class ): self.__add_class_introductions( ci_creator, internal_class ) - # - implement better 0(n) algorithm - def __add_namespaces( self, cc, ns ): - ns_creator = code_creators.namespace_as_pyclass_t( ns ) - cc.adopt_creator( ns_creator ) - for internal_ns in ns.namespaces( recursive=False, allow_empty=True): - if self.__contains_exported( ns ): - self.__add_namespaces( ns_creator, internal_ns ) - def create(self ): """Create and return the module for the extension. @@ -119,17 +114,18 @@ ccc.adopt_creator( code_creators.name_mappings_t( self.__exported_symbols ) ) ccc.adopt_creator( code_creators.separator_t() ) #adding namespaces - for ns in self.global_ns.namespaces( recursive=False, allow_empty=True): - if self.__contains_exported( ns ): - self.__add_namespaces( ccc, ns ) - #adding class introductions + global_ns_cc = code_creators.bookmark_t() + ccc.adopt_creator( global_ns_cc ) + ccc.adopt_creator( self.__class_ccs ) + self.__namespace2pyclass[ self.global_ns ] = global_ns_cc + #adding class introductions - special case because of hierarchy f = lambda cls: self.__should_generate_code( cls ) \ and isinstance( cls.parent, declarations.namespace_t ) ns_classes = self.global_ns.classes( f, recursive=True, allow_empty=True) ns_classes = sort_algorithms.sort_classes( ns_classes ) for class_ in ns_classes: - if self.__contains_exported( ns ): - self.__add_class_introductions( ccc, class_ ) + if self.__contains_exported( class_ ): + self.__add_class_introductions( self.__class_ccs, class_ ) ccc.adopt_creator( code_creators.embedded_code_repository_t( code_repository.ctypes_cpp_utils ) ) @@ -174,6 +170,8 @@ def visit_class_declaration(self ): self.__dependencies_manager.add_exported( self.curr_decl ) + ci_creator = code_creators.class_introduction_t( self.curr_decl ) + self.curr_code_creator.adopt_creator( ci_creator ) def visit_class(self): self.__dependencies_manager.add_exported( self.curr_decl ) @@ -197,6 +195,11 @@ self.__dependencies_manager.add_exported( self.curr_decl ) def visit_namespace(self ): + if self.global_ns is not self.curr_decl: + ns_creator = code_creators.namespace_as_pyclass_t( self.curr_decl ) + self.__namespace2pyclass[ self.curr_decl ] = ns_creator + self.__namespace2pyclass[ self.curr_decl.parent ].adopt_creator( ns_creator ) + ns = self.curr_decl for decl in self.curr_decl.decls( recursive=False, allow_empty=True ): if isinstance( decl, declarations.namespace_t) or self.__should_generate_code( decl ): Modified: pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -84,15 +84,18 @@ undecorated = set( b2u.values() ) is_exported = lambda d: msvc.undecorate_decl( d ) in undecorated \ or d.name in b2u and b2u[d.name] == d.name #treatment of C functions - + #include exported declarations included_decls = set() included_decls.update( self.global_ns.calldefs( is_exported, allow_empty=True, recursive=True ) ) included_decls.update( self.global_ns.variables( is_exported, allow_empty=True, recursive=True ) ) - + #include declarations, on which exported declarations depend + they_depend_on_us = decls_package.dependency_info_t.they_depend_on_us + included_decls.update( they_depend_on_us( included_decls ) ) for d in included_decls: + print str(d) d.include() - if isinstance( d.parent, decls_package.class_t ): - d.parent.include() + if isinstance( d, decls_package.class_t ): + d.top_class.include() def build_code_creator( self, library_path, doc_extractor=None ): creator = creators_factory.ctypes_creator_t( self.global_ns Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -26,8 +26,8 @@ #mb.code_creator.create() sys.path.append( autoconfig.build_directory ) import ctypes_pof - print ctypes_pof.identity( 23 ) - self.failUnless( ctypes_pof.identity( 23 ) == 23 ) + #the following code fails - difference in the calling conventions + self.failUnless( ctypes_pof.identity( int(111) ) == 111 ) def create_suite(): suite = unittest.TestSuite() Modified: pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2008-12-28 20:45:32 UTC (rev 1512) @@ -47,7 +47,7 @@ void do_smth( number_aptr_t& ){ } -int identity( int i){ return i;} +int identity( int some_data){ return some_data;} BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2008-12-28 13:17:02
|
Revision: 1511 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1511&view=rev Author: roman_yakovenko Date: 2008-12-28 13:16:57 +0000 (Sun, 28 Dec 2008) Log Message: ----------- add handling for "C" functions Modified Paths: -------------- pygccxml_dev/pygccxml/msvc/common_utils.py pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/algorithm.py pyplusplus_dev/pyplusplus/code_creators/declaration_based.py pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py pyplusplus_dev/unittests/ctypes_pof_tester.py pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp pyplusplus_dev/unittests/data/ctypes_pof/mydll.h Added Paths: ----------- pyplusplus_dev/pyplusplus/code_creators/ctypes_formatter.py pyplusplus_dev/pyplusplus/code_creators/function_definition.py Modified: pygccxml_dev/pygccxml/msvc/common_utils.py =================================================================== --- pygccxml_dev/pygccxml/msvc/common_utils.py 2008-12-28 12:12:16 UTC (rev 1510) +++ pygccxml_dev/pygccxml/msvc/common_utils.py 2008-12-28 13:16:57 UTC (rev 1511) @@ -262,5 +262,5 @@ % fname ) @staticmethod - def is_c_function( decl, blob, undecorated_blob ): - return decl.name == blob == undecorated_blob + def is_c_function( decl, blob ): + return decl.name == blob Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-28 12:12:16 UTC (rev 1510) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-28 13:16:57 UTC (rev 1511) @@ -153,3 +153,4 @@ from fields_definition import fields_definition_t from embedded_code_repository import embedded_code_repository_t from methods_definition import methods_definition_t +from function_definition import c_function_definition_t Modified: pyplusplus_dev/pyplusplus/code_creators/algorithm.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/algorithm.py 2008-12-28 12:12:16 UTC (rev 1510) +++ pyplusplus_dev/pyplusplus/code_creators/algorithm.py 2008-12-28 13:16:57 UTC (rev 1511) @@ -11,7 +11,7 @@ from pyplusplus.decl_wrappers.algorithm import * -import types +import types import namespace def _make_flatten_list( creator_or_creators ): @@ -69,14 +69,14 @@ This class is used as container for different find algorithms. """ "creator_finder - this class used as namespace" - + @staticmethod def find_by_declaration( declaration_matcher, where, recursive=True ): - """Finds code creator by declaration. - declaration_matcher should be callable, that takes single argument + """Finds code creator by declaration. + declaration_matcher should be callable, that takes single argument declaration, and returns True or False where - code creator or list of code creators - This function returns a list of all relevant code creators + This function returns a list of all relevant code creators """ import declaration_based #prevent cyclic import search_area = where @@ -85,14 +85,14 @@ return filter( lambda inst: isinstance( inst, declaration_based.declaration_based_t ) \ and declaration_matcher( inst.declaration ) , search_area ) - + @staticmethod def find_by_declaration_single( declaration_matcher, where, recursive=True ): answer = creator_finder.find_by_declaration( declaration_matcher, where, recursive ) if len( answer ) == 1: return answer[0] return None - + @staticmethod def find_by_class_instance( what, where, recursive=True ): search_area = where @@ -101,4 +101,15 @@ return filter( lambda inst: isinstance( inst, what ), search_area ) def make_id_creator( code_creator ): - return lambda decl_string: create_identifier( code_creator, decl_string ) + return lambda decl_string: create_identifier( code_creator, decl_string ) + +def complete_py_name( decl ): + aliases = [] + current = decl + while current: + aliases.append( current.alias ) + current = current.parent + del aliases[-1] # :: from the global namespace + aliases.reverse() + return '.'.join( aliases ) + Added: pyplusplus_dev/pyplusplus/code_creators/ctypes_formatter.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/ctypes_formatter.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_creators/ctypes_formatter.py 2008-12-28 13:16:57 UTC (rev 1511) @@ -0,0 +1,145 @@ +# Copyright 2004-2008 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) + +""" +defines types visitor class interface +""" + +import algorithm +from pygccxml import declarations + +class type_converter_t(declarations.type_visitor_t): + """ + types visitor interface + + All functions within this class should be redefined in derived classes. + """ + def __init__(self, type_, decl_formatter): + declarations.type_visitor_t.__init__(self) + self.user_type = type_ + self.decl_formatter = decl_formatter + + def visit_void( self ): + return "None" + + def visit_char( self ): + return "ctypes.c_char" + + def visit_unsigned_char( self ): + return "ctypes.c_ubyte" + + def visit_signed_char( self ): + return "ctypes.c_byte" + + def visit_wchar( self ): + return "ctypes.c_wchar" + + def visit_short_int( self ): + return "ctypes.c_short" + + def visit_short_unsigned_int( self ): + return "ctypes.c_ushort" + + def visit_bool( self ): + return "ctypes.c_bool" + + def visit_int( self ): + return "ctypes.c_int" + + def visit_unsigned_int( self ): + return "ctypes.c_uint" + + def visit_long_int( self ): + return "ctypes.c_long" + + def visit_long_unsigned_int( self ): + return "ctypes.c_ulong" + + def visit_long_long_int( self ): + return "ctypes.c_longlong" + + def visit_long_long_unsigned_int( self ): + return "ctypes.c_ulonglong" + + def visit_float( self ): + return "ctypes.c_float" + + def visit_double( self ): + return "ctypes.c_double" + + def visit_long_double( self ): + return "ctypes.c_longdouble" + + #skip complex and jxxx types + + def visit_volatile( self ): + base_visitor = type_converter_t( self.user_type.base, self.decl_formatter ) + return declarations.apply_visitor( base_visitor, base_visitor.user_type ) + + def visit_const( self ): + base_visitor = type_converter_t( self.user_type.base, self.decl_formatter ) + return declarations.apply_visitor( base_visitor, base_visitor.user_type ) + + def visit_pointer( self ): + no_ptr = declarations.remove_const( declarations.remove_pointer( self.user_type ) ) + if declarations.is_same( declarations.char_t(), no_ptr ): + return "ctypes.c_char_p" + elif declarations.is_same( declarations.wchar_t(), no_ptr ): + return "ctypes.c_wchar_p" + elif declarations.is_same( declarations.void_t(), no_ptr ): + return "ctypes.c_void_p" + else: + base_visitor = type_converter_t( self.user_type.base, self.decl_formatter ) + internal_type_str = declarations.apply_visitor( base_visitor, base_visitor.user_type ) + return "ctypes.POINTER( %s )" % internal_type_str + + def visit_reference( self ): + no_ref = declarations.remove_const( declarations.remove_reference( self.user_type ) ) + if declarations.is_same( declarations.char_t(), no_ref ): + return "ctypes.c_char_p" + elif declarations.is_same( declarations.wchar_t(), no_ref ): + return "ctypes.c_wchar_p" + elif declarations.is_same( declarations.void_t(), no_ref ): + return "ctypes.c_void_p" + else: + base_visitor = type_converter_t( self.user_type.base, self.decl_formatter ) + internal_type_str = declarations.apply_visitor( base_visitor, base_visitor.user_type ) + return "ctypes.POINTER( %s )" % internal_type_str + + def visit_array( self ): + item_visitor = type_converter_t( declarations.array_item_type(self.user_type) + , self.decl_formatter ) + item_type = declarations.apply_visitor( item_visitor, item_visitor.user_type ) + size = declarations.array_size( self.user_type ) + if size == declarations.array_t.SIZE_UNKNOWN: + size = 0 + return "( %s * %d )" % ( item_type, size ) + + def visit_free_function_type( self ): + return_visitor = type_converter_t( self.return_type, self.decl_formatter ) + return_type = declarations.apply_visitor(return_visitor, self.return_type) + argtypes = [] + for arg in self.user_type.arguments_types: + arg_visitor = type_converter_t( arg, self.decl_formatter ) + argtypes.append( declarations.apply_visitor(arg_visitor, arg) ) + return declarations.call_invocation.join( "ctypes.CFUNCTYPE", [return_type] + argtypes ) + + #~ def visit_member_function_type( self ): + #~ raise NotImplementedError() + + #~ def visit_member_variable_type( self ): + #~ raise NotImplementedError() + + def visit_declarated( self ): + return self.decl_formatter( self.user_type.declaration ) + + def visit_restrict( self ): + base_visitor = type_converter_t( self.user_type.base, self.decl_formatter ) + return declarations.apply_visitor( base_visitor, base_visitor.user_type ) + +def as_ctype( type_, decl_formatter=algorithm.complete_py_name ): + v = type_converter_t( type_, decl_formatter ) + return declarations.apply_visitor( v, type_ ) + Property changes on: pyplusplus_dev/pyplusplus/code_creators/ctypes_formatter.py ___________________________________________________________________ Added: svn:mergeinfo + Modified: pyplusplus_dev/pyplusplus/code_creators/declaration_based.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/declaration_based.py 2008-12-28 12:12:16 UTC (rev 1510) +++ pyplusplus_dev/pyplusplus/code_creators/declaration_based.py 2008-12-28 13:16:57 UTC (rev 1511) @@ -48,14 +48,7 @@ @utils.cached def complete_py_name( self ): - aliases = [] - current = self.declaration - while current: - aliases.append( current.alias ) - current = current.parent - del aliases[-1] # :: from the global namespace - aliases.reverse() - return '.'.join( aliases ) + return algorithm.complete_py_name( self.declaration ) @property def decl_identifier( self ): Added: pyplusplus_dev/pyplusplus/code_creators/function_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/function_definition.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-28 13:16:57 UTC (rev 1511) @@ -0,0 +1,60 @@ +# Copyright 2004-2008 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 code_creator +import ctypes_formatter +import declaration_based +from pygccxml import declarations + +""" +BSCGetBaseArray = _libraries['msbsc70.dll'].BSCGetBaseArray +BSCGetBaseArray.restype = BOOL +BSCGetBaseArray.argtypes = [POINTER(Bsc), IINST, POINTER(POINTER(IINST)), POINTER(ULONG)] + +""" + +class c_function_definition_t(code_creator.code_creator_t, declaration_based.declaration_based_t): + def __init__( self, free_fun ): + code_creator.code_creator_t.__init__(self) + declaration_based.declaration_based_t.__init__( self, free_fun ) + + @property + def ftype( self ): + return self.declaration.function_type() + + def __join_args( self, args ): + args_str = '' + arg_separator = ', ' + if 1 == len( args ): + args_str = ' ' + args[0] + ' ' + else: + args_str = ' ' + arg_separator.join( args ) + ' ' + return '[%s]' % args_str + + + def _create_impl(self): + result = [] + result.append( '#%s' % self.undecorated_decl_name ) + result.append( '%(alias)s = %(library_var_name)s.%(alias)s' + % dict( alias=self.declaration.alias + , library_var_name=self.top_parent.library_var_name ) ) + + if not declarations.is_void( self.ftype.return_type ): + result.append( '%(alias)s.restype = %(restype)s' + % dict( alias=self.declaration.alias + , restype=ctypes_formatter.as_ctype( self.ftype.return_type ) ) ) + + if self.ftype.arguments_types: + tmp = [] + tmp.append( '%(alias)s.argtypes = ' % dict( alias=self.declaration.alias ) ) + args = map( ctypes_formatter.as_ctype, self.ftype.arguments_types ) + tmp.append( self.__join_args( args ) ) + result.append( ''.join( tmp ) ) + + return os.linesep.join( result ) + + def _get_system_headers_impl( self ): + return [] Modified: pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py =================================================================== --- pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-28 12:12:16 UTC (rev 1510) +++ pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-28 13:16:57 UTC (rev 1511) @@ -5,11 +5,12 @@ import sort_algorithms import dependencies_manager +from pygccxml import msvc +from pyplusplus import _logging_ from pygccxml import declarations from pyplusplus import decl_wrappers from pyplusplus import code_creators from pyplusplus import code_repository -from pyplusplus import _logging_ ACCESS_TYPES = declarations.ACCESS_TYPES VIRTUALITY_TYPES = declarations.VIRTUALITY_TYPES @@ -163,6 +164,10 @@ def visit_free_function( self ): self.__dependencies_manager.add_exported( self.curr_decl ) + if self.curr_decl.name in self.__exported_symbols \ + and self.curr_decl.name == self.__exported_symbols[ self.curr_decl.name ]: + #we deal with c function + self.curr_code_creator.adopt_creator( code_creators.c_function_definition_t( self.curr_decl ) ) def visit_free_operator( self ): self.__dependencies_manager.add_exported( self.curr_decl ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py 2008-12-28 12:12:16 UTC (rev 1510) +++ pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py 2008-12-28 13:16:57 UTC (rev 1511) @@ -29,12 +29,12 @@ if not self.print_details: return intend_txt = ' ' * (self.level+1) * self.INDENT_SIZE - self.writer( intend_txt + "Alias: " + self.instance.alias + os.linesep ) - self.writer( intend_txt + "Ignore: " + str( self.instance.ignore ) + os.linesep ) + self.writer( intend_txt + "alias: " + self.instance.alias + os.linesep ) + self.writer( intend_txt + "ignore: " + str( self.instance.ignore ) + os.linesep ) if not self.instance.ignore: msgs = self.instance.readme() if msgs: - self.writer( intend_txt + "ReadMe: " + os.linesep ) + self.writer( intend_txt + "readme: " + os.linesep ) more_intend_txt = ' ' * (self.level+2) * self.INDENT_SIZE for msg in msgs: self.writer( more_intend_txt + msg + os.linesep ) @@ -43,13 +43,19 @@ if not self.print_details: return self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Call policies: " + str(self.instance.call_policies) + os.linesep ) + + "call policies: " + str(self.instance.call_policies) + os.linesep ) self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Use keywords: " + str(self.instance.use_keywords) + os.linesep ) + + "use keywords: " + str(self.instance.use_keywords) + os.linesep ) self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Use signature: " + str(self.instance.create_with_signature) + os.linesep ) + + "use signature: " + str(self.instance.create_with_signature) + os.linesep ) self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Use default arguments: " + str(self.instance.use_default_arguments) + os.linesep ) + + "use default arguments: " + str(self.instance.use_default_arguments) + os.linesep ) + try: + from pygccxml import msvc + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + + "undecorated decl: " + msvc.undecorate_decl(self.instance) + os.linesep ) + except: + pass def visit_member_function( self ): super( decl_wrapper_printer_t, self ).visit_member_function() @@ -85,22 +91,22 @@ def visit_class(self ): super( decl_wrapper_printer_t, self ).visit_class() self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Expose using scope: " + str(self.instance.always_expose_using_scope) + os.linesep ) + + "expose using scope: " + str(self.instance.always_expose_using_scope) + os.linesep ) self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Redefine operators: " + str(self.instance.redefine_operators) + os.linesep ) + + "redefine operators: " + str(self.instance.redefine_operators) + os.linesep ) self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Held type: " + str(self.instance.held_type) + os.linesep ) + + "held type: " + str(self.instance.held_type) + os.linesep ) self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Use noncopyable: " + str(self.instance.noncopyable) + os.linesep ) + + "use noncopyable: " + str(self.instance.noncopyable) + os.linesep ) self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Class wrapper alias: " + str(self.instance.wrapper_alias) + os.linesep ) + + "class wrapper alias: " + str(self.instance.wrapper_alias) + os.linesep ) def visit_enumeration(self): super( decl_wrapper_printer_t, self ).visit_enumeration() self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Enumeration value aliases: " + str(self.instance.value_aliases) + os.linesep ) + + "enumeration value aliases: " + str(self.instance.value_aliases) + os.linesep ) self.writer( ' ' * (self.level+1) * self.INDENT_SIZE - + "Enumeration export values: " + str(self.instance.export_values) + os.linesep ) + + "enumeration export values: " + str(self.instance.export_values) + os.linesep ) def visit_namespace(self ): super( decl_wrapper_printer_t, self ).visit_namespace() Modified: pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2008-12-28 12:12:16 UTC (rev 1510) +++ pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2008-12-28 13:16:57 UTC (rev 1511) @@ -80,8 +80,10 @@ def __include_declarations( self ): self.global_ns.exclude() - undecorated = set( self.__blob2undecorated.values() ) - is_exported = lambda d: msvc.undecorate_decl( d ) in undecorated + b2u = self.__blob2undecorated + undecorated = set( b2u.values() ) + is_exported = lambda d: msvc.undecorate_decl( d ) in undecorated \ + or d.name in b2u and b2u[d.name] == d.name #treatment of C functions included_decls = set() included_decls.update( self.global_ns.calldefs( is_exported, allow_empty=True, recursive=True ) ) Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-28 12:12:16 UTC (rev 1510) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-28 13:16:57 UTC (rev 1511) @@ -20,14 +20,15 @@ def test(self): mb = ctypes_module_builder_t( [self.header], self.symbols_file, autoconfig.cxx_parsers_cfg.gccxml ) - #~ mb.global_ns.include() + #~ mb.print_declarations() mb.build_code_creator( self.symbols_file ) mb.write_module( os.path.join( autoconfig.build_directory, self.module_name + '.py' ) ) #mb.code_creator.create() sys.path.append( autoconfig.build_directory ) import ctypes_pof + print ctypes_pof.identity( 23 ) + self.failUnless( ctypes_pof.identity( 23 ) == 23 ) - def create_suite(): suite = unittest.TestSuite() if 'win' in sys.platform: Modified: pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2008-12-28 12:12:16 UTC (rev 1510) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2008-12-28 13:16:57 UTC (rev 1511) @@ -47,6 +47,8 @@ void do_smth( number_aptr_t& ){ } +int identity( int i){ return i;} + BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved Modified: pyplusplus_dev/unittests/data/ctypes_pof/mydll.h =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.h 2008-12-28 12:12:16 UTC (rev 1510) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.h 2008-12-28 13:16:57 UTC (rev 1511) @@ -26,3 +26,9 @@ typedef std::auto_ptr< pof::number_t > number_aptr_t; void __declspec(dllexport) do_smth( number_aptr_t& ); + +extern "C"{ + +int __declspec(dllexport) identity( int ); + +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2008-12-28 12:12:24
|
Revision: 1510 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1510&view=rev Author: roman_yakovenko Date: 2008-12-28 12:12:16 +0000 (Sun, 28 Dec 2008) Log Message: ----------- improve printing Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/decl_printer.py Modified: pygccxml_dev/pygccxml/declarations/decl_printer.py =================================================================== --- pygccxml_dev/pygccxml/declarations/decl_printer.py 2008-12-28 12:09:49 UTC (rev 1509) +++ pygccxml_dev/pygccxml/declarations/decl_printer.py 2008-12-28 12:12:16 UTC (rev 1510) @@ -102,24 +102,24 @@ def print_decl_header(self): header = self.__nice_decl_name( self.__inst ) + ": '%s'" % self.__inst.name - self.writer( ' ' * self.level * self.INDENT_SIZE + header.ljust( self.JUSTIFY )) + self.writer( ' ' * self.level * self.INDENT_SIZE + header.ljust( self.JUSTIFY ) + os.linesep) if self.__print_details: curr_level = self.level + 1 if self.__inst.location: location = 'location: [%s]:%s'%(self.__inst.location.file_name, self.__inst.location.line) - self.writer( ' ' * curr_level * self.INDENT_SIZE + location) + self.writer( ' ' * curr_level * self.INDENT_SIZE + location + os.linesep) if self.verbose: artificial = 'artificial: ' + "'%s'" % str(self.__inst.is_artificial) - self.writer( ' ' * curr_level * self.INDENT_SIZE + artificial.ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + artificial.ljust( self.JUSTIFY ) + os.linesep) if self.verbose and self.__inst.attributes: attributes = 'attributes: %s'%(self.__inst.attributes) - self.writer( ' ' * curr_level * self.INDENT_SIZE + attributes) + self.writer( ' ' * curr_level * self.INDENT_SIZE + attributes + os.linesep) if self.verbose and self.__inst.demangled: demangled = 'demangled: %s'%(self.__inst.demangled) - self.writer( ' ' * curr_level * self.INDENT_SIZE + demangled) + self.writer( ' ' * curr_level * self.INDENT_SIZE + demangled + os.linesep) if self.verbose and self.__inst.mangled: mangled = 'mangled: %s'%(self.__inst.mangled) - self.writer( ' ' * curr_level * self.INDENT_SIZE + mangled) + self.writer( ' ' * curr_level * self.INDENT_SIZE + mangled + os.linesep) def print_calldef_info(self, decl=None): """ Returns function signature: [retval, [arg1, ..., argN]]. """ @@ -133,12 +133,13 @@ for arg in decl.arguments: args.append(arg.type.decl_string + ' ' + arg.name) indent = ' ' * (self.level+1) * self.INDENT_SIZE - self.writer( indent + "return type: " + str(retval) ) - self.writer( indent + "arguments type: " + ', '.join(args)) + self.writer( indent + "is extern: " + str(decl.has_extern) + os.linesep) + self.writer( indent + "return type: " + str(retval) + os.linesep) + self.writer( indent + "arguments type: " + ', '.join(args) + os.linesep) if isinstance( decl, calldef.member_calldef_t ): - self.writer( indent + "virtual: " + str(decl.virtuality)) - self.writer( indent + "is const: " + str(decl.has_const)) - self.writer( indent + "is static: " + str(decl.has_static)) + self.writer( indent + "virtual: " + str(decl.virtuality) + os.linesep) + self.writer( indent + "is const: " + str(decl.has_const) + os.linesep) + self.writer( indent + "is static: " + str(decl.has_static) + os.linesep) def visit_member_function( self ): self.print_decl_header() @@ -150,7 +151,7 @@ if self.__print_details: self.writer( ' ' * ( self.level + 1 ) * self.INDENT_SIZE - + 'copy constructor: ' + str(self.__inst.is_copy_constructor) ) + + 'copy constructor: ' + str(self.__inst.is_copy_constructor) + os.linesep) def visit_destructor( self ): self.print_decl_header() @@ -178,36 +179,36 @@ self.print_decl_header() curr_level = self.level + 1 class_type = 'class type: ' + "'%s'" % str(self.__inst.class_type) - self.writer( ' ' * curr_level * self.INDENT_SIZE + class_type.ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + class_type.ljust( self.JUSTIFY ) + os.linesep) if self.__print_details: byte_size = 'size: %d'%(self.__inst.byte_size) - self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_size.ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_size.ljust( self.JUSTIFY ) + os.linesep) try: byte_align = 'align: %d'%(self.__inst.byte_align) - self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_align.ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_align.ljust( self.JUSTIFY ) + os.linesep) except NotImplementedError: - self.writer( ' ' * curr_level * self.INDENT_SIZE + "align: not implemented".ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + "align: not implemented".ljust( self.JUSTIFY ) + os.linesep) if self.__inst.aliases: aliases = map( lambda typedef: typedef.name, self.__inst.aliases ) aliases.sort() msg = 'aliases: ' + `aliases` - self.writer( ' ' * curr_level * self.INDENT_SIZE + msg.ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + msg.ljust( self.JUSTIFY ) + os.linesep) def print_hierarchy(hierarchy_type, classes, curr_level): - self.writer( ' ' * curr_level * self.INDENT_SIZE + hierarchy_type.ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + hierarchy_type.ljust( self.JUSTIFY ) + os.linesep) curr_level += 1 for class_ in classes: class_str = 'class: ' + "'%s'" % str(class_.related_class.decl_string) - self.writer( ' ' * curr_level * self.INDENT_SIZE + class_str.ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + class_str.ljust( self.JUSTIFY ) + os.linesep) access = 'access type: ' + "'%s'" % str(class_.access) - self.writer( ' ' * (curr_level + 1)* self.INDENT_SIZE + access.ljust( self.JUSTIFY )) + self.writer( ' ' * (curr_level + 1)* self.INDENT_SIZE + access.ljust( self.JUSTIFY ) + os.linesep) if not ( None is class_.is_virtual ): is_virtual = 'virtual inheritance: ' + "'%s'" % str(class_.is_virtual) - self.writer( ' ' * (curr_level + 1)* self.INDENT_SIZE + is_virtual.ljust( self.JUSTIFY )) + self.writer( ' ' * (curr_level + 1)* self.INDENT_SIZE + is_virtual.ljust( self.JUSTIFY ) + os.linesep) def print_members(members_type, members, curr_level): - self.writer( ' ' * curr_level * self.INDENT_SIZE + members_type.ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + members_type.ljust( self.JUSTIFY ) + os.linesep) if self.__recursive: curr_level += 1 for member in members: @@ -228,11 +229,11 @@ def visit_enumeration(self): self.print_decl_header() curr_level = self.level + 1 - self.writer( ' ' * curr_level * self.INDENT_SIZE + 'values:'.ljust( self.JUSTIFY ) ) + self.writer( ' ' * curr_level * self.INDENT_SIZE + 'values:'.ljust( self.JUSTIFY ) + os.linesep) value_level = ' ' * ( curr_level + 1 )* self.INDENT_SIZE - self.writer( os.linesep ) + self.writer( os.linesep + os.linesep) for name, value in self.__inst.values: - self.writer( value_level + "%s : %s"% (name, value)) + self.writer( value_level + "%s : %s"% (name, value) + os.linesep) def visit_namespace(self ): if self.verbose == False and not self.__inst.declarations: @@ -249,22 +250,22 @@ def visit_typedef(self ): self.print_decl_header() curr_level = self.level + 1 - self.writer( ' ' * curr_level * self.INDENT_SIZE + 'alias to: ' + self.__inst.type.decl_string) + self.writer( ' ' * curr_level * self.INDENT_SIZE + 'alias to: ' + self.__inst.type.decl_string + os.linesep) def visit_variable(self ): self.print_decl_header() curr_level = self.level + 1 - self.writer( ' ' * curr_level * self.INDENT_SIZE + 'type: %s value: %s'%(self.__inst.type.decl_string, self.__inst.value) ) + self.writer( ' ' * curr_level * self.INDENT_SIZE + 'type: %s value: %s'%(self.__inst.type.decl_string, self.__inst.value) + os.linesep) if self.__print_details: byte_size = 'size: %d'%(self.__inst.type.byte_size) - self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_size.ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_size.ljust( self.JUSTIFY ) + os.linesep) try: byte_align = 'align: %d'%(self.__inst.type.byte_align) - self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_align.ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_align.ljust( self.JUSTIFY ) + os.linesep) except NotImplementedError: - self.writer( ' ' * curr_level * self.INDENT_SIZE + "align: not implemented".ljust( self.JUSTIFY )) + self.writer( ' ' * curr_level * self.INDENT_SIZE + "align: not implemented".ljust( self.JUSTIFY ) + os.linesep) byte_offset = 'offset: %d'%(self.__inst.byte_offset) - self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_offset + os.linesep) + self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_offset + os.linesep + os.linesep) def print_declarations( decls , detailed=True This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2008-12-28 12:09:53
|
Revision: 1509 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1509&view=rev Author: roman_yakovenko Date: 2008-12-28 12:09:49 +0000 (Sun, 28 Dec 2008) Log Message: ----------- add handling for "C" functions Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/algorithm.py pygccxml_dev/pygccxml/msvc/common_utils.py pygccxml_dev/unittests/data/msvc/mydll.cpp pygccxml_dev/unittests/data/msvc/mydll.h pygccxml_dev/unittests/undname_creator_tester.py Modified: pygccxml_dev/pygccxml/declarations/algorithm.py =================================================================== --- pygccxml_dev/pygccxml/declarations/algorithm.py 2008-12-27 21:16:17 UTC (rev 1508) +++ pygccxml_dev/pygccxml/declarations/algorithm.py 2008-12-28 12:09:49 UTC (rev 1509) @@ -331,4 +331,4 @@ fname = 'visit_' + decl_inst.__class__.__name__[:-2] #removing '_t' from class name if not hasattr(visitor, fname ): raise visit_function_has_not_been_found_t( visitor, decl_inst ) - getattr( visitor, fname )() + return getattr( visitor, fname )() Modified: pygccxml_dev/pygccxml/msvc/common_utils.py =================================================================== --- pygccxml_dev/pygccxml/msvc/common_utils.py 2008-12-27 21:16:17 UTC (rev 1508) +++ pygccxml_dev/pygccxml/msvc/common_utils.py 2008-12-28 12:09:49 UTC (rev 1509) @@ -199,22 +199,38 @@ exceptions.UserWarning.__init__( self, *args, **keywd ) class exported_symbols: - map_file_re = re.compile( r' +\d+ (?P<decorated>.+?) \((?P<undecorated>.+)\)$' ) + map_file_re_c = re.compile( r' +\d+ (?P<internall>.+?)(?:\s+exported name\:\s(?P<name>.*)$)') + map_file_re_cpp = re.compile( r' +\d+ (?P<decorated>.+?) \((?P<undecorated>.+)\)$' ) + @staticmethod def load_from_map_file( fname ): """returns dictionary { decorated symbol : orignal declaration name }""" result = {} f = open( fname ) - exports_started = False + lines = [] + was_exports = False for line in f: - if not exports_started: - exports_started = bool( 'Exports' == line.strip() ) - if not exports_started: - continue - line = line.rstrip() - found = exported_symbols.map_file_re.match( line ) + if was_exports: + lines.append( line ) + elif 'Exports' == line.strip(): + was_exports = True + else: + pass + index = 0 + while index < len( lines ): + line = lines[index].rstrip() + found = exported_symbols.map_file_re_cpp.match( line ) if found: result[ found.group( 'decorated' ) ] = found.group( 'undecorated' ) + elif index + 1 < len( lines ): + two_lines = line + lines[index+1].rstrip() + found = exported_symbols.map_file_re_c.match( two_lines ) + if found: + result[ found.group( 'name' ) ] = found.group( 'name' ) + index += 1 + else: + pass + index += 1 return result @staticmethod @@ -244,3 +260,7 @@ else: raise RuntimeError( "Don't know how to read exported symbols from file '%s'" % fname ) + + @staticmethod + def is_c_function( decl, blob, undecorated_blob ): + return decl.name == blob == undecorated_blob Modified: pygccxml_dev/unittests/data/msvc/mydll.cpp =================================================================== --- pygccxml_dev/unittests/data/msvc/mydll.cpp 2008-12-27 21:16:17 UTC (rev 1508) +++ pygccxml_dev/unittests/data/msvc/mydll.cpp 2008-12-28 12:09:49 UTC (rev 1509) @@ -97,6 +97,9 @@ return TRUE; } +int identity( int i){ + return i; +} /* void __cdecl Fv_v_cdecl(void) Modified: pygccxml_dev/unittests/data/msvc/mydll.h =================================================================== --- pygccxml_dev/unittests/data/msvc/mydll.h 2008-12-27 21:16:17 UTC (rev 1508) +++ pygccxml_dev/unittests/data/msvc/mydll.h 2008-12-28 12:09:49 UTC (rev 1509) @@ -104,3 +104,7 @@ __declspec(dllexport) long Fv_l(void); __declspec(dllexport) short Fv_s(void); __declspec(dllexport) void Fv_v(void); + +extern "C"{ + int __declspec(dllexport) identity( int ); +} \ No newline at end of file Modified: pygccxml_dev/unittests/undname_creator_tester.py =================================================================== --- pygccxml_dev/unittests/undname_creator_tester.py 2008-12-27 21:16:17 UTC (rev 1508) +++ pygccxml_dev/unittests/undname_creator_tester.py 2008-12-28 12:09:49 UTC (rev 1509) @@ -15,6 +15,8 @@ from pygccxml import parser from pygccxml import declarations +print msvc.undecorate_blob( '?make_flatten@algorithms@reflection@engine_objects@@YAXAEBVinstance_info_t@23@V?$back_insert_iterator@V?$vector@Vinstance_info_t@reflection@engine_objects@@V?$allocator@Vinstance_info_t@reflection@engine_objects@@@std@@@std@@@std@@@Z' ) + class tester_t( parser_test_case.parser_test_case_t ): global_ns = None @@ -50,6 +52,7 @@ def __tester_impl( self, fname ): symbols = msvc.exported_symbols.load_from_file( fname ) + self.failUnless( 'identity' in symbols ) undecorated_blob_names = set() for blob in symbols.iterkeys(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2008-12-27 21:16:23
|
Revision: 1508 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1508&view=rev Author: roman_yakovenko Date: 2008-12-27 21:16:17 +0000 (Sat, 27 Dec 2008) Log Message: ----------- porting latest changes to Linux Modified Paths: -------------- pyplusplus_dev/unittests/autoconfig.py Modified: pyplusplus_dev/unittests/autoconfig.py =================================================================== --- pyplusplus_dev/unittests/autoconfig.py 2008-12-27 10:57:29 UTC (rev 1507) +++ pyplusplus_dev/unittests/autoconfig.py 2008-12-27 21:16:17 UTC (rev 1508) @@ -42,7 +42,7 @@ class scons_config: - libs = []#['boost_python'] + libs = [] libpath = [ python.libs ] + boost.libs cpppath = [ boost.include, python.include, indexing_suite.include ] include_dirs = cpppath + [data_directory] @@ -52,6 +52,8 @@ msvc_compiler = '' if 'linux' not in sys.platform: msvc_compiler = str( pygccxml.utils.native_compiler.get_version()[1] ) + else: + scons_config.libs.append( 'boost_python' ) code = [ "import sys" , "env = Environment()" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |