Exemple #1
0
void addParticle(Emitter e) {
	Particle *p;
	p = (Particle*) malloc(sizeof(Particle));

	p->name = e.name;
	p->zIndex = NULL;

	double randRotation = e.alpha != 0 ? rand()%e.alpha / 360.0 * 2 * M_PI : e.alpha;
	p->state.p.x = e.p.x + e.startR * cos(e.rotation / 360.0 * 2 * M_PI + randRotation);
	p->state.p.y = e.p.y + e.startR * sin(e.rotation / 360.0 * 2 * M_PI + randRotation);
	p->state.v.x = 0;
	p->state.v.y = 0;

	p->animation.preDuration = 0;
	double randR = e.rMin < e.rMax ? (e.rMin + rand()%(e.rMax - e.rMin)) : e.rMin;
	p->animation.end.p.x = e.startR * cos(e.rotation / 360.0 * 2 * M_PI + randRotation)
		+ e.p.x + randR * cos(e.rotation / 360.0 * 2 * M_PI + randRotation);
	p->animation.end.p.y = e.startR * sin(e.rotation / 360.0 * 2 * M_PI + randRotation)
		+ e.p.y + randR * sin(e.rotation / 360.0 * 2 * M_PI + randRotation);
	p->animation.end.v.x = 0;
	p->animation.end.v.y = 0;

	selectType(e.type, &p);

	p->animation.preDuration += e.preDuration;
	p->animation.start = p->state;
	p->emitter = e;

	addItem(p);
}
void ConsoleTools::viewFile(){
  try{
    // Source file text lines store.
    TextLinesStore textLinesStore;
    textLinesStore.loadFile(inputFileName, inputEncoding, true);
    // parsers factory
    ParserFactory pf(catalogPath);
    // Base editor to make primary parse
    BaseEditor baseEditor(&pf, &textLinesStore);
    // HRD RegionMapper linking
    baseEditor.setRegionMapper(&DString("console"), hrdName);
    FileType *type = selectType(pf.getHRCParser(), &textLinesStore);
    baseEditor.setFileType(type);
    // Initial line count notify
    baseEditor.lineCountEvent(textLinesStore.getLineCount());

    int background;
    const StyledRegion *rd = StyledRegion::cast(baseEditor.rd_def_Text);
    if (rd != null && rd->bfore && rd->bback) background = rd->fore + (rd->back<<4);
    else background = 0x1F;
    // File viewing in console window
    TextConsoleViewer viewer(&baseEditor, &textLinesStore, background, outputEncodingIndex);
    viewer.view();
  }catch(Exception &e){
    fprintf(stderr, "%s\n", e.getMessage()->getChars());
  }catch(...){
    fprintf(stderr, "unknown exception ...\n");
  }
}
void ConsoleTools::profile(int loopCount){
  clock_t msecs;

  // parsers factory
  ParserFactory pf(catalogPath);
  // Source file text lines store.
  TextLinesStore textLinesStore;
  textLinesStore.loadFile(inputFileName, inputEncoding, true);
  // Base editor to make primary parse
  BaseEditor baseEditor(&pf, &textLinesStore);
  // HRD RegionMapper linking
  baseEditor.setRegionMapper(&DString("console"), hrdName);
  FileType *type = selectType(pf.getHRCParser(), &textLinesStore);
  type->getBaseScheme();
  baseEditor.setFileType(type);

  msecs = clock();
  while(loopCount--){
    baseEditor.modifyLineEvent(0);
    baseEditor.lineCountEvent(textLinesStore.getLineCount());
    baseEditor.validate(-1, false);
  }
  msecs = clock() - msecs;

  printf("%ld\n", (msecs*1000)/CLOCKS_PER_SEC );
}
MotionType ParamRectangleFromCenterSize<TFrame, coord>::intersect( const OFX::PenArgs& args )
{
	// intersect center point
	MotionType m = _center.intersect( args );
	if( m._mode != eMotionNone )
	{
		TUTTLE_TCOUT( "intersect center." );
		_selectType = eSelectTypeC;
		return m;
	}
	// intersect borders
	_selectType = selectType( args );
	TUTTLE_TCOUT( "_selectType : " << mapESelectTypeToString( _selectType ) );
	if( _selectType != eSelectTypeNone )
	{
		m._mode = eMotionTranslate;
		m._axis = eAxisXY;
		return m;
	}
	m._mode = eMotionNone;
	m._axis = eAxisNone;
	return m;
}
/**
Set up the CCntSqlStatement objects held by the class.
*/
void CPplCommAddrTable::ConstructL()
	{
	// Statement types
	TCntSqlStatementType insertType(EInsert, KSqlContactCommAddrTableName() );
	TCntSqlStatementType selectType(ESelect, KSqlContactCommAddrTableName() );
	TCntSqlStatementType updateType(EUpdate, KSqlContactCommAddrTableName() );
	TCntSqlStatementType deleteType(EDelete, KSqlContactCommAddrTableName() );

	// Where clauses

	// sizes of the clauses
	const TInt KWhereContactIdBufSize(KCommAddrContactId().Size() +
		KWhereStringEqualsStringFormatText().Size() + KCommAddrContactIdParam().Size() );
	const TInt KWhereCommAddrIdBufSize(KCommAddrId().Size() +
		KWhereStringEqualsStringFormatText().Size() + KCommAddrIdParam().Size() );
	const TInt KWhereAndClauseBufSize(KWhereCommAddrIdBufSize + KSqlAnd().Size() + KWhereCommAddrIdBufSize);

	HBufC* whereContactIdClause = HBufC::NewLC(KWhereContactIdBufSize);
	// for WHERE contact_id = [contact id value]
	whereContactIdClause->Des().AppendFormat(KWhereStringEqualsStringFormatText,
		&KCommAddrContactId, &KCommAddrContactIdParam );

	// for WHERE comm_addr_id = [comm addr id value]
	HBufC* whereCommAddrIdClause = HBufC::NewLC(KWhereCommAddrIdBufSize);
	whereCommAddrIdClause->Des().AppendFormat(KWhereStringEqualsStringFormatText,
		&KCommAddrId, &KCommAddrIdParam );

	// for WHERE value = [value string] AND type = [type value]
	HBufC* whereValueAndTypeClause = HBufC::NewLC(KWhereAndClauseBufSize);
	TPtr whereValueAndTypeClausePtr = whereValueAndTypeClause->Des();
	whereValueAndTypeClausePtr.AppendFormat(KWhereStringEqualsStringFormatText,
		&KCommAddrValue, &KCommAddrValueParam );
	whereValueAndTypeClausePtr.Append(KSqlAnd);
	whereValueAndTypeClausePtr.AppendFormat(KWhereStringEqualsStringFormatText,
		&KCommAddrType, &KCommAddrTypeParam );

	// INSERT

	// insert new comm addr record
	// 	INSERT INTO comm_addr
	//		(comm_addr_id, contact_id, type, value, extra_value, extra_type_info)
	//		VALUES (NULL, [contact id value], [type value],
	//			[value string], [extra value string], [extra type info]);
	//
	iInsertStmnt = TSqlProvider::GetSqlStatementL(insertType);
	iInsertStmnt->SetParamL(KCommAddrId(), KCommAddrIdParam() );
	iInsertStmnt->SetParamL(KCommAddrContactId(), KCommAddrContactIdParam() );
	iInsertStmnt->SetParamL(KCommAddrValue(), KCommAddrValueParam() );
	iInsertStmnt->SetParamL(KCommAddrExtraValue(), KCommAddrExtraValueParam() );
	iInsertStmnt->SetParamL(KCommAddrType(), KCommAddrTypeParam() );
	iInsertStmnt->SetParamL(KCommAddrExtraTypeInfo(), KCommAddrExtraTypeInfoParam() );

	// SELECT

	// select all fields for all comm addrs for a particular item id
	// For a statement in the following format:
	// 	SELECT comm_addr_id, type, value, extra_value,extra_type_info FROM comm_addr
	//		WHERE contact_id = [contact id value];
	//
	iWholeSelectStmnt = TSqlProvider::GetSqlStatementL(selectType);
	iWholeSelectStmnt->SetParamL(KCommAddrId(), KNullDesC() );
	iWholeSelectStmnt->SetParamL(KCommAddrType(), KNullDesC() );
	iWholeSelectStmnt->SetParamL(KCommAddrValue(), KNullDesC() );
	iWholeSelectStmnt->SetParamL(KCommAddrExtraValue(), KNullDesC() );
	iWholeSelectStmnt->SetParamL(KCommAddrExtraTypeInfo(), KNullDesC() );
	iWholeSelectStmnt->SetConditionL(*whereContactIdClause);

	// select fields for contacts that match phone, email or SIP lookup
	// For a statement in the following format:
	// 	SELECT contact_id, extra_value FROM comm_addr
	//		WHERE value = [value string] AND type = [type value];
	//
	iMatchSelectStmnt = TSqlProvider::GetSqlStatementL(selectType);
	iMatchSelectStmnt->SetParamL(KCommAddrContactId(), KNullDesC() );
	iMatchSelectStmnt->SetParamL(KCommAddrExtraValue(), KNullDesC() );
	iMatchSelectStmnt->SetConditionL(*whereValueAndTypeClause);

	// UPDATE

	// update comm addr record
	// For a statement in the following format:
	// 	UPDATE comm_addr SET
	//		contact_id = [contact id value],
	//		type = [type value],
	//		value = [value string],
	//		extra_value = [extra value string]
	//      extra_type_info = [ extra type info ] 
	//		WHERE comm_addr_id = [comm addr id value];
	//
	iUpdateStmnt = TSqlProvider::GetSqlStatementL(updateType);
	iUpdateStmnt->SetParamL(KCommAddrContactId(), KCommAddrContactIdParam() );
	iUpdateStmnt->SetParamL(KCommAddrValue(), KCommAddrValueParam() );
	iUpdateStmnt->SetParamL(KCommAddrExtraValue(), KCommAddrExtraValueParam() );
	iUpdateStmnt->SetParamL(KCommAddrType(), KCommAddrTypeParam() );
	iUpdateStmnt->SetParamL(KCommAddrExtraTypeInfo(), KCommAddrExtraTypeInfoParam() );
	iUpdateStmnt->SetConditionL(*whereCommAddrIdClause);

	// DELETE

	// delete single comm addr record
	// For a statement in the following format:
	// 	DELETE FROM comm_addr WHERE comm_addr_id = [comm addr id value];
	//
	iSingleDeleteStmnt = TSqlProvider::GetSqlStatementL(deleteType);
	iSingleDeleteStmnt->SetConditionL(*whereCommAddrIdClause);

	// delete all comm addrs for a particular contact item
	// For a statement in the following format:
	// 	DELETE FROM comm_addr WHERE contact_id = [contact id value];
	//
	iAllForItemDeleteStmnt = TSqlProvider::GetSqlStatementL(deleteType);
	iAllForItemDeleteStmnt->SetConditionL(*whereContactIdClause);

	CleanupStack::PopAndDestroy(3, whereContactIdClause); // and whereCommAddrIdClause, whereValueAndTypeClause
	}
int ColorerFilter::SendOutput() {
    DString styleType = DString("rgb");

    ap_set_content_type(kFilter->r,"text/html; charset=utf-8");

    try {
        // parsers factory
        ParserFactory pf(catalogPath);
        // HRC loading
        HRCParser *hrcParser = pf.getHRCParser();

        RegionMapper *mapper = null;
        bool useMarkup = false;

        try {
            mapper = pf.createStyledMapper(&styleType, hrdName);
        }
        catch(ParserFactoryException &e) {
            useMarkup = true;
            mapper = pf.createTextMapper(hrdName);
        };

        // Base editor to make primary parse
        BaseEditor baseEditor(&pf, pSource);
        // Using compact regions
        baseEditor.setRegionCompact(true);
        baseEditor.setRegionMapper(mapper);
        baseEditor.lineCountEvent(pSource->getLineCount());
        // Choosing file type
        FileType *type = selectType(hrcParser, pSource->getLine(0));
        baseEditor.setFileType(type);
        // parsing all the text
        baseEditor.validate(-1);

        Hashtable<String*> *docLinkHash = new Hashtable<String*>;
        BucketWriter* myWriter = new BucketWriter(kFilter);
        Writer* escapedWriter = new HtmlEscapesWriter(myWriter);
        Writer* cwrite = myWriter;

#if 0 /* Add Configuration Options to add HTML Header.. etc */
        if()
            cwrite->write(DString("<html>\n<head>\n<style></style>\n</head>\n<body><pre>\n"));
#endif

        cwrite->write(DString("<pre>\n"));
        for(int i = 0; i < pSource->getLineCount(); i++){
            htmlRGBWrite(myWriter, escapedWriter, docLinkHash, 
                         pSource->getLine(i), baseEditor.getLineRegions(i));
        }

#if 0 /* Add Configuration Options to add HTML Header.. etc */
        if()
            cwrite->write(DString("</pre></body></html>\n"));
#endif
        cwrite->write(DString("</pre>\n"));

        myWriter->SendBrigade();
        delete docLinkHash;
        delete escapedWriter;
        delete myWriter;
    }
    catch(Exception &e) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, kFilter->r, 
                      "ColorerFilter::SendOutput(): uncaught exception: %s",
                      e.getMessage()->getChars());    
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    catch(...) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, kFilter->r, "ColorerFilter::SendOutput(): unknown exception!");    
        return HTTP_INTERNAL_SERVER_ERROR;
    };

    return OK;
}
/**
Set up the CCntSqlStatement objects held by the class.
*/
void CPplGroupsTable::ConstructL()
	{
	// Statement types
	TCntSqlStatementType insertType(EInsert, KSqlContactGroupTableName);
	TCntSqlStatementType selectType(ESelect, KSqlContactGroupTableName);
	TCntSqlStatementType updateType(EUpdate, KSqlContactGroupTableName);
	TCntSqlStatementType deleteType(EDelete, KSqlContactGroupTableName);
	TCntSqlStatementType countContactsType(ESelect, KSqlContactTableName);
	
	// Where clauses

	// sizes of the clauses
	const TInt KWhereGroupClauseBufSize(KGroupContactGroupId().Size() + 
		KWhereStringEqualsStringFormatText().Size() + KGroupContactGroupIdParam().Size() );
	const TInt KWhereMemberClauseBufSize(KGroupContactGroupMemberId().Size() + 
		KWhereStringEqualsStringFormatText().Size() + KGroupContactGroupMemberIdParam().Size() );
	const TInt KWhereOrClauseBufSize(KWhereGroupClauseBufSize + KSqlOr().Size() + KWhereMemberClauseBufSize);
	
	// for WHERE contact_group_id = [contact id value]
	HBufC* whereGroupIdClause = HBufC::NewLC(KWhereGroupClauseBufSize);
	whereGroupIdClause->Des().AppendFormat(KWhereStringEqualsStringFormatText, 
		&KGroupContactGroupId, &KGroupContactGroupIdParam );

	// for WHERE contact_group_member_id = [contact id value]
	HBufC* whereMemberIdClause = HBufC::NewLC(KWhereMemberClauseBufSize);
	whereMemberIdClause->Des().AppendFormat(KWhereStringEqualsStringFormatText, 
		&KGroupContactGroupMemberId, &KGroupContactGroupMemberIdParam );

	// for WHERE contact_group_id = [contact id value] 
	//	OR contact_group_member_id = [contact id value]
	HBufC* whereGroupOrMemberIdClause = HBufC::NewLC(KWhereOrClauseBufSize);
	TPtr whereGroupOrMemberIdClausePtr = whereGroupOrMemberIdClause->Des();
	whereGroupOrMemberIdClausePtr.AppendFormat(KWhereStringEqualsStringFormatText, 
		&KGroupContactGroupId, &KGroupContactGroupIdParam);
	whereGroupOrMemberIdClausePtr.Append(KSqlOr);
	whereGroupOrMemberIdClausePtr.AppendFormat(KWhereStringEqualsStringFormatText, 
		&KGroupContactGroupMemberId, &KGroupContactGroupMemberIdParam);

	// for WHERE contact_id = [contact_id]
	HBufC* whereContactIdClause = HBufC::NewLC(KWhereGroupClauseBufSize);
	whereContactIdClause->Des().AppendFormat(KWhereStringEqualsStringFormatText, 
		&KContactId, &KContactIdParam );
		
	// INSERT

	// insert group-member relationships
	// For a statement in the following format:
	// 	INSERT INTO groups 
	//		(group_id, contact_group_id, contact_group_member_id) 
	//		VALUES (NULL, [contact group id value], [contact group member id value]);
	//
	iInsertStmnt = TSqlProvider::GetSqlStatementL(insertType);
	iInsertStmnt->SetParamL(KGroupContactGroupId(), KGroupContactGroupIdParam());
	iInsertStmnt->SetParamL(KGroupContactGroupMemberId(), KGroupContactGroupMemberIdParam());

	// SELECT
	
	// select group id
	// For a statement in the following format:
	// 	SELECT contact_group_id FROM groups 
	//		WHERE contact_group_member_id = [contact id value];
	//
	iSelectGroupsStmnt = TSqlProvider::GetSqlStatementL(selectType);
	iSelectGroupsStmnt->SetParamL(KGroupContactGroupId(), KNullDesC() );
	iSelectGroupsStmnt->SetConditionL(*whereMemberIdClause);

	// select member id
	// For a statement in the following format:
	// 	SELECT contact_group_member_id FROM groups 
	//		WHERE contact_group_id = [contact id value];
	//
	iSelectMembersStmnt = TSqlProvider::GetSqlStatementL(selectType);
	iSelectMembersStmnt->SetParamL(KGroupContactGroupMemberId(), KNullDesC() );
	iSelectMembersStmnt->SetConditionL(*whereGroupIdClause);

	// DELETE

	// delete all where group or member equals id
	// For a statement in the following format:
	// 	DELETE FROM groups WHERE contact_group_id = [contact id value]
	//		OR contact_group_member_id = [contact id value];
	//
	iDeleteStmnt = TSqlProvider::GetSqlStatementL(deleteType);
	iDeleteStmnt->SetConditionL(*whereGroupOrMemberIdClause);

	// SELECT
	
	// SELECt count(*) FROM contact WHERE contact_id = [contact_id]
	iCountContactsStmnt = TSqlProvider::GetSqlStatementL(countContactsType);
	iCountContactsStmnt->SetParamL(KSqlCount, KSpace);
	iCountContactsStmnt->SetConditionL(*whereContactIdClause);
	
	CleanupStack::PopAndDestroy(4, whereGroupIdClause); // and whereContactIdClause, whereMemberIdClause, whereGroupOrMemberIdClause
	}
void ConsoleTools::genOutput(bool useTokens){
  try{
    // Source file text lines store.
    TextLinesStore textLinesStore;
    textLinesStore.loadFile(inputFileName, inputEncoding, true);
    // parsers factory
    ParserFactory pf(catalogPath);
    // HRC loading
    HRCParser *hrcParser = pf.getHRCParser();
    // HRD RegionMapper creation
    bool useMarkup = false;
    RegionMapper *mapper = null;
    if (!useTokens){
      try{
        mapper = pf.createStyledMapper(&DString("rgb"), hrdName);
      }catch(ParserFactoryException &){
        useMarkup = true;
        mapper = pf.createTextMapper(hrdName);
      }
    }
    // Base editor to make primary parse
    BaseEditor baseEditor(&pf, &textLinesStore);
    // Using compact regions
    baseEditor.setRegionCompact(true);
    baseEditor.setRegionMapper(mapper);
    baseEditor.lineCountEvent(textLinesStore.getLineCount());
    // Choosing file type
    FileType *type = selectType(hrcParser, &textLinesStore);
    baseEditor.setFileType(type);

    //  writing result into HTML colored stream...
    const RegionDefine *rd = null;
    if (mapper != null) rd = baseEditor.rd_def_Text;

    Writer *escapedWriter = null;
    Writer *commonWriter = null;
    try{
      if (outputFileName != null) commonWriter = new FileWriter(outputFileName, outputEncodingIndex, bomOutput);
      else commonWriter = new StreamWriter(stdout, outputEncodingIndex, bomOutput);
      if (htmlEscaping) escapedWriter = new HtmlEscapesWriter(commonWriter);
      else escapedWriter = commonWriter;
    }catch(Exception &e){
      fprintf(stderr, "can't open file '%s' for writing:\n", outputFileName->getChars());
      fprintf(stderr, e.getMessage()->getChars());
      return;
    }

    if (htmlWrapping && useTokens){
      commonWriter->write(DString("<html>\n<head>\n<style></style>\n</head>\n<body><pre>\n"));
    }else if (htmlWrapping && rd != null){
      if (useMarkup){
        commonWriter->write(TextRegion::cast(rd)->stext);
      }else{
        commonWriter->write(DString("<html><body style='"));
        ParsedLineWriter::writeStyle(commonWriter, StyledRegion::cast(rd));
        commonWriter->write(DString("'><pre>\n"));
      }
    }

    if (copyrightHeader){
      commonWriter->write(DString("Created with colorer-take5 library. Type '"));
      commonWriter->write(type->getName());
      commonWriter->write(DString("'\n\n"));
    }

    int lni = 0;
    int lwidth = 1;
    int lncount = textLinesStore.getLineCount();
    for(lni = lncount/10; lni > 0; lni = lni/10, lwidth++);

    for(int i = 0; i < lncount; i++){
      if (lineNumbers){
        int iwidth = 1;
        for(lni = i/10; lni > 0; lni = lni/10, iwidth++);
        for(lni = iwidth; lni < lwidth; lni++) commonWriter->write(0x0020);
        commonWriter->write(SString(i));
        commonWriter->write(DString(": "));
      }
      if (useTokens){
        ParsedLineWriter::tokenWrite(commonWriter, escapedWriter, docLinkHash, textLinesStore.getLine(i), baseEditor.getLineRegions(i));
      }else if (useMarkup){
        ParsedLineWriter::markupWrite(commonWriter, escapedWriter, docLinkHash, textLinesStore.getLine(i), baseEditor.getLineRegions(i));
      }else{
        ParsedLineWriter::htmlRGBWrite(commonWriter, escapedWriter, docLinkHash, textLinesStore.getLine(i), baseEditor.getLineRegions(i));
      }
      commonWriter->write(DString("\n"));
    }

    if (htmlWrapping && useTokens){
      commonWriter->write(DString("</pre></body></html>\n"));
    }else if (htmlWrapping && rd != null){
      if (useMarkup){
        commonWriter->write(TextRegion::cast(rd)->etext);
      }else{
        commonWriter->write(DString("</pre></body></html>\n"));
      }
    }

    if (htmlEscaping) delete commonWriter;
    delete escapedWriter;

    delete mapper;
  }catch(Exception &e){
    fprintf(stderr, "%s\n", e.getMessage()->getChars());
  }catch(...){
    fprintf(stderr, "unknown exception ...\n");
  }
}