Esempio n. 1
0
    def generate_implementation(self):
        """Generates C++ Object implementation.
        """
        file_path = io_utils.cpp_object_implementation_path(self.__group_name, self.__class_name)
        output_cc = open(file_path, 'w')

        cpp_include = '#include "{0}.h"\n\n#include "json11/json11.hpp"'.format(self.__header_file_name())
        cpp_using = 'using std::string;\nusing std::unique_ptr;\nusing std::vector;'
        cpp_public_mark = '////////////////////////////////////////////////////////////////////////////////\n// ' \
                          '{0}, public:'.format(self.__class_name)

        output_cc.write(cpp_include + _CPP_BR)
        output_cc.write(cpp_using + _CPP_BR)
        output_cc.write(self.__config.cpp_ns_begin + _CPP_BR)
        output_cc.write(cpp_public_mark + _CPP_BR)

        output_cc.write(_CPP_LIFECYCLE_SPLIT + _CPP_BR)
        output_cc.write(self.__constructor_implementation() + _CPP_BR)
        output_cc.write(self.__deconstructor_implementation() + _CPP_BR)
        output_cc.write(self.__init_method_implementation() + _CPP_BR)
        output_cc.write(self.__clone_implementation() + _CPP_BR)

        output_cc.write(_CPP_CODING_INTERFACE_SPLIT + _CPP_BR)
        output_cc.write(self.__init_with_json_implementation() + _CPP_BR)

        output_cc.write(self.__config.cpp_ns_end + _CPP_BR)
    def generate_implementation(self):
        """Generates C++ Object implementation.
        """
        file_path = io_utils.cpp_object_implementation_path(
            self.__group_name, self.__class_name)
        output_cc = open(file_path, 'w')

        cpp_include = '#include "{0}.h"\n\n#include "json11/json11.hpp"'.format(
            self.__header_file_name())
        cpp_using = 'using std::string;\nusing std::unique_ptr;\nusing std::vector;'
        cpp_public_mark = '////////////////////////////////////////////////////////////////////////////////\n// ' \
                          '{0}, public:'.format(self.__class_name)

        output_cc.write(cpp_include + _CPP_BR)
        output_cc.write(cpp_using + _CPP_BR)
        output_cc.write(self.__config.cpp_ns_begin + _CPP_BR)
        output_cc.write(cpp_public_mark + _CPP_BR)

        output_cc.write(_CPP_LIFECYCLE_SPLIT + _CPP_BR)
        output_cc.write(self.__constructor_implementation() + _CPP_BR)
        output_cc.write(self.__deconstructor_implementation() + _CPP_BR)
        output_cc.write(self.__init_method_implementation() + _CPP_BR)
        output_cc.write(self.__clone_implementation() + _CPP_BR)

        output_cc.write(_CPP_CODING_INTERFACE_SPLIT + _CPP_BR)
        output_cc.write(self.__init_with_json_implementation() + _CPP_BR)

        output_cc.write(self.__config.cpp_ns_end + _CPP_BR)
Esempio n. 3
0
    def generate_manager_implementation(self):
        """Generates C++ Object Manager implementation.
        """
        if self.__cpp_manager_or_none is None:
            return

        cpp_manager = self.__cpp_manager_or_none

        header_file_name = cpp_class_name_to_cpp_file_name(self.__class_name) + '_manager.h'
        file_path = io_utils.cpp_object_implementation_path(self.__group_name, cpp_manager.class_name())
        output_cc = open(file_path, 'w')

        cpp_include = '#include "{0}"\n'.format(header_file_name)
        cpp_include += '#include "director/director.h"'
        cpp_using = 'using std::string;\nusing std::unique_ptr;\nusing std::vector;\n\nusing sakura::FileUtils;\n'
        cpp_public_mark = '////////////////////////////////////////////////////////////////////////////////\n// ' \
                          '{0}, public:'.format(cpp_manager.class_name())
        cpp_private_mark = '////////////////////////////////////////////////////////////////////////////////\n// ' \
                           '{0}, private:'.format(cpp_manager.class_name())
        cpp_sqlite_schema_split = '// SQLite schema --------------------------------------------------------\n'

        output_cc.write(cpp_include + _CPP_BR)
        output_cc.write(cpp_using + _CPP_BR)
        output_cc.write(self.__config.cpp_ns_begin + _CPP_BR)

        output_cc.write(cpp_sqlite_schema_split + '\n')
        output_cc.write(cpp_manager.sqlite_key_declaration() + '\n')
        output_cc.write(cpp_manager.easy_sqlite_field_declaration() + _CPP_BR)

        output_cc.write(cpp_public_mark + _CPP_BR)

        output_cc.write(_CPP_LIFECYCLE_SPLIT + _CPP_BR)
        output_cc.write(cpp_manager.generate_constructor_implementation() + _CPP_BR)
        output_cc.write(cpp_manager.generate_deconstructor_implementation() + _CPP_BR)
        output_cc.write(cpp_manager.generate_init_or_die_implementation() + _CPP_BR)
        output_cc.write(cpp_manager.generate_default_manager_implementation() + _CPP_BR)

        output_cc.write(_CPP_HTTP_SPLIT + _CPP_BR)
        output_cc.write(cpp_manager.generate_manager_http_implementation())

        output_cc.write(_CPP_PERSISTENT_STORE_SPLIT + _CPP_BR)
        output_cc.write(cpp_manager.generate_save_implementations())
        output_cc.write(cpp_manager.generate_fetch_implementations())
        output_cc.write(cpp_manager.generate_delete_implementations())

        output_cc.write(cpp_private_mark + _CPP_BR)

        output_cc.write(_CPP_UTILS_SPLIT + _CPP_BR)
        output_cc.write(cpp_manager.unsafe_save_implementation() + _CPP_BR)
        for table_name in cpp_manager.table_name_list:
            output_cc.write(cpp_manager.unsafe_save_implementation(table_name) + _CPP_BR)

        output_cc.write(cpp_manager.sqlite_record_by_object_implementation() + _CPP_BR)
        for table_name in cpp_manager.table_name_list:
            output_cc.write(cpp_manager.sqlite_record_by_object_implementation(table_name) + _CPP_BR)

        output_cc.write(cpp_manager.sqlite_object_from_record_implementation() + _CPP_BR)

        output_cc.write(self.__config.cpp_ns_end + _CPP_BR)
    def generate_manager_implementation(self):
        """Generates C++ Object Manager implementation.
        """
        if self.__cpp_manager_or_none is None:
            return

        cpp_manager = self.__cpp_manager_or_none

        header_file_name = cpp_class_name_to_cpp_file_name(
            self.__class_name) + '_manager.h'
        file_path = io_utils.cpp_object_implementation_path(
            self.__group_name, cpp_manager.class_name())
        output_cc = open(file_path, 'w')

        cpp_include = '#include "{0}"\n'.format(header_file_name)
        cpp_include += '#include "director/director.h"'
        cpp_using = 'using std::string;\nusing std::unique_ptr;\nusing std::vector;\n\nusing sakura::FileUtils;\n'
        cpp_public_mark = '////////////////////////////////////////////////////////////////////////////////\n// ' \
                          '{0}, public:'.format(cpp_manager.class_name())
        cpp_private_mark = '////////////////////////////////////////////////////////////////////////////////\n// ' \
                           '{0}, private:'.format(cpp_manager.class_name())
        cpp_sqlite_schema_split = '// SQLite schema --------------------------------------------------------\n'

        output_cc.write(cpp_include + _CPP_BR)
        output_cc.write(cpp_using + _CPP_BR)
        output_cc.write(self.__config.cpp_ns_begin + _CPP_BR)

        output_cc.write(cpp_sqlite_schema_split + '\n')
        output_cc.write(cpp_manager.sqlite_key_declaration() + '\n')
        output_cc.write(cpp_manager.easy_sqlite_field_declaration() + _CPP_BR)

        output_cc.write(cpp_public_mark + _CPP_BR)

        output_cc.write(_CPP_LIFECYCLE_SPLIT + _CPP_BR)
        output_cc.write(cpp_manager.generate_constructor_implementation() +
                        _CPP_BR)
        output_cc.write(cpp_manager.generate_deconstructor_implementation() +
                        _CPP_BR)
        output_cc.write(cpp_manager.generate_init_or_die_implementation() +
                        _CPP_BR)
        output_cc.write(cpp_manager.generate_default_manager_implementation() +
                        _CPP_BR)

        output_cc.write(_CPP_HTTP_SPLIT + _CPP_BR)
        output_cc.write(cpp_manager.generate_manager_http_implementation())

        output_cc.write(_CPP_PERSISTENT_STORE_SPLIT + _CPP_BR)
        output_cc.write(cpp_manager.generate_save_implementations())
        output_cc.write(cpp_manager.generate_fetch_implementations())
        output_cc.write(cpp_manager.generate_delete_implementations())

        output_cc.write(cpp_private_mark + _CPP_BR)

        output_cc.write(_CPP_UTILS_SPLIT + _CPP_BR)
        output_cc.write(cpp_manager.unsafe_save_implementation() + _CPP_BR)
        for table_name in cpp_manager.table_name_list:
            output_cc.write(
                cpp_manager.unsafe_save_implementation(table_name) + _CPP_BR)

        output_cc.write(cpp_manager.sqlite_record_by_object_implementation() +
                        _CPP_BR)
        for table_name in cpp_manager.table_name_list:
            output_cc.write(
                cpp_manager.sqlite_record_by_object_implementation(table_name)
                + _CPP_BR)

        output_cc.write(
            cpp_manager.sqlite_object_from_record_implementation() + _CPP_BR)

        output_cc.write(self.__config.cpp_ns_end + _CPP_BR)