예제 #1
0
bool GeneratorNG::loadData(const QByteArray &data)
{
    const QJsonDocument document = QJsonDocument::fromJson(data);

    m_types = readTypes(document);
    m_solvedTypes = solveTypes(m_types);

    m_methods = readMethods(document);

    return !(m_types.isEmpty() || m_solvedTypes.isEmpty() | m_methods.isEmpty());
}
예제 #2
0
bool Foam::edgeMesh::canReadType
(
    const word& ext,
    const bool verbose
)
{
    return checkSupport
           (
               readTypes(),
               ext,
               verbose,
               "reading"
           );
}
bool Foam::UnsortedMeshedSurface<Face>::canReadType
(
    const word& ext,
    const bool verbose
)
{
   return checkSupport
   (
       readTypes() | ParentType::readTypes(),
       ext,
       verbose,
       "reading"
   );
}
예제 #4
0
bool Foam::extendedEdgeMesh::canReadType
(
    const word& ext,
    const bool verbose
)
{
    return edgeMeshFormatsCore::checkSupport
    (
        readTypes(),
        ext,
        verbose,
        "reading"
   );
}
Foam::autoPtr< Foam::UnsortedMeshedSurface<Face> >
Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext)
{
    if (debug)
    {
        Info<< "UnsortedMeshedSurface::New(const fileName&, const word&) : "
            "constructing UnsortedMeshedSurface"
            << endl;
    }

    typename fileExtensionConstructorTable::iterator cstrIter =
        fileExtensionConstructorTablePtr_->find(ext);

    if (cstrIter == fileExtensionConstructorTablePtr_->end())
    {
        // no direct reader, use the parent if possible
        wordHashSet supported = ParentType::readTypes();
        if (supported.found(ext))
        {
            // create indirectly
            autoPtr<UnsortedMeshedSurface<Face> > surf
            (
                new UnsortedMeshedSurface<Face>
            );
            surf().transfer(ParentType::New(name, ext)());

            return surf;
        }

        // nothing left but to issue an error
        supported += readTypes();

        FatalErrorIn
        (
            "UnsortedMeshedSurface<Face>::New"
            "(const fileName&, const word&) : "
            "constructing UnsortedMeshedSurface"
        )   << "Unknown file extension " << ext << nl << nl
            << "Valid types are:" << nl
            << supported
            << exit(FatalError);
    }

    return autoPtr<UnsortedMeshedSurface<Face> >(cstrIter()(name));
}
예제 #6
0
/**
 * Convert the byte array a simple message. Assumes that the byte array is a message.
 * @return a message containing the data specified in the byte stream
 */
OSCMessage& OSCByteArrayToMsgConverter::convertMessage()
{
    OSCMessage* message = new OSCMessage();
    QString addrStr = readString();
    message->setAddress(addrStr);
    QByteArray types = readTypes();
    if(types.isNull()) return *message;

    moveToFourByteBoundry();
    for(int i = 0; i < types.length(); i++) {
        if('[' == types.at(i))
        {
            // we're looking at an array -- read it in
            message->addArgument(readArray(types, ++i));
            // then increment i to the end of the array
            while(']' != types.at(i)) i++;
        }else
            message->addArgument(readArgument(types.at(i)));
    }
    return *message;
}
void join1(char target[800],int threshold)
{
	Result.clear();
	RoadList.clear();
	AnswerList.clear();
	Result.reserve(10000);
	RoadList.reserve(100000);
	AnswerList.reserve(10000);
	int len=0;
	readTypes(target,bmType,page_no_Type,page_size);
	if(len==Result.size())
	{
		printf("Didn`t Find Target1!\n");
		return;
	}
	len=Result.size();
	while(Result.empty()==0)
	{
		Concept *c=Result.front();
		Result.erase(Result.begin());
		RoadList.push_back(new Road(c,c->father,1));
	}
	for(int i=2;i<threshold;i++)
	{
		readSubClassOf(target,bmSubClassOf,page_no_SubClassOf,page_size,threshold);
		while(RoadListTemp.empty()==0)
		{
			Road *r=RoadListTemp.front();
			RoadListTemp.erase(RoadListTemp.begin());
			RoadList.push_back(new Road(r->start,r->end,r->length));
		}
		//("%d\n",i);
	}
	sort(RoadList.begin(),RoadList.end(),ResultSort);
	page_no_Type=0;
	matchTypes(target,bmType,page_no_Type,page_size);
	sort(AnswerList.begin(),AnswerList.end(),AnswerSort);
	for(vector<Answer*>::iterator Iter=AnswerList.begin();Iter!=AnswerList.end()-1;Iter++)
		if(strcmp((*Iter)->name,target)==0||strcmp((*Iter)->name,(*(Iter+1))->name)==0)
		{
			Iter=AnswerList.erase(Iter);
			Iter--;
		}
	char filename[100];
	memset(filename,0,sizeof(filename));
	strcpy(filename,"Schema Integration of ");
	strcat(filename,target);
	strcat(filename," by Join Algorithm 1 at Threshold of ");
	char thre[5];
	memset(thre,0,sizeof(thre));
	_itoa(threshold,thre,10);
	strcat(filename,thre);
	strcat(filename,".txt");
	FILE *IntegrationOut=fopen(filename,"w");
	int SchemaCount=0;
	for(vector<Answer*>::iterator Iter=AnswerList.begin();Iter!=AnswerList.end();Iter++)
	{
		fprintf(IntegrationOut,"%s\t%d\n",(*Iter)->name,(*Iter)->length);
		SchemaCount++;
	}
	fprintf(IntegrationOut,"Integrated Schema Amount:%d\n",SchemaCount);
	printf("Integrated Schema Amount:%d\n",SchemaCount);
	fclose(IntegrationOut);
}
void join2(char target[800],int threshold)
{
	FILE *Length_Type;
	Length_Type=fopen("Length_Type.txt","r");
	char* page = NULL;
	int page_no = 0;
	int offset = 0;
	bmMatch->PinPage(page_no, page);
	char temp[800];
	int total_page = num_page;
	int total_offset = offset;
	int i,j;
	int data=0;
	int length=0;
	char lastRecord[200];
	memset(lastRecord,0,sizeof(lastRecord));
	Concept *c=new Concept();
	Concept *f=new Concept();
	readTypes(target,bmType,page_no_Type,page_size);
	ListTarget.reserve(100);
	while(Result.empty()==0)
	{
		Concept *c=Result.front();
		Result.erase(Result.begin());
		ListTarget.push_back(c);
	}
	Result.clear();
	Result.reserve(100);
	while(page_no <= total_page)
	{
		while(fscanf(Length_Type,"%d",&length)==1)
		{
			c->Clear();
			f->Clear();
			memset(temp,0,sizeof(temp));
			readBytes(bmMatch,temp,length,page,page_no,offset);
			i=1;
			j=0;
			while(temp[i]!=' ')
			{
				c->id[j]=temp[i];
				i++;
				j++;
			}
			i++;
			j=0;
			while(temp[i]!=' ')
			{
				c->name[j]=temp[i];
				i++;
				j++;
			}
			if(strcmp(c->name,"Vern_Graham")==0)
			{
				j+=0;
			}
			i++;
			j=0;
			while(temp[i]!=' ')
			{
				c->type[j]=temp[i];
				i++;
				j++;
			}
			i++;
			j=0;
			while(temp[i]!=' ')
			{
				f->id[j]=temp[i];
				i++;
				j++;
			}
			i++;
			j=0;
			while(temp[i]!=' ')
			{
				f->name[j]=temp[i];
				i++;
				j++;
			}
			i++;
			j=0;
			while(i<(int)strlen(temp))
			{
				f->type[j]=temp[i];
				i++;
				j++;
			}
			//c->father=f;
			//Concept *fcopy=new Concept(f->id,f->name,f->type,f->father);
			//Concept *ccopy=new Concept(c->id,c->name,c->type,fcopy);
			//Result.push_back(ccopy);
			//printf("%s\n",temp);
			//return temp;
			if(strcmp(lastRecord,c->name)==0)
			{
				Concept *fcopy=new Concept(f->id,f->name,f->type,f->father);
				Concept *ccopy=new Concept(c->id,c->name,c->type,fcopy);
				Result.push_back(ccopy);
			}
			else
			{
				//printf("%s\n",lastRecord);
				if(strcmp(lastRecord,"")!=0)
				{
					for(vector<Concept*>::iterator Iter=ListTarget.begin();Iter!=ListTarget.end();Iter++)
					{
						Concept *fcopy=new Concept((*Iter)->father->id,(*Iter)->father->name,(*Iter)->father->type,(*Iter)->father->father);
						Concept *ccopy=new Concept((*Iter)->id,(*Iter)->name,(*Iter)->type,fcopy);
						Result.push_back(ccopy);
					}
					match(target,lastRecord,threshold);
				}
				memset(lastRecord,0,sizeof(lastRecord));
				strcpy(lastRecord,c->name);
				for(vector<Concept*>::iterator Iter=Result.begin();Iter!=Result.end();Iter++)
				{
					delete (*Iter)->father;
					delete *Iter;
				}
				for(vector<Road*>::iterator Iter=RoadList.begin();Iter!=RoadList.end();Iter++)
				{
					//delete (*Iter)->start->father;
					delete (*Iter)->start;
					//delete (*Iter)->end->father;
					delete (*Iter)->end;
					delete *Iter;
				}
				Result.clear();
				RoadList.clear();
				Result.reserve(100);
				RoadList.reserve(10000);
				Concept *fcopy=new Concept(f->id,f->name,f->type,f->father);
				Concept *ccopy=new Concept(c->id,c->name,c->type,fcopy);
				Result.push_back(ccopy);
				//printf("%s\n",temp);
				//return temp;
			}
		}
	}
	fclose(Length_Type);
}
예제 #9
0
/**
 * To read the attributes into memory we first have to get the number of 
 * attribute instances of the structure @link perf_file_attr @endlink. To 
 * achieve this, .attrs.size is divided by the size of the containing structure
 * @link perf_file_attr @endlink. Then we can read the array of instances from 
 * the file offset .attrs.offset. For every instance we have to read the 
 * corresponding IDs. As for the whole structure, there can be several ID's. 
 * .ids.size is used to determine the number of IDs. If only one event source 
 * was used, there is no ID entry since all records belong to the single one 
 * @link perf_file_attr @endlink instance.
 *
 * We check that .attr.sample_id_all is set for all instances. This ensures that
 * all records have an timestamp and an identification entry. All instances are
 * checked that they have the same value for .attr.sample\_type.
 */
static bool readAttr() {
    struct perf_file_attr f_attr;
    
    if( (fheader.attrs.size % sizeof( struct perf_file_attr )) != 0 ){
        char buf[256];
        snprintf( buf, sizeof(buf), "problem with attrs size: %llu %lu", fheader.attrs.size, sizeof( struct perf_file_attr ) );
        set_last_error( ERR_SIZE_MISMATCH, strdup(buf) );
        return false;
    }
    eventAttrCount = fheader.attrs.size / sizeof( struct perf_file_attr );
    eventAttr = (struct event_type_entry *)malloc( sizeof( *eventAttr ) * eventAttrCount );
    
    trysys( lseek( i_fd, fheader.attrs.offset, SEEK_SET ) >= 0 );
    
    /* special case if there is only one event
     * events don't have an ID tag, use default value
     */
    if( eventAttrCount == 1 ){
        try( add_link( -1ULL, &eventAttr[0] ) );
    }
    
    off_t pos = lseek( i_fd, 0, SEEK_CUR );
    unsigned int i;
    for( i = 0; i < eventAttrCount; i++ ){
        trysys( lseek( i_fd, pos, SEEK_SET ) >= 0 );
        try( readn( i_fd, &f_attr, sizeof(f_attr) ) );
        pos = lseek( i_fd, 0, SEEK_CUR );
        trysys( pos >= 0 );
        
        trymsg( f_attr.attr.size == sizeof( f_attr.attr ), ERR_SIZE_MISMATCH, "f_attr.config.size" );
        
        eventAttr[i].attr = f_attr.attr;
        
        if( !f_attr.attr.sample_id_all ){
            set_last_error( ERR_NOT_YET_DEFINED, "need attr.sample_id_all" );
            return false;
        }
        if( i == 0 ){
            samplingType = f_attr.attr.sample_type;
        } else {
            if( samplingType != f_attr.attr.sample_type ){
                set_last_error( ERR_SAMPLES_DIFFER_IN_TYPE, NULL );
                return false;
            }
        }
        
        u64   f_id;
        unsigned int idcount = f_attr.ids.size / sizeof(f_id);
        
        if( idcount > 0 ){
            trysys( lseek( i_fd, f_attr.ids.offset, SEEK_SET ) >= 0 );
            unsigned int k;
            for( k = 0; k < idcount; k++ ){
                try( readn( i_fd, &f_id, sizeof( f_id ) ) );
                try( add_link( f_id, &eventAttr[i] ) );
            }
        }
    }
    
    return true;
}

/**
 * There can also be several instances of the @link perf_trace_event_type
 * @endlink in the file. As before, the .event_types.size is used to determine
 * the number of instances. By comparing .config of the @link perf_file_attr
 * @endlink instances with .event_id of the @link perf_trace_event_type @endlink
 * instances the corresponding pairs are searched. .name from the latter is 
 * assigned to the @link perf_file_attr @endlink instance.
 */
static bool readTypes() {
    unsigned int traceInfoCount = 0;
    struct perf_trace_event_type *traceInfo = NULL;
    
    if( (fheader.event_types.size % sizeof( struct perf_trace_event_type )) != 0 ){
        char buf[256];
        snprintf( buf, sizeof(buf), "problem with event_types size: %llu %lu\n", fheader.event_types.size, sizeof( struct perf_file_header ) );
        set_last_error( ERR_SIZE_MISMATCH, strdup(buf) );
        return false;
    }
    traceInfoCount = fheader.event_types.size / sizeof( struct perf_trace_event_type );
    
    trysys( lseek( i_fd, fheader.event_types.offset, SEEK_SET ) >= 0 );
    
    traceInfo = (struct perf_trace_event_type *)malloc( fheader.event_types.size );
    trysys( traceInfo != NULL );
    
    try( readn( i_fd, traceInfo, fheader.event_types.size ) );
    
    unsigned int i, k;
    for( i = 0; i < eventAttrCount; i++ ){
        for( k = 0; k < traceInfoCount; k++ ){
            if( eventAttr[i].attr.config == traceInfo[k].event_id ){
                memcpy( &eventAttr[i].name, traceInfo[k].name, sizeof(eventAttr[i].name) );
                break;
            }
        }
        if( k == traceInfoCount ){
            char buf[256];
            snprintf( buf, sizeof(buf), "%llu", eventAttr[i].attr.config );
            set_last_error( ERR_TRACE_INFO_NOT_FOUND_FOR_CONFIG, strdup(buf) );
            return false;
        }
    }
    return true;
}

// ---- public ----

u64 get_sampling_type(){
    return  samplingType;
}

bool has_more_events(){
    off_t off = lseek( i_fd, 0, SEEK_CUR );
    trysys( off >= 0 ); //TODO: throw exception
    return off < (int)(fheader.data.offset+fheader.data.size);
}

bool next_event_header( struct perf_event_header* header ){
    try( readn( i_fd, header, sizeof(*header) ) );
    return true;
};

bool read_event_data( union perf_event *evt ){
    try( evt->header.size <= sizeof(*evt) );
    try( readn( i_fd,  &(evt->sample.array[0]), evt->header.size-sizeof(evt->header) ) );
    return true;
};

bool skip_event_data( struct perf_event_header* header ){
    try( lseek( i_fd, header->size-sizeof(*header), SEEK_CUR ) >= 0 );
    return true;
};

/**
 * Reads the perf file header.
 * Testing .magic for the content "PERFFILE" to ensure that we are really 
 * reading a perf file. Comparing the .attr_size with the size of the structure
 * @link perf_file_attr @endlink gives information whether the values 
 * have to be swapped. For readperf, we assume this is not the case.
 */
bool start_session( int fd ){
    i_fd = fd;
    try( readn( i_fd, &fheader, sizeof(fheader) ) );
    
    const char MAGIC[8] = { 'P', 'E', 'R', 'F', 'F', 'I', 'L', 'E' };
    
    if( fheader.magic != *((u64 *)MAGIC) ){
        set_last_error( ERR_NO_PERF_FILE, NULL );
        return false;
    }

    if( fheader.attr_size != sizeof(struct perf_file_attr) ){
        set_last_error( ERR_SIZE_MISMATCH, "maybe needed swap but not implemented" );
        return false;
    };
    
    try( readAttr() );
    try( readTypes() );
    
    trysys( lseek( i_fd, fheader.data.offset, SEEK_SET ) >= 0 );
    return true;
}

unsigned int get_entry_count(){
    return eventAttrCount;
}

struct event_type_entry* get_entry_by_index( unsigned int index ){
    return &eventAttr[index];
};

struct event_type_entry* get_entry( u64 id ){
    unsigned int i;
    for( i = 0; i < linkcount; i++ ){
        if( idlink[i].id == id ){
            return idlink[i].entry;
        }
    }
    set_last_error( ERR_ENTRY_NOT_FOUND, "session:get_entry" );
    return NULL;
};