2011-05-20 16:42:25 +02:00
|
|
|
# Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
2010-10-03 23:04:50 +02:00
|
|
|
# reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
# can be found in the LICENSE file.
|
|
|
|
|
|
|
|
from cef_parser import *
|
|
|
|
|
|
|
|
def make_ctocpp_header(header, clsname):
|
|
|
|
cls = header.get_class(clsname)
|
|
|
|
if cls is None:
|
|
|
|
raise Exception('Class does not exist: '+clsname)
|
|
|
|
|
|
|
|
clientside = cls.is_client_side()
|
|
|
|
defname = string.upper(clsname[3:])
|
|
|
|
capiname = cls.get_capi_name()
|
|
|
|
|
2011-12-08 02:38:30 +01:00
|
|
|
result = get_copyright()
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
result += '#ifndef _'+defname+'_CTOCPP_H\n'+ \
|
|
|
|
'#define _'+defname+'_CTOCPP_H\n'
|
|
|
|
|
|
|
|
if clientside:
|
|
|
|
result += """
|
|
|
|
#ifndef BUILDING_CEF_SHARED
|
|
|
|
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
|
|
|
|
#else // BUILDING_CEF_SHARED
|
|
|
|
"""
|
|
|
|
else:
|
|
|
|
result += """
|
|
|
|
#ifndef USING_CEF_SHARED
|
|
|
|
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
|
|
|
|
#else // USING_CEF_SHARED
|
|
|
|
"""
|
|
|
|
|
|
|
|
result += """
|
|
|
|
#include "include/cef.h"
|
|
|
|
#include "include/cef_capi.h"
|
|
|
|
#include "libcef_dll/ctocpp/ctocpp.h"
|
|
|
|
|
|
|
|
// Wrap a C structure with a C++ class.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if clientside:
|
|
|
|
result += '// This class may be instantiated and accessed DLL-side only.\n'
|
|
|
|
else:
|
|
|
|
result += '// This class may be instantiated and accessed wrapper-side only.\n'
|
|
|
|
|
|
|
|
result += 'class '+clsname+'CToCpp\n'+ \
|
|
|
|
' : public CefCToCpp<'+clsname+'CToCpp, '+clsname+', '+capiname+'>\n'+ \
|
|
|
|
'{\n'+ \
|
|
|
|
'public:\n'+ \
|
|
|
|
' '+clsname+'CToCpp('+capiname+'* str)\n'+ \
|
|
|
|
' : CefCToCpp<'+clsname+'CToCpp, '+clsname+', '+capiname+'>(str) {}\n'+ \
|
|
|
|
' virtual ~'+clsname+'CToCpp() {}\n\n'+ \
|
|
|
|
' // '+clsname+' methods\n';
|
|
|
|
|
|
|
|
funcs = cls.get_virtual_funcs()
|
|
|
|
for func in funcs:
|
2011-05-20 16:42:25 +02:00
|
|
|
result += ' virtual '+func.get_cpp_proto()+' OVERRIDE;\n'
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
result += '};\n\n'
|
|
|
|
|
|
|
|
if clientside:
|
|
|
|
result += '#endif // BUILDING_CEF_SHARED\n'
|
|
|
|
else:
|
|
|
|
result += '#endif // USING_CEF_SHARED\n'
|
|
|
|
|
|
|
|
result += '#endif // _'+defname+'_CTOCPP_H\n'
|
|
|
|
|
|
|
|
return wrap_code(result)
|
|
|
|
|
|
|
|
|
|
|
|
def write_ctocpp_header(header, clsname, dir, backup):
|
2010-12-07 02:30:26 +01:00
|
|
|
file = dir+os.sep+get_capi_name(clsname[3:], False)+'_ctocpp.h'
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-09-27 17:02:08 +02:00
|
|
|
if path_exists(file):
|
2010-10-03 23:04:50 +02:00
|
|
|
oldcontents = read_file(file)
|
|
|
|
else:
|
|
|
|
oldcontents = ''
|
|
|
|
|
|
|
|
newcontents = make_ctocpp_header(header, clsname)
|
|
|
|
if newcontents != oldcontents:
|
|
|
|
if backup and oldcontents != '':
|
|
|
|
backup_file(file)
|
|
|
|
write_file(file, newcontents)
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
# test the module
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# verify that the correct number of command-line arguments are provided
|
|
|
|
if len(sys.argv) < 3:
|
|
|
|
sys.stderr.write('Usage: '+sys.argv[0]+' <infile> <classname>')
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
# create the header object
|
|
|
|
header = obj_header(sys.argv[1])
|
|
|
|
|
|
|
|
# dump the result to stdout
|
|
|
|
sys.stdout.write(make_ctocpp_header(header, sys.argv[2]))
|