示例#1
0
bool MetaDataTable::readStarList(std::ifstream& in, std::vector<EMDLabel> *desiredLabels)
{
	setIsList(true);
    long int objectID = addObject();
    EMDLabel label;
    std::string line, firstword, value;
    std::vector<std::string> words;
    std::stringstream ss;
    bool also_has_loop = false;

    // Read data and fill structures accordingly
    while (getline(in, line, '\n'))
    {
    	 tokenize(line, words);

    	 // Ignore empty lines
    	 if (words.size() == 0)
    		 continue;
    	 else
    		 firstword = words[0];

    	 // Get label-value pairs
    	 if (firstword[0] == '_')
    	 {
    		 label = EMDL::str2Label(firstword.substr(1)); // get rid of leading underscore
        	 if (words.size() != 2)
        		 REPORT_ERROR("MetaDataTable::readStarList: did not encounter a single word after "+firstword);
    		 value = words[1];

    		 if (desiredLabels != NULL && !vectorContainsLabel(*desiredLabels, label))
				label = EMDL_UNDEFINED; //ignore if not present in desiredLabels
    		 if (label != EMDL_UNDEFINED)
			 {
				 activeLabels.push_back(label);
				 setValueFromString(label, value, objectID);
			 }
    	 }
    	 // Check whether there is a comment or an empty line
    	 else if (firstword[0] == '#' || firstword[0] == ';')
    	 {
    		 // TODO: handle comments?
    		 continue;
    	 }
    	 // Check whether a loop structure comes after this list
    	 else if (firstword.find("loop_") == 0)
    	 {
    		 also_has_loop = true;
    		 return also_has_loop;
    	 }
    	 // Check whether this data blocks ends (because a next one is there)
    	 else if (firstword.find("data_") == 0)
    	 {
    		 // Should I reverse the pointer one line?
    		 return also_has_loop;
    	 }
     }
     // Reached the end of the file
     return also_has_loop;
}
示例#2
0
bool CVSCPVariable::getVariableFromString( const wxString& strVariable )
{
    wxString strName;			      // Name of variable
    wxString strValue;				  // Variable value
    int		 typeVariable;			  // Type of variable;
    bool	 bPersistent = false;	// Persitence of variable		

    wxStringTokenizer tkz( strVariable, _(",") );

    // Get name of variable
    if ( tkz.HasMoreTokens() ) {
        strName = tkz.GetNextToken();
    }
    else {
        return false;	
    }

    // Get the type of the variable
    if ( tkz.HasMoreTokens() ) {
        typeVariable = CVSCPVariable::getVariableTypeFromString( tkz.GetNextToken() );
    }
    else {
        return false;	
    }

    // Get the persistance of the variable
    if ( tkz.HasMoreTokens() ) {
        wxString str = tkz.GetNextToken();
        str = str.Upper();
        if ( wxNOT_FOUND != str.Find( _("TRUE") ) ) {
            bPersistent = true;
        }
    }
    else {
        return false;	
    }

    // Get the value of the variable
    if ( tkz.HasMoreTokens() ) {
        strValue = tkz.GetNextToken();
        strValue.Upper();
    }
    else {
        return false;	
    }

    // Set values
    m_type = typeVariable;
    m_bPersistent = bPersistent;
    setName( strName );
    setValueFromString( typeVariable, strVariable );

    return true;

}
示例#3
0
void CVSCPVariable::Reset( void )
{
    if ( m_bPersistent ) {
        setValueFromString( m_type, m_persistant );
    }
    else {
        switch ( m_type ) { 

            case VSCP_DAEMON_VARIABLE_CODE_STRING:
                m_strValue = _("");
                break;

            case VSCP_DAEMON_VARIABLE_CODE_BOOLEAN:
                m_boolValue = false;
                break;

            case VSCP_DAEMON_VARIABLE_CODE_INTEGER:
            case VSCP_DAEMON_VARIABLE_CODE_LONG:
                m_longValue = 0;
                break;

            case VSCP_DAEMON_VARIABLE_CODE_DOUBLE:
                m_floatValue = 0;
                break;

            case VSCP_DAEMON_VARIABLE_CODE_VSCP_MEASUREMENT:
                // TODO
                break;

            case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT:
                if ( NULL != m_event.pdata ) {
                    delete [] m_event.pdata;
                }
                m_event.pdata = NULL;
                m_event.crc = 0;
                memset( m_event.GUID, 0, 16 );
                m_event.head = 0;
                m_event.obid = 0;
                m_event.sizeData = 0;
                m_event.timestamp = 0;
                m_event.vscp_class = 0;
                m_event.vscp_type = 0;
                break;

            case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT_GUID:
                memset( m_event.GUID, 0, 16 );
                break;

            case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT_DATA:
                if ( NULL != m_event.pdata ) {
                    delete [] m_event.pdata;
                }
                m_event.pdata = NULL;
                break;

            case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT_CLASS:
                m_event.vscp_class = 0;
                break;

            case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT_TYPE:
                m_event.vscp_type = 0;
                break;

            case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT_TIMESTAMP:
                m_timestamp= m_timestamp.Today();
                break;

            case VSCP_DAEMON_VARIABLE_CODE_UNASSIGNED:
            
                // Fall through - Not allowed here

            default:
                break;
        }
    }
}
示例#4
0
void MetaDataTable::readStarLoop(std::ifstream& in, std::vector<EMDLabel> *desiredLabels)
{
	setIsList(false);

	//Read column labels
    int labelPosition = 0;
    EMDLabel label;
    std::string line, token, value;

    // First read all the column labels
    while (getline(in, line, '\n'))
    {
    	line = simplify(line);
    	// TODO: handle comments...
    	if (line[0] == '#' || line[0] == '\0' || line[0] == ';')
    		continue;

    	if (line[0] == '_') // label definition line
    	{
    		//Only take string from "_" until "#"
    		token = line.substr(line.find("_") + 1, line.find("#") - 2);
    		label = EMDL::str2Label(token);
    		//std::cerr << " label= XX" << label << "XX token= XX" << token<<"XX" << std::endl;
    		if (desiredLabels != NULL && !vectorContainsLabel(*desiredLabels, label))
    			label = EMDL_UNDEFINED; //ignore if not present in desiredLabels

    		if (label == EMDL_UNDEFINED)
    		{
    			//std::cerr << "Warning: ignoring the following (undefined) label:" <<token << std::endl;
    			REPORT_ERROR("ERROR: Unrecognised metadata label: " + token);
    			ignoreLabels.push_back(labelPosition);
    		}
    		else
    			activeLabels.push_back(label);

    		labelPosition++;
    	}
    	else // found first data line
    	{
    		break;
    	}
    }

    // Then fill the table (dont read another line until the one from above has been handled)
    bool is_first= true;
    while (is_first || getline(in, line, '\n'))
    {
    	is_first=false;
    	line = simplify(line);
    	// Stop at empty line
    	if (line[0] == '\0')
    		break;

    	// Add a new line to the table
    	addObject();

    	// Parse data values
    	std::stringstream os2(line);
    	std::string value;
		labelPosition = 0;
		int counterIgnored = 0;
		while (os2 >> value)
		{
			// TODO: handle comments here...
			if (std::find(ignoreLabels.begin(), ignoreLabels.end(), labelPosition) != ignoreLabels.end())
			{
				// Ignore this column
				counterIgnored++;
				labelPosition++;
				continue;
			}
			setValueFromString(activeLabels[labelPosition - counterIgnored], value);
			labelPosition++;
		}

    }

}