Exemplo n.º 1
0
bool CppCodeGenerator::GenerateCode(PObjectBase project)
{
  m_header->Clear();
  m_source->Clear();
  string date(__DATE__);
  string time(__TIME__);
  string code_header (
   "///////////////////////////////////////////////////////////////////////////\n"
   "// C++ code generated with wxFormBuilder (version " __DATE__ ")\n" 
   "// http://wxformbuilder.software-libre.org/\n"
   "//\n"
   "// PLEASE DO \"NOT\" EDIT THIS FILE!\n"
   "///////////////////////////////////////////////////////////////////////////\n");
   
  m_header->WriteLn(code_header);
  m_source->WriteLn(code_header);
  
  string file = project->GetProperty("file")->GetValue();
  
  m_header->WriteLn("#ifndef __" + file + "__");
  m_header->WriteLn("#define __" + file + "__");

  m_source->WriteLn("#include \""+file+".h\"");
  
  
  GenIncludes(project);
  GenDefines(project);
  
  for (unsigned int i=0; i<project->GetChildCount(); i++)
  {
    GenClassDeclaration(project->GetChild(i));
    GenConstructor(project->GetChild(i));
  }
  
  m_header->WriteLn("#endif //__" + file + "__");
  m_header->WriteLn("");
  
  return true;
}
Exemplo n.º 2
0
void PHPCodeGenerator::GenClassDeclaration(PObjectBase class_obj, bool use_enum, const wxString& classDecoration, const EventVector &events, const wxString& eventHandlerPostfix)
{
	PProperty propName = class_obj->GetProperty( wxT("name") );
	if ( !propName )
	{
		wxLogError(wxT("Missing \"name\" property on \"%s\" class. Review your XML object description"),
			class_obj->GetClassName().c_str());
		return;
	}

	wxString class_name = propName->GetValue();
	if ( class_name.empty() )
	{
		wxLogError( wxT("Object name can not be null") );
		return;
	}

	m_source->WriteLn( wxT("/*") );
	m_source->WriteLn( wxT(" * Class ") + class_name);
	m_source->WriteLn( wxT(" */") );
	m_source->WriteLn( );

	m_source->WriteLn( wxT("class ") + classDecoration + class_name + wxT(" extends ") + GetCode( class_obj, wxT("base") ).Trim() + wxT(" {") );
	m_source->Indent();

	// The constructor is also included within public
	GenConstructor( class_obj, events );
	GenDestructor( class_obj, events );

	m_source->WriteLn( wxT("") );

	// event handlers
	GenVirtualEventHandlers(events, eventHandlerPostfix);
	GetGenEventHandlers( class_obj );

	m_source->Unindent();
	m_source->WriteLn( wxT("}") );
	m_source->WriteLn( wxT("") );
}
Exemplo n.º 3
0
bool CppCodeGenerator::GenerateCode( shared_ptr<ObjectBase> project )
{
	if (!project)
	{
		wxLogError(wxT("There is no project to generate code"));
		return false;
	}

	bool useEnum = false;

	shared_ptr< Property > useEnumProperty = project->GetProperty( wxT("use_enum") );
	if (useEnumProperty && useEnumProperty->GetValueAsInteger())
		useEnum = true;

	m_i18n = false;
	shared_ptr< Property > i18nProperty = project->GetProperty( wxT("internationalize") );
	if (i18nProperty && i18nProperty->GetValueAsInteger())
		m_i18n = true;

	m_header->Clear();
	m_source->Clear();
	wxString code (
		wxT("///////////////////////////////////////////////////////////////////////////\n")
		wxT("// C++ code generated with wxFormBuilder (version ") wxT(__DATE__) wxT(")\n")
		wxT("// http://wxformbuilder.sourceforge.net/\n")
		wxT("//\n")
		wxT("// PLEASE DO \"NOT\" EDIT THIS FILE!\n")
		wxT("///////////////////////////////////////////////////////////////////////////\n") );

	m_header->WriteLn( code );
	m_source->WriteLn( code );

	shared_ptr<Property> propFile = project->GetProperty( wxT("file") );
	if (!propFile)
	{
		wxLogError( wxT("Missing \"file\" property on Project Object") );
		return false;
	}

	wxString file = propFile->GetValue();
	if ( file.empty() )
	{
		file = wxT("noname");
	}

	m_header->WriteLn( wxT("#ifndef __") + file + wxT("__") );
	m_header->WriteLn( wxT("#define __") + file + wxT("__") );
	m_header->WriteLn( wxT("") );

	code = GetCode( project, wxT("header_preamble") );
	m_header->WriteLn( code );

	// Generate the libraries
	set< wxString > libraries;
	GenLibraries( project, &libraries );

	// Write the library lines
	WriteLibrariesBlock( libraries );

	// generamos en el h los includes de las dependencias de los componentes.
	set<wxString> includes;
	GenIncludes(project, &includes);

	// Write the include lines
	set<wxString>::iterator include_it;
	for ( include_it = includes.begin(); include_it != includes.end(); ++include_it )
	{
		m_header->WriteLn( *include_it );
	}
	if ( !includes.empty() )
	{
		m_header->WriteLn( wxT("") );
	}

	code = GetCode( project, wxT("header_epilogue") );
	m_header->WriteLn( code );
	m_header->WriteLn( wxT("") );

	// en el cpp generamos el include del .h generado y los xpm
	code = GetCode( project, wxT("cpp_preamble") );
	m_source->WriteLn( code );
	m_source->WriteLn( wxT("") );

	m_source->WriteLn( wxT("#include \"") + file + wxT(".h\""));
	m_source->WriteLn( wxT("") );
	GenXpmIncludes( project );

	code = GetCode( project, wxT("cpp_epilogue") );
	m_source->WriteLn( code );

	// generamos los defines de las macros
	if ( !useEnum )
	{
		GenDefines( project );
	}

	for ( unsigned int i = 0; i < project->GetChildCount(); i++ )
	{
		GenClassDeclaration( project->GetChild( i ), useEnum );
		GenConstructor( project->GetChild( i ) );
	}

	m_header->WriteLn( wxT("#endif //__") + file + wxT("__") );

	return true;
}