Exemplo n.º 1
0
void ScfgRuleWriter::WriteUnpairedFormat(const ScfgRule &rule,
    std::ostream &sourceSS,
    std::ostream &targetSS)
{
  const std::vector<Symbol> &sourceRHS = rule.GetSourceRHS();
  const std::vector<Symbol> &targetRHS = rule.GetTargetRHS();

  // Write the source side of the rule to sourceSS.
  int i = 0;
  for (std::vector<Symbol>::const_iterator p(sourceRHS.begin());
       p != sourceRHS.end(); ++p, ++i) {
    WriteSymbol(*p, sourceSS);
    sourceSS << " ";
  }
  if (m_options.conditionOnTargetLhs) {
    WriteSymbol(rule.GetTargetLHS(), sourceSS);
  } else {
    WriteSymbol(rule.GetSourceLHS(), sourceSS);
  }

  // Write the target side of the rule to targetSS.
  i = 0;
  for (std::vector<Symbol>::const_iterator p(targetRHS.begin());
       p != targetRHS.end(); ++p, ++i) {
    WriteSymbol(*p, targetSS);
    targetSS << " ";
  }
  WriteSymbol(rule.GetTargetLHS(), targetSS);
}
Exemplo n.º 2
0
	RESULTCODE GetSymbolResponse::Write(WebWriter* pWriter)
	{
		if(pWriter==NULL)
		{
			return AG_FAILURE;
		}
		
		XDocument* pxDoc = new XDocument();
		if(m_pSymbol!=NULL)
		{
			WriteSymbol(pxDoc);
		}
		else if(m_pSymbols!=NULL)
		{
			WriteSymbols(pxDoc);
		}

		int len = 0;
		g_uchar* buffer = NULL;
		GLogger* pLogger = augeGetLoggerInstance();

		pxDoc->WriteToString(&buffer, len, m_pRequest->GetEncoding(),0);

		pWriter->WriteHead(m_pRequest->GetMimeType(),false);
		pWriter->Write(buffer, len);
		pWriter->WriteTail();

		pLogger->Info((g_char*)buffer);
		
		return AG_SUCCESS;
	}
Exemplo n.º 3
0
void ScfgRuleWriter::WriteStandardFormat(const ScfgRule &rule)
{
  const std::vector<Symbol> &sourceRHS = rule.GetSourceRHS();
  const std::vector<Symbol> &targetRHS = rule.GetTargetRHS();

  std::map<int, int> sourceToTargetNTMap;
  std::map<int, int> targetToSourceNTMap;

  const Alignment &alignment = rule.GetAlignment();

  for (Alignment::const_iterator p(alignment.begin());
       p != alignment.end(); ++p) {
    if (sourceRHS[p->first].GetType() == NonTerminal) {
      assert(targetRHS[p->second].GetType() == NonTerminal);
      sourceToTargetNTMap[p->first] = p->second;
      targetToSourceNTMap[p->second] = p->first;
    }
  }

  std::ostringstream sourceSS;
  std::ostringstream targetSS;

  // Write the source side of the rule to sourceSS.
  int i = 0;
  for (std::vector<Symbol>::const_iterator p(sourceRHS.begin());
       p != sourceRHS.end(); ++p, ++i) {
    WriteSymbol(*p, sourceSS);
    if (p->GetType() == NonTerminal) {
      int targetIndex = sourceToTargetNTMap[i];
      WriteSymbol(targetRHS[targetIndex], sourceSS);
    }
    sourceSS << " ";
  }
  WriteSymbol(rule.GetSourceLHS(), sourceSS);

  // Write the target side of the rule to targetSS.
  i = 0;
  for (std::vector<Symbol>::const_iterator p(targetRHS.begin());
       p != targetRHS.end(); ++p, ++i) {
    if (p->GetType() == NonTerminal) {
      int sourceIndex = targetToSourceNTMap[i];
      WriteSymbol(sourceRHS[sourceIndex], targetSS);
    }
    WriteSymbol(*p, targetSS);
    targetSS << " ";
  }
  WriteSymbol(rule.GetTargetLHS(), targetSS);

  // Write the rule to the forward and inverse extract files.
  m_fwd << sourceSS.str() << " ||| " << targetSS.str() << " |||";
  m_inv << targetSS.str() << " ||| " << sourceSS.str() << " |||";
  for (Alignment::const_iterator p(alignment.begin());
       p != alignment.end(); ++p) {
    m_fwd << " " << p->first << "-" << p->second;
    m_inv << " " << p->second << "-" << p->first;
  }
  m_fwd << " ||| 1" << std::endl;
  m_inv << " ||| 1" << std::endl;
}
Exemplo n.º 4
0
void ScfgRuleWriter::WriteUnpairedFormat(const ScfgRule &rule)
{
  const std::vector<Symbol> &sourceRHS = rule.GetSourceRHS();
  const std::vector<Symbol> &targetRHS = rule.GetTargetRHS();
  const Alignment &alignment = rule.GetAlignment();

  std::ostringstream sourceSS;
  std::ostringstream targetSS;

  // Write the source side of the rule to sourceSS.
  int i = 0;
  for (std::vector<Symbol>::const_iterator p(sourceRHS.begin());
       p != sourceRHS.end(); ++p, ++i) {
    WriteSymbol(*p, sourceSS);
    sourceSS << " ";
  }
  WriteSymbol(rule.GetSourceLHS(), sourceSS);

  // Write the target side of the rule to targetSS.
  i = 0;
  for (std::vector<Symbol>::const_iterator p(targetRHS.begin());
       p != targetRHS.end(); ++p, ++i) {
    WriteSymbol(*p, targetSS);
    targetSS << " ";
  }
  WriteSymbol(rule.GetTargetLHS(), targetSS);

  // Write the rule to the forward and inverse extract files.
  m_fwd << sourceSS.str() << " ||| " << targetSS.str() << " |||";
  m_inv << targetSS.str() << " ||| " << sourceSS.str() << " |||";
  for (Alignment::const_iterator p(alignment.begin());
       p != alignment.end(); ++p) {
    m_fwd << " " << p->first << "-" << p->second;
    m_inv << " " << p->second << "-" << p->first;
  }
  m_fwd << " ||| 1" << std::endl;
  m_inv << " ||| 1" << std::endl;
}
Exemplo n.º 5
0
void ExpandElm( NODE * n )
{
NODE *cn;

  if( substENABLED == 0 ) {
    WriteElm( n );
    return;
  }   
  cn = LookUpSubst( n );
  if( cn == 0 ) {
    WriteElm( n );
  } else {
    if( cn->type > SUBST ) {
      WriteElm( n );
    } else {
      cn->type += SUBST;
      WriteSymbol( O_PAREN );
      WriteNode( cn->right );       
      WriteSymbol( C_PAREN );
      cn->type -= SUBST;
    }
  }
}
Exemplo n.º 6
0
void ScfgRuleWriter::WriteStandardFormat(const ScfgRule &rule,
    std::ostream &sourceSS,
    std::ostream &targetSS)
{
  const std::vector<Symbol> &sourceRHS = rule.GetSourceRHS();
  const std::vector<Symbol> &targetRHS = rule.GetTargetRHS();

  std::map<int, int> sourceToTargetNTMap;
  std::map<int, int> targetToSourceNTMap;

  const Alignment &alignment = rule.GetAlignment();

  for (Alignment::const_iterator p(alignment.begin());
       p != alignment.end(); ++p) {
    if (sourceRHS[p->first].GetType() == NonTerminal) {
      assert(targetRHS[p->second].GetType() == NonTerminal);
      sourceToTargetNTMap[p->first] = p->second;
      targetToSourceNTMap[p->second] = p->first;
    }
  }

  // Write the source side of the rule to sourceSS.
  int i = 0;
  for (std::vector<Symbol>::const_iterator p(sourceRHS.begin());
       p != sourceRHS.end(); ++p, ++i) {
    WriteSymbol(*p, sourceSS);
    if (p->GetType() == NonTerminal) {
      int targetIndex = sourceToTargetNTMap[i];
      WriteSymbol(targetRHS[targetIndex], sourceSS);
    }
    sourceSS << " ";
  }
  if (m_options.conditionOnTargetLhs) {
    WriteSymbol(rule.GetTargetLHS(), sourceSS);
  } else {
    WriteSymbol(rule.GetSourceLHS(), sourceSS);
  }

  // Write the target side of the rule to targetSS.
  i = 0;
  for (std::vector<Symbol>::const_iterator p(targetRHS.begin());
       p != targetRHS.end(); ++p, ++i) {
    if (p->GetType() == NonTerminal) {
      int sourceIndex = targetToSourceNTMap[i];
      WriteSymbol(sourceRHS[sourceIndex], targetSS);
    }
    WriteSymbol(*p, targetSS);
    targetSS << " ";
  }
  WriteSymbol(rule.GetTargetLHS(), targetSS);
}
Exemplo n.º 7
0
coResult coCppTypesGeneratorPlugin::WriteParsedType(coStringOutputStream& _stream, const coParsedType& _parsedType, const coConstString& _indentation)
{
	const coType* type = _parsedType.type;
	coASSERT(type);

	coTRY(WriteSymbol(_stream, *type, "\t", "type->"), nullptr);
	_stream << _indentation << "type->size8 = sizeof(" << type->name << ");\n";
	_stream << _indentation << "type->alignment8 = alignof(" << type->name << ");\n";
	_stream << _indentation << "type->super = nullptr;\n";
	_stream << _indentation << "type->createFunc = []() -> void* { return new " << type->name << "(); };\n";

	_stream << _indentation << "\n";

	// Fields
	{
		coUint nbPublicFields = 0;
		for (const coParsedField* parsedField : _parsedType.parsedFields)
		{
			coASSERT(parsedField);
			const coField* field = parsedField->field;
			if (field->symbolFlags & coSymbol::public_)
			{
				++nbPublicFields;
			}
		}

		if (nbPublicFields)
		{
			_stream << _indentation << "// Fields\n";
			_stream << _indentation << "coReserve(type->fields, " << nbPublicFields << ");\n";
			_stream << _indentation << "\n";
			for (const coParsedField* parsedField : _parsedType.parsedFields)
			{
				coASSERT(parsedField);
				const coField* field = parsedField->field;
				coASSERT(field);
				if (field->symbolFlags & coSymbol::public_)
				{
					coTRY(WriteParsedField(_stream, _parsedType, *parsedField, _indentation), "Failed to write field: " << parsedField->field->name);
				}
			}
		}
	}

	return true;
}
Exemplo n.º 8
0
bool MusBinOutput::WriteNote( const MusNote *note )
{
	int i;
	
	Write( &note->TYPE, 1 );
	WriteElementAttr( note );
	Write( &note->sil, 1 ); 
	Write( &note->val, 1 );
	Write( &note->inv_val, 1 );
	Write( &note->point, 1 );
	Write( &note->stop_rel, 1 );
	Write( &note->acc, 1 );
	Write( &note->accInvis, 1 );
	Write( &note->q_auto, 1 );
	Write( &note->queue, 1 );
	Write( &note->stacc, 1 );
	Write( &note->oblique, 1 );
	Write( &note->queue_lig, 1 );
	Write( &note->chord, 1 );
	Write( &note->fchord, 1 );
	Write( &note->lat, 1 );
	Write( &note->haste, 1 );
	//Write( &note->code, sizeof( note->code ) );
	unsigned char code = (unsigned char)note->code;
	Write( &code, 1 ); // deplace dans element, mais unsigned short
	Write( &note->tetenot, 1 );
	Write( &note->typStac, 1 );
	
	// lyric
	char count = 0;
	for ( i = 0; i < (int)note->m_lyrics.GetCount(); i++ ){
		MusSymbol *lyric = &note->m_lyrics[i];
		if ( lyric )
			count++;
	}
	Write( &count, 1 );
	
	for ( i = 0; i < (int)note->m_lyrics.GetCount(); i++ ){
		MusSymbol *lyric = &note->m_lyrics[i];
		if ( lyric )
			WriteSymbol( lyric );
	}
	
	return true;
}
Exemplo n.º 9
0
coResult coCppTypesGeneratorPlugin::WriteParsedField(coStringOutputStream& _stream, const coParsedType& _parsedType, const coParsedField& _parsedField, const coConstString& _indentation)
{
	coLocalAllocator localAllocator(2048);

	const coField* field = _parsedField.field;
	coASSERT(field);
	_stream << _indentation << "// " << field->name << "\n";
	_stream << _indentation << "{\n";

	coDynamicString blockIndent(localAllocator);
	blockIndent << _indentation << "\t";
	_stream << blockIndent << "coField* field = new coField();\n";
	coTRY(WriteSymbol(_stream, *field, blockIndent, "field->"), nullptr);
	_stream << blockIndent << "field->type = nullptr;\n";
	_stream << blockIndent << "field->offset8 = static_cast<decltype(field->offset8)>(coGetFieldOffset<" << _parsedType.type->name << ">(&" << _parsedType.type->name << "::" << field->name << "));\n";

	_stream << blockIndent << "\n";
	_stream << blockIndent << "coPushBack(type->fields, field);\n";
	_stream << _indentation << "}\n";
	_stream << _indentation << "\n";
	coASSERT(field);
	return true;
}
Exemplo n.º 10
0
int ExpandNode( NODE *n, int lastop )
{
int needParen = 0;

  if( n == 0 ) return lastop;

  if( ( n->left ) &&
      ( PRI[ n->left->type ] < PRI[ n->type ] ) )
      needParen = 1;

  if( needParen ) {
    WriteOp( crtop );
    WriteSymbol( O_PAREN );
  }
  lastop = ExpandNode( n->left, lastop );
  if( needParen ) WriteSymbol( C_PAREN );

  switch( n->type ) {
    case ADD:  
    case SUB:   
    case MUL:   
    case DIV:   
    case POW:   crtop = n->type;
                break;
    case NONE:  printf("ERROR - null element"); 
    		break;
    case CONST: 
    case ELM:
    case VELM:
    case MELM:
    case EELM:
		switch( crtop ) {
		  case MUL: case DIV: case POW:
		    WriteOp( crtop );
		    if ( n->sign == -1 ) {
		      WriteSymbol( O_PAREN );
		      WriteOp( SUB );
		      ExpandElm( n );
		      WriteSymbol( C_PAREN );
		    } else {
		      ExpandElm( n );
		    }
		    break;
		  case ADD:  if( n->sign == -1 )
			       crtop = SUB;
			     WriteOp( crtop );
			     ExpandElm( n );
			     break;
		  case SUB:  if( n->sign == -1 )
			       crtop = ADD;
			     WriteOp( crtop );
			     ExpandElm( n );
			     break;
		  case NONE: if( n->sign == -1 )
			       WriteOp( SUB );
			     ExpandElm( n );
			     break;
		}
		break;
  }

  if( ( n->right ) &&
      ( PRI[ n->right->type ] <= PRI[ n->type ] ) )
      needParen = 1; 

  if( needParen ) {
    WriteOp( crtop );
    WriteSymbol( O_PAREN );
  }  
  lastop = ExpandNode( n->right, n->type );
  if( needParen ) WriteSymbol( C_PAREN );
  return lastop;
}
Exemplo n.º 11
0
void WriteOp( int op )
{
  WriteSymbol( op );
  crtop = NONE;
}
Exemplo n.º 12
0
bool MusBinOutput::WriteStaff( const MusStaff *staff )
{
	unsigned int k;

	uint32 = wxUINT32_SWAP_ON_BE( staff->nblement );
	Write( &uint32, 4 );
	uint16 = wxUINT16_SWAP_ON_BE( staff->voix );
	Write( &uint16, 2 );
	uint16 = wxUINT16_SWAP_ON_BE( staff->noGrp );
	Write( &uint16, 2 );
	uint16 = wxUINT16_SWAP_ON_BE( staff->totGrp );
	Write( &uint16, 2 );
	uint16 = wxUINT16_SWAP_ON_BE( staff->noLigne );
	Write( &uint16, 2 );
	uint16 = wxUINT16_SWAP_ON_BE( staff->no );
	Write( &uint16, 2 );
	Write( &staff->armTyp, 1 );
	Write( &staff->armNbr, 1 );
	Write( &staff->notAnc, 1 );
	Write( &staff->grise, 1 );
	Write( &staff->invisible, 1 );
	uint16 = wxUINT16_SWAP_ON_BE( staff->ecart );
	Write( &uint16, 2 );
	Write( &staff->vertBarre, 1 );
	Write( &staff->brace, 1 );
	Write( &staff->pTaille, 1 );
    int32 = wxINT32_SWAP_ON_BE( staff->indent );
    Write( &int32, 4 );
	Write( &staff->indentDroite, 1 );
	Write( &staff->portNbLine, 1 );
	Write( &staff->accol, 1 );
	Write( &staff->accessoire, 1 );
	uint16 = wxUINT16_SWAP_ON_BE( staff->reserve );
	Write( &uint16, 2 );
	for (k = 0;k < staff->nblement ; k++ )
	{
		if ( staff->m_elements[k].IsNote() )
		{
			WriteNote( (MusNote*)&staff->m_elements[k] );
		}
		else if ( staff->m_elements[k].IsSymbol() )
		{
			WriteSymbol( (MusSymbol*)&staff->m_elements[k] );
		}
        else if ( staff->m_elements[k].IsNeume() )
		{
			WriteNeume( (MusNeume*)&staff->m_elements[k] );
		}
		if ( m_flag == MUS_BIN_ARUSPIX_CMP )
		{		
			MusElement *elem = &staff->m_elements[k];
			int32 = wxINT32_SWAP_ON_BE( (int)elem->m_im_filename.Length() );
			Write( &int32, 4 );
			Write( elem->m_im_filename.c_str(), (int)elem->m_im_filename.Length() + 1 );
			int32 = wxINT32_SWAP_ON_BE( elem->m_im_staff );
			Write( &int32, 4 );
			int32 = wxINT32_SWAP_ON_BE( elem->m_im_pos );
			Write( &int32, 4 );
			int32 = wxINT32_SWAP_ON_BE( elem->m_cmp_flag );
			Write( &int32, 4 );
		}
	}

	return true;
}