def make_ctocpp_class_impl()

in tools/make_ctocpp_impl.py [0:0]


def make_ctocpp_class_impl(header, clsname, impl):
  cls = header.get_class(clsname)
  if cls is None:
    raise Exception('Class does not exist: ' + clsname)

  capiname = cls.get_capi_name()

  # retrieve the existing virtual function implementations
  existing = get_function_impls(impl, clsname + 'CToCpp::')

  base_class_name = header.get_base_class_name(clsname)
  base_scoped = True if base_class_name == 'CefBaseScoped' else False
  if base_scoped:
    template_class = 'CefCToCppScoped'
  else:
    template_class = 'CefCToCppRefCounted'

  # generate virtual functions
  virtualimpl = make_ctocpp_virtual_function_impl(header, cls, existing,
                                                  base_scoped)
  if len(virtualimpl) > 0:
    virtualimpl = '\n// VIRTUAL METHODS - Body may be edited by hand.\n\n' + virtualimpl

  # retrieve the existing static function implementations
  existing = get_function_impls(impl, clsname + '::')

  # generate static functions
  staticimpl = make_ctocpp_function_impl(clsname,
                                         cls.get_static_funcs(), existing,
                                         base_scoped)
  if len(staticimpl) > 0:
    staticimpl = '\n// STATIC METHODS - Body may be edited by hand.\n\n' + staticimpl

  resultingimpl = staticimpl + virtualimpl

  # any derived classes can be unwrapped
  unwrapderived = make_ctocpp_unwrap_derived(header, cls, base_scoped)

  const =  '// CONSTRUCTOR - Do not edit by hand.\n\n'+ \
           clsname+'CToCpp::'+clsname+'CToCpp() {\n'+ \
           '}\n\n'+ \
           '// DESTRUCTOR - Do not edit by hand.\n\n'+ \
           clsname+'CToCpp::~'+clsname+'CToCpp() {\n'

  if not cls.has_attrib('no_debugct_check') and not base_scoped:
    const += '  shutdown_checker::AssertNotShutdown();\n'

  const += '}\n\n'

  # determine what includes are required by identifying what translation
  # classes are being used
  includes = format_translation_includes(header, const + resultingimpl +
                                         (unwrapderived[0]
                                          if base_scoped else unwrapderived))

  # build the final output
  result = get_copyright()

  result += includes + '\n' + resultingimpl + '\n'

  parent_sig = template_class + '<' + clsname + 'CToCpp, ' + clsname + ', ' + capiname + '>'

  if base_scoped:
    const += 'template<> '+capiname+'* '+parent_sig+'::UnwrapDerivedOwn(CefWrapperType type, CefOwnPtr<'+clsname+'> c) {\n'+ \
             unwrapderived[0] + \
             '  NOTREACHED() << "Unexpected class type: " << type;\n'+ \
             '  return nullptr;\n'+ \
             '}\n\n' + \
             'template<> '+capiname+'* '+parent_sig+'::UnwrapDerivedRaw(CefWrapperType type, CefRawPtr<'+clsname+'> c) {\n'+ \
             unwrapderived[1] + \
             '  NOTREACHED() << "Unexpected class type: " << type;\n'+ \
             '  return nullptr;\n'+ \
             '}\n\n'
  else:
    const += 'template<> '+capiname+'* '+parent_sig+'::UnwrapDerived(CefWrapperType type, '+clsname+'* c) {\n'+ \
             unwrapderived + \
             '  NOTREACHED() << "Unexpected class type: " << type;\n'+ \
             '  return nullptr;\n'+ \
             '}\n\n'

  const += 'template<> CefWrapperType ' + parent_sig + '::kWrapperType = ' + get_wrapper_type_enum(
      clsname) + ';'

  result += const

  return result