def __generate_root_header(self, namespace_generators: [], file_cache: FileCache): if self.params_description.root_header and self.api_description.project_name: root_header = FileGenerator(os.path.join(self.output_folder, self.params_description.root_header)) root_header.put_begin_cpp_comments(self.params_description) with WatchdogScope(root_header, self.api_description.project_name.upper() + '_LIBRARY_ROOT_INCLUDED'): with IfDefScope(root_header, '{0}_LIBRARY_USE_DYNAMIC_LOADER'.format( self.api_description.project_name.upper()), False): for namespace_generator in namespace_generators: root_header.put_line('#define {0}_CAPI_USE_DYNAMIC_LOADER'.format( namespace_generator.wrap_name.upper())) root_header.put_line('') with IfDefScope(root_header, '{0}_LIBRARY_DEFINE_FUNCTION_POINTERS'.format( self.api_description.project_name.upper()), False): for namespace_generator in namespace_generators: root_header.put_line('#define {0}_CAPI_DEFINE_FUNCTION_POINTERS'.format( namespace_generator.wrap_name.upper())) root_header.put_line('') root_header.put_include_files(False) for namespace_generator in namespace_generators: root_header.include_user_header(file_cache.namespace_header(namespace_generator.full_name_array)) if self.params_description.root_header_initializer: root_header.put_line('') with IfDefScope(root_header, '__cplusplus'): if self.params_description.root_header_namespace: root_header.put_line('namespace {0}'.format(self.params_description.root_header_namespace)) with IndentScope(root_header): self.__generate_root_initializer(root_header, namespace_generators) else: self.__generate_root_initializer(root_header, namespace_generators)
def __generate_root_initializer(self, out: FileGenerator, namespace_generators: []): out.put_line('class {0}'.format(self.params_description.root_header_initializer)) with IndentScope(out, '};'): member_names = [] for namespace_generator in namespace_generators: member_name = namespace_generator.wrap_name.lower() + '_module_init' out.put_line('{namespace}::Initialization {member};'.format( namespace=namespace_generator.wrap_name, member=member_name)) member_names.append(member_name) out.put_line('') if not self.params_description.shared_library_name: out.put_line('{0}();'.format(self.params_description.root_header_initializer)) with Unindent(out): out.put_line('public:') if member_names: with IfDefScope(out, '{0}_LIBRARY_USE_DYNAMIC_LOADER'.format( self.api_description.project_name.upper()), False): out.put_line('{0}(const char* shared_library_name) :'.format( self.params_description.root_header_initializer)) with Indent(out): for member_name in member_names[:-1]: out.put_line('{member_name}(shared_library_name),'.format(member_name=member_name)) out.put_line('{member_name}(shared_library_name)'.format(member_name=member_names[-1])) with IndentScope(out): pass if self.params_description.shared_library_name: out.put_line('{0}()'.format(self.params_description.root_header_initializer)) with IndentScope(out): pass
def __generate_definition(self): definition_header = self.file_cache.get_file_for_class( self.full_name_array) definition_header.put_begin_cpp_comments(self.params) watchdog_string = '_'.join( [item.upper() for item in self.full_name_array]) + '_DEFINITION_INCLUDED' with WatchdogScope(definition_header, watchdog_string): definition_header.put_include_files() definition_header.include_user_header( self.file_cache.class_header_decl(self.full_name_array)) if self.base_class_generator: definition_header.include_user_header( self.file_cache.class_header( self.base_class_generator.full_name_array)) with IfDefScope(definition_header, '__cplusplus'): first_method = True first_method = self.__generate_constructor_definitions( definition_header, first_method) self.__generate_method_definitions(definition_header, first_method) definition_header.put_line('') self.lifecycle_traits.generate_std_methods_definitions( definition_header, self) if hasattr(self, 'extension_base_class_generator'): definition_header.put_line('') self.__generate_cast_name_definition(definition_header) definition_header.put_line('') self.inheritance_traits.generate_set_object_definition( definition_header, self) self.__generate_down_cast_definitions(definition_header) generate_callbacks_on_client_side_definitions( definition_header, self)
def __generate_declaration(self): declaration_header = self.file_cache.get_file_for_class_decl( self.full_name_array) declaration_header.put_begin_cpp_comments(self.params) watchdog_string = '_'.join( [item.upper() for item in self.full_name_array]) + '_DECLARATION_INCLUDED' with WatchdogScope(declaration_header, watchdog_string): declaration_header.put_include_files() declaration_header.include_user_header( self.file_cache.capi_header(self.full_name_array)) declaration_header.include_user_header( self.file_cache.fwd_header(self.full_name_array)) with IfDefScope(declaration_header, '__cplusplus'): declaration_header.put_line( self.parent_namespace.one_line_namespace_begin) declaration_header.put_line('') self.__generate_class_declaration(declaration_header) declaration_header.put_line('') declaration_header.put_line( self.parent_namespace.one_line_namespace_end) self.__generate_down_cast_template_declarations( declaration_header) include_headers(declaration_header, self.class_object.include_headers)
def generate_move_constructor_declaration(self, out: FileGenerator, class_generator): if self.params.enable_cpp11_features_in_wrap_code: with IfDefScope(out, get_has_rvalue_references(class_generator), False): out.put_line( 'inline {class_short_name}({class_name}&& other);'.format( class_short_name=class_generator.wrap_short_name, class_name=class_generator.wrap_name))
def __generate_namespace_enumerators(self, namespace_header): if self.enum_generators: with IfDefScope(namespace_header, '__cplusplus'): namespace_header.put_line(self.one_line_namespace_begin) namespace_header.put_line('') for enum_generator in self.enum_generators: enum_generator.generate_enum_definition(namespace_header) namespace_header.put_line('') namespace_header.put_line(self.one_line_namespace_end) namespace_header.put_line('')
def generate(self, out: FileGenerator): out.put_line('') with IfDefScope(out, '__cplusplus'): out.put_line('#include <stdexcept>') out.put_line('#include <sstream>') out.put_line('') # We always have at least one element out.put_line('namespace {0}'.format( self.namespace_info.namespace_name_array[0])) with IndentScope(out): self.__generate_body(out)
def __generate_forward_declarations(self, file_cache: FileCache, capi_generator: CapiGenerator): forward_declarations = file_cache.get_file_for_fwd( self.full_name_array) forward_declarations.put_begin_cpp_comments(self.params) with WatchdogScope(forward_declarations, self.full_name.upper() + '_FWD_INCLUDED'): with IfDefScope(forward_declarations, '__cplusplus'): if self.params.enable_cpp11_features_in_wrap_code: forward_declarations.put_include_files() forward_declarations.include_system_header('utility') capi_generator.main_exception_traits.generate_check_and_throw_exception_forward_declaration( forward_declarations) self.__generate_forward_declarations_impl(forward_declarations)
def generate_move_constructor_definition(self, out: FileGenerator, class_generator): if self.params.enable_cpp11_features_in_wrap_code: with IfDefScope(out, get_has_rvalue_references(class_generator), False): out.put_line( 'inline {namespace}::{class_short_name}({class_name}&& other){base_init}' .format(namespace=class_generator.full_wrap_name, class_short_name=class_generator.wrap_short_name, class_name=class_generator.wrap_name, base_init=get_base_move_init(class_generator))) with IndentScope(out): class_generator.inheritance_traits.generate_object_assignment( out, class_generator, '', 'other.mObject') class_generator.inheritance_traits.generate_object_assignment( out, class_generator, 'other.', '0')
def generate_check_and_throw_exception(self, file_cache: FileCache): out = file_cache.get_file_for_check_and_throw_exception() out.put_begin_cpp_comments(self.params) with WatchdogScope(out, self.params.beautiful_capi_namespace.upper() + '_CHECK_AND_THROW_EXCEPTION_INCLUDED'): with IfDefScope(out, '__cplusplus'): out.put_include_files() out.include_system_header('stdexcept') out.include_system_header('cassert') for exception_class in self.exception_classes: out.include_user_header( file_cache.class_header(exception_class.full_name_array)) out.put_line('namespace {0}'.format(self.params.beautiful_capi_namespace)) with IndentScope(out): out.put_line( 'inline void check_and_throw_exception(uint32_t exception_code, void* exception_object)') with IndentScope(out): self.__create_check_and_throw_exceptions_body(out, ByFirstArgument.__generate_throw_wrap)
def __generate_namespace_functions(self, capi_generator, file_cache, namespace_header): if self.functions: with IfDefScope(namespace_header, '__cplusplus'): namespace_header.put_line(self.one_line_namespace_begin) namespace_header.put_line('') for function_generator in self.functions: DoxygenCppGenerator().generate_for_routine( namespace_header, function_generator.function_object, function_generator) function_generator.generate_wrap_definition( namespace_header, capi_generator) function_generator.generate_c_function(capi_generator) function_generator.include_dependent_definition_headers( namespace_header, file_cache) function_generator.include_dependent_implementation_headers( capi_generator) namespace_header.put_line('') namespace_header.put_line(self.one_line_namespace_end)
def __generate_move_assignment_definition(self, out: FileGenerator, class_generator): if self.params.enable_cpp11_features_in_wrap_code: with IfDefScope(out, get_has_rvalue_references(class_generator), False): out.put_line( 'inline {class_name}& {class_name}::operator=({class_name}&& other)' .format(class_name=class_generator.full_wrap_name)) with IndentScope(out): out.put_line('if (this != &other)') with IndentScope(out): if class_generator.base_class_generator: out.put_line( '{0}::operator=(std::move(other));'.format( class_generator.base_class_generator. full_wrap_name)) class_generator.inheritance_traits.generate_object_assignment( out, class_generator, '', 'other.mObject') class_generator.inheritance_traits.generate_object_assignment( out, class_generator, 'other.', '0') out.put_line('return *this;')
def __generate_body(self, out: FileGenerator): out.put_line('class Initialization') with IndentScope(out, '};'): self.__generate_members(out) self.__generate_load_function(out) self.__generate_load_module(out) if not self.params.shared_library_name: out.put_line('Initialization();') out.put_line('Initialization(const Initialization&);') if self.params.enable_cpp11_features_in_wrap_code: move_constructors_delete_condition = '{ns}_CPP_COMPILER_HAS_MOVE_CONSTRUCTOR_DELETE'.format( ns=self.namespace_name) with IfDefScope(out, move_constructors_delete_condition, False): with Indent(out): out.put_line( 'Initialization(Initialization &&) = delete;') with Unindent(out): out.put_line('public:') self.__generate_constructor(out) self.__generate_destructor(out)
def generate_std_methods_declarations(self, out: FileGenerator, class_generator): self.__create_exception_traits(class_generator) out.put_line( 'inline {class_name}& operator=(const {class_name}& other);'. format(class_name=class_generator.wrap_name)) if self.params.enable_cpp11_features_in_wrap_code: with IfDefScope(out, get_has_rvalue_references(class_generator), False): out.put_line( 'inline {class_name}& operator=({class_name}&& other);'. format(class_name=class_generator.wrap_name)) out.put_line('static inline {class_name} {null_method}();'.format( class_name=class_generator.wrap_name, null_method=self.params.null_method_name)) out.put_line('inline bool {0}() const;'.format( self.params.is_null_method_name)) out.put_line('inline bool {0}() const;'.format( self.params.is_not_null_method_name)) out.put_line('inline bool operator!() const;') out.put_line('inline void* {detach_method}();'.format( detach_method=self.params.detach_method_name)) out.put_line('inline void* {get_raw_pointer_method}() const;'.format( get_raw_pointer_method=self.params.get_raw_pointer_method_name))
def __generate_compiler_traits(self, out: FileGenerator): if self.params.enable_cpp11_features_in_wrap_code: with IfDefScope(out, '__cplusplus', False): with Indent(out): if_def_then_else(out, '_MSC_VER', self.__generate_msvc_traits, self.__generate_non_msvc_traits) out.put_line('')