当前位置: 首页>>代码示例>>C++>>正文


C++ ObjectData::getDataAt方法代码示例

本文整理汇总了C++中ObjectData::getDataAt方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectData::getDataAt方法的具体用法?C++ ObjectData::getDataAt怎么用?C++ ObjectData::getDataAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObjectData的用法示例。


在下文中一共展示了ObjectData::getDataAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: saveToSingleFile

void TextFileStorage::saveToSingleFile()
{

	string str = this->getLocation() + this->getFileName();

	ofstream file( str.c_str(), ios::app);
  
  // Get the initial position of the internal iterator of the Datahandler.
  int pos = this->getInput()->getPosition();
  

  
  if( file.is_open() )
  {
    
  	ObjectData* objectData = NULL;
  	if( onlyCurrent )
  	{
  		// Get the current data object.
  		objectData = getInput()->getCurrentObject();
  	}
  	else
  	{
  		// Get the first data object.
  		objectData = getInput()->getFirstObjectCompleted();  
  	}
    
    // Declare actual field data object.
    FieldData* data; 

		// Loop through all objectData elements in the Datahandler which are finched.
    while( objectData != NULL )
    {

			// Start with a new object.
			file << "\n# BEGIN OF OBJECT\n";
						
			// Loop through all fieldData elements in an objectData object.
			for( int j = 0; j < objectData->getSize(); j++ )
			{
				data = objectData->getDataAt(j);
				

				switch( data->getType() )
				{
					case typeFieldDataInt:
						file << data->getInt() << "\n";
					break;
					
					case typeFieldDataFloat:
						file << data->getFloat() << "\n";
					break;
					
					case typeFieldDataDouble:  
						file << data->getDouble() << "\n";
					break;
					
					case typeFieldDataString:
						file << data->getString() << "\n";
					break;
					
					case typeFieldDataBool:
						if( data->getBool() )
						{
							file << "true\n";
						}
						else
						{
							file << "false\n";
						}
					break;				
				}		
			}
			
			// The end of the object
			file << "# END OF OBJECT\n";
			
			if( onlyCurrent )
			{
				// Stop the loop if only the current object is to be executed.
				objectData = NULL;
			}
			else
			{		
				// Get the next data object.
				objectData = getInput()->getNextObjectCompleted(); 
			} 
			  	
    }
    

	  // Resore the initial position of the internal Datahandler iterator. This is not as it is seposed to be. TODO alter the datahandler internal iterator.
	  getInput()->getObjectAt( pos );
    
    // Close the file.
    file.close();

  }
  else
	{
//.........这里部分代码省略.........
开发者ID:AlbertPluton,项目名称:Tagnlock,代码行数:101,代码来源:TextFileStorage.cpp

示例2: saveToIndividualFile

void TextFileStorage::saveToIndividualFile()
{

	string str;
	ofstream file;

  // Declare actual field data object.
  FieldData* data; 

  // Get the initial position of the internal iterator of the Datahandler.
  int pos = this->getInput()->getPosition();

	ObjectData* objectData = NULL;
	if( onlyCurrent )
	{
		// Get the current data object.
		objectData = getInput()->getCurrentObject();
	}
	else
	{
		// Get the first data object.
		objectData = getInput()->getFirstObjectCompleted();  
	}

	// Loop over all elements in the datahandler
	while( objectData != NULL)
	{

		// Create the file name.
		stringstream integerConvertor;
		integerConvertor << fileNumber++;
		str = this->getLocation() + this->getFileName() + integerConvertor.str();

		// Open the file;
		file.open( str.c_str() );
		
		if( file.is_open() )
		{
			
			// Loop through all fieldData elements in an objectData object.
			for( int j = 0; j < objectData->getSize(); j++ )
			{
				data = objectData->getDataAt(j);
				
				switch( data->getType() )
				{
					case typeFieldDataInt:
						file << data->getInt() << endl;
					break;
					
					case typeFieldDataFloat:
						file << data->getFloat() << endl;
					break;
					
					case typeFieldDataDouble:
						file << data->getDouble() << endl;
					break;
					
					case typeFieldDataString:
						file << data->getString() << endl;
					break;
					
					case typeFieldDataBool:
						if( data->getBool() )
						{
							file << "true" << endl;
						}
						else
						{
							file << "false" << endl;
						}
					break;				
				}		
			}			
			
			file.close();
		}
		else
		{
			//TODO throw
		}		
		
	
		if( onlyCurrent )
		{
			// Stop the loop if only the current object is to be executed.
			objectData = NULL;
		}
		else
		{		
			// Get the next data object.
			objectData = getInput()->getNextObjectCompleted(); 
		} 		
		
		
	}

  // Resore the initial position of the internal Datahandler iterator. This is not as it is seposed to be. TODO alter the datahandler internal iterator.
  (this->getInput())->getObjectAt( pos );

//.........这里部分代码省略.........
开发者ID:AlbertPluton,项目名称:Tagnlock,代码行数:101,代码来源:TextFileStorage.cpp

示例3: main

int main (int argc, const char* argv[] )
{
	
	// Lets start of by defining a Category

	// A vector for the combo field
	vector<string> comboOptions;
	comboOptions.push_back("option 1");
	comboOptions.push_back("option 2");
	comboOptions.push_back("option 3");

	TextField fieldA( "text_A", true, true );
	CheckField fieldB( "check_B", false, true );
	CheckField fieldC( "check_C", false, true );
  ComboField fieldD( "combo_D", true, false, &comboOptions, ComboRadio);
	TextField fieldE( "text_E", false, false );	
	CheckField fieldF( "check_F", false, true );
	double min = -2;
	double max = 6;
	SpinField  fieldG( "spin_G", false, false, NULL, &max, 0.01, true, 3, true );	

	Category category_test;
	category_test.addField(&fieldA);
	category_test.addField(&fieldB);
	category_test.addField(&fieldC);
	category_test.addField(&fieldD);
	category_test.addField(&fieldE);
	category_test.addField(&fieldF);
	category_test.addField(&fieldG);

	category_test.setName("testName");



	// Lets load a second Category from a definition file.
	Category category_GPL;
	category_GPL.loadCategory("src/test/testCategory.txt");
	
	
	// Generate data for these categories and add them to a Datahandler.
	Datahandler dataHandler;
	string location = ""; URIobject uri(location);
	ObjectData* objectData;
	FieldData* fieldData;
	
		
	// Data for the first category
	for( int i = 1; i <= 5; i++ )
	{
		dataHandler.addNewObject( &category_test, &uri );
		objectData = dataHandler.getCurrentObject();
		(objectData->getDataAt( 0 ))->set( (string)"First string" );	
		(objectData->getDataAt( 1 ))->set( true );	
		(objectData->getDataAt( 2 ))->set( false );	
		(objectData->getDataAt( 3 ))->set( (string)"Second string" );
		(objectData->getDataAt( 4 ))->set( (string)"Third string" );
		(objectData->getDataAt( 5 ))->set( true );
		(objectData->getDataAt( 6 ))->set( i );
		//for( int j = 0; j < objectData->getSize(); j++ ) cout << "Type: " << (objectData->getDataAt( j ))->getType() << "\n"; //TODO remove debug line
		//cout << "\n"; //TODO remove debug line
	}
	
	
	// Data for the second category
	bool   read[] = {true, true, false};
	string name[] = {"Bart", "Albert", "Zelda"};
	string sirName[] = { "Employ", "Boss", "Cat"};
	string gender[] = { "Male", "Male", "Male" };
	string birthplace[] = { "Here", "There", "Japan" };
	double birthYear[] = { 1880, 1870, 1990 };
	string birthMonth[] = { "April", "May", "June" };
	double birthDay[] =	{ 1, 2, 3 };
	
	for( int i = 0; i < 3; i++ )
	{
		dataHandler.addNewObject( &category_GPL, &uri );
		objectData = dataHandler.getCurrentObject();
		(objectData->getDataAt( 0 ))->set( read[i] );
		(objectData->getDataAt( 1 ))->set( name[i] );
		(objectData->getDataAt( 2 ))->set( sirName[i] );
		(objectData->getDataAt( 3 ))->set( gender[i] );
		(objectData->getDataAt( 4 ))->set( birthplace[i] );
		(objectData->getDataAt( 5 ))->set( birthYear[i] );
		(objectData->getDataAt( 6 ))->set( birthMonth[i] );
		(objectData->getDataAt( 7 ))->set( birthDay[i] );
	}		

	
	// Display the data
	objectData = dataHandler.getFirstObject();
	for( int i = 0; i < 8; i++ )
	{
		cout << "\n";
		for( int j = 0; j < objectData->getSize(); j++ )
		{
			fieldData = objectData->getDataAt(j);
			printData( fieldData );
		}
		objectData = dataHandler.getNextObject();
	}
//.........这里部分代码省略.........
开发者ID:AlbertPluton,项目名称:Tagnlock,代码行数:101,代码来源:DatahandlerTest.cpp


注:本文中的ObjectData::getDataAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。