Пример #1
0
bool TemplateParser::ParseForEach()
{
	// Whitespaces at the very start are ignored
	ignore_whitespaces();

	// parsing the property
	if (GetNextToken() == TOK_PROPERTY)
	{
		wxString propname = ParsePropertyName();
		wxString inner_template = ExtractInnerTemplate();

		PProperty property = m_obj->GetProperty(propname);
		wxString propvalue = property->GetValue();

		// Property value must be an string using ',' as separator.
		// The template will be generated nesting as many times as
		// tokens were found in the property value.

		if (property->GetType() == PT_INTLIST || property->GetType() == PT_UINTLIST)
		{
			// For doing that we will use wxStringTokenizer class from wxWidgets
			wxStringTokenizer tkz( propvalue, wxT(","));
			int i = 0;
			while (tkz.HasMoreTokens())
			{
				wxString token;
				token = tkz.GetNextToken();
				token.Trim(true);
				token.Trim(false);

				// Parsing the internal template
				{
					wxString code;
					PTemplateParser parser = CreateParser( this, inner_template );
					parser->SetPredefined( token, wxString::Format( wxT("%i"), i++ ) );
					code = parser->ParseTemplate();
					m_out << wxT("\n") << code;
				}
			}
		}
		else if (property->GetType() == PT_STRINGLIST)
		{
			wxArrayString array = property->GetValueAsArrayString();
			for ( unsigned int i = 0 ; i < array.Count(); i++ )
			{
				wxString code;
				PTemplateParser parser = CreateParser(this,inner_template);
				parser->SetPredefined( ValueToCode( PT_WXSTRING_I18N, array[i] ), wxString::Format( wxT("%i"), i ) );
				code = parser->ParseTemplate();
				m_out << wxT("\n") << code;
			}
		}
		else
			wxLogError(wxT("Property type not compatible with \"foreach\" macro"));
	}

	return true;
}
Пример #2
0
void PHPCodeGenerator::FindMacros( PObjectBase obj, std::vector<wxString>* macros )
{
	// iterate through all of the properties of all objects, add the macros
	// to the vector
	unsigned int i;

	for ( i = 0; i < obj->GetPropertyCount(); i++ )
	{
		PProperty prop = obj->GetProperty( i );
		if ( prop->GetType() == PT_MACRO )
		{
			wxString value = prop->GetValue();
			if( value.IsEmpty() ) continue;

			// Skip wx IDs
			if ( ( ! value.Contains( wxT("XRCID" ) ) ) &&
				 ( m_predMacros.end() == m_predMacros.find( value ) ) )
			{
				if ( macros->end() == std::find( macros->begin(), macros->end(), value ) )
				{
					macros->push_back( value );
				}
			}
		}
	}

	for ( i = 0; i < obj->GetChildCount(); i++ )
	{
		FindMacros( obj->GetChild( i ), macros );
	}
}
Пример #3
0
wxString TemplateParser::PropertyToCode(PProperty property)
{
	if ( property )
	{
		return ValueToCode(property->GetType(), property->GetValue());
	}
	else
	{
		return wxEmptyString;
	}
}
Пример #4
0
wxArrayInt ObjectBase::GetPropertyAsArrayInt(const wxString& pname)
{
	wxArrayInt array;
	PProperty property = GetProperty( pname );
	if (property)
	{
		IntList il( property->GetValue(), property->GetType() == PT_UINTLIST );
		for (unsigned int i=0; i < il.GetSize() ; i++)
			array.Add(il.GetValue(i));
	}

	return array;
}
Пример #5
0
void CppCodeGenerator::FindMacros(PObjectBase obj, set<string> &macro_set)
{
  // recorre cada propiedad de cada objeto identificando aquellas
  // que sean macros, en cuyo caso la añade al conjunto.
  unsigned int i;  
 
  for (i=0; i<obj->GetPropertyCount(); i++)
  {
    PProperty prop = obj->GetProperty(i);
    if (prop->GetType() == PT_MACRO)
      macro_set.insert(prop->GetValue());
  }
  
  for (i=0; i<obj->GetChildCount(); i++)
  {
    FindMacros(obj->GetChild(i),macro_set);
  }
}
Пример #6
0
/**
 * Convierte el valor de una propiedad a código C++.
 */
string CppTemplateParser::PropertyToCode(PProperty property)
{
  PropertyType type = property->GetType();
  string value = property->GetValue();
  
  string result;
  
  switch (type)
  {
    case PT_WXSTRING:
    // TO-DO's
    // Las cadenas de caracteres (wxString) hay que pasarlas a cadenas tipo "C"
    // "Hola" -> wxT("\"Hola\"")
      result = "wxT(\"" + ConvertCppString(value) + "\")"; 
      break;
    case PT_MACRO:
    case PT_TEXT:
    case PT_OPTION:
      result = value;
      break;
    case PT_BITLIST:
      if (value == "")
        result = "0";
      else
        result = value;
      break;
    case PT_WXPOINT:
      if (value == "")
        result = "wxDefaultPosition";
      else
        result = "wxPoint(" + value + ")";
      break;
    case PT_WXSIZE:
      if (value == "")
        result = "wxDefaultSize";
      else
        result = "wxSize(" + value + ")";
      break;
    case PT_BOOL:
      if (value == "0")
        result = "false";
      else
        result = "true";
      break;
    case PT_WXFONT:
      if (value != "")
      {
        wxFont font = 
          TypeConv::StringToFont(wxString(value.c_str(),wxConvUTF8));
        
        wxString underlined(wxT("false"));
        if (font.GetUnderlined())
          underlined = wxT("true");
 
        wxString font_str = wxString::Format(wxT("wxFont(%d,%d,%d,%d,%s,wxT(\"%s\"))"),
                             font.GetPointSize(),
                             font.GetFamily(),
                             font.GetStyle(),
                             font.GetWeight(),
                             underlined.c_str(),
                             font.GetFaceName().c_str());
        result = string(font_str.mb_str());
      }
      else
        result = "wxFont()";
      break;  
    case PT_WXCOLOUR:
      if (value != "") 
      {
        wxColour colour = 
          TypeConv::StringToColour(wxString(value.c_str(),wxConvUTF8));
          
        wxString col_str = wxString::Format(wxT("wxColour(%d,%d,%d)"),
                             colour.Red(),colour.Green(),colour.Blue());
        result = string(col_str.mb_str());
        
      }
      else 
          result = "wxColour()";
       
      break;  
      
    case PT_BITMAP:
      // La generación de esta propiedad es provisional ya que la idea
      // principal es que los archivos xpm se incluyan (#include) en el
      // fichero cpp y no cargarlo de un fichero.
      result = "wxBitmap(wxT(\"" + ConvertCppString(value)
                       + "\"), wxBITMAP_TYPE_XPM)";
      break;
    default:
      
      break;  
  }
  
  return result;
}