本文整理汇总了C++中TextReader::IsOpen方法的典型用法代码示例。如果您正苦于以下问题:C++ TextReader::IsOpen方法的具体用法?C++ TextReader::IsOpen怎么用?C++ TextReader::IsOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextReader
的用法示例。
在下文中一共展示了TextReader::IsOpen方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadTrainingData
void Gesture::LoadTrainingData( char *filename )
{
TextReader *reader = g_app->m_resource->GetTextReader(filename);
DarwiniaReleaseAssert(reader && reader->IsOpen(), "Couldn't open Gesture data file");
reader->ReadLine();
int numSymbols = atoi(reader->GetNextToken());
m_symbols.SetSize( numSymbols );
for( int c = 0; c < numSymbols; ++c )
{
m_symbols.PutData( GestureSymbol(), c );
Classification *theClass = &m_symbols[c].m_classes;
reader->ReadLine();
theClass->m_nextTrainer = atoi(reader->GetNextToken());
if( theClass->m_nextTrainer > 0 )
{
reader->ReadLine();
for( int t = 0; t < theClass->m_nextTrainer; ++t )
{
FeatureSet *fs = &theClass->m_trainers[t];
for( int f = 0; f <= GESTURE_MAX_FEATURES; ++f )
{
fs->f[f] = atof(reader->GetNextToken());
}
}
}
}
delete reader;
TrainSystem();
}
示例2: LoadLanguageCaption
bool LanguageTable::LoadLanguageCaption( Language *lang )
{
TextReader *in = g_fileSystem->GetTextReader( lang->m_path );
if( !in ) return false;
if( !in->IsOpen() )
{
delete in;
return false;
}
//
// Read all the phrases from the language file
while (in->ReadLine())
{
if (!in->TokenAvailable()) continue;
char *key = in->GetNextToken();
char *aString = in->GetRestOfLine();
if( key && aString && stricmp( key, "lang" ) == 0 )
{
//
// Strip trailing '\n'
int stringLength = strlen( aString );
if( aString[stringLength-1] == '\n' )
{
aString[stringLength-1] = '\x0';
}
if( aString[stringLength-2] == '\r' )
{
aString[stringLength-2] = '\x0';
}
snprintf( lang->m_caption, sizeof(lang->m_caption), aString );
lang->m_caption[ sizeof(lang->m_caption) - 1 ] = '\0';
delete in;
return true;
}
}
delete in;
return false;
}
示例3: LoadCoastlines
void EarthData::LoadCoastlines()
{
double startTime = GetHighResTime();
m_islands.EmptyAndDelete();
int numIslands = 0;
char coastFile[1024];
if( g_preferences->GetInt(PREFS_GRAPHICS_LOWRESWORLD) == 0 )
{
strcpy(coastFile, "data/earth/coastlines.dat");
}
else
{
strcpy(coastFile, "data/earth/coastlines-low.dat");
}
TextReader *coastlines = g_fileSystem->GetTextReader( coastFile );
AppAssert( coastlines && coastlines->IsOpen() );
Island *island = NULL;
while( coastlines->ReadLine() )
{
char *line = coastlines->GetRestOfLine();
if( line[0] == 'b' )
{
if( island )
{
m_islands.PutData( island );
}
island = new Island();
++numIslands;
}
else
{
float longitude, latitude;
sscanf( line, "%f %f", &longitude, &latitude );
island->m_points.PutData( new Vector3<float>( longitude, latitude, 0.0f ) );
}
}
delete coastlines;
double totalTime = GetHighResTime() - startTime;
AppDebugOut( "Parsing Coastline data (%d islands) : %dms\n", numIslands, int( totalTime * 1000.0f ) );
}
示例4: Initialise
void EntityBlueprint::Initialise()
{
TextReader *theFile = g_app->m_resource->GetTextReader("stats.txt");
AppReleaseAssert(theFile && theFile->IsOpen(), "Couldn't open stats.txt");
int entityIndex = 0;
while( theFile->ReadLine() )
{
if (!theFile->TokenAvailable()) continue;
AppReleaseAssert(entityIndex < Entity::NumEntityTypes, "Too many entity blueprints defined");
m_names[entityIndex] = strdup(theFile->GetNextToken());
m_stats[entityIndex][0] = iv_atof(theFile->GetNextToken());
m_stats[entityIndex][1] = iv_atof(theFile->GetNextToken());
m_stats[entityIndex][2] = iv_atof(theFile->GetNextToken());
++entityIndex;
}
delete theFile;
}
示例5: LoadBorders
void EarthData::LoadBorders()
{
double startTime = GetHighResTime();
m_borders.EmptyAndDelete();
int numIslands = 0;
Island *island = NULL;
TextReader *international = g_fileSystem->GetTextReader( "data/earth/international.dat" );
AppAssert( international && international->IsOpen() );
while( international->ReadLine() )
{
char *line = international->GetRestOfLine();
if( line[0] == 'b' )
{
if( island )
{
m_borders.PutData( island );
++numIslands;
}
island = new Island();
}
else
{
float longitude, latitude;
sscanf( line, "%f %f", &longitude, &latitude );
island->m_points.PutData( new Vector3<float>( longitude, latitude, 0.0f ) );
}
}
delete international;
double totalTime = GetHighResTime() - startTime;
AppDebugOut( "Parsing International data (%d islands) : %dms\n", numIslands, int( totalTime * 1000.0f ) );
}
示例6: LoadLanguage
void LanguageTable::LoadLanguage(char *_filename, BTree<char *> &_langTable )
{
TextReader *in = g_fileSystem->GetTextReader(_filename);
AppReleaseAssert(in && in->IsOpen(), "Couldn't open language file %s", _filename );
//
// Read all the phrases from the language file
while (in->ReadLine())
{
if (!in->TokenAvailable()) continue;
char *key = in->GetNextToken();
#ifdef TARGET_OS_MACOSX
//
// Special case hack
// If this is the Mac version and there is a replacement string
// Use the replacement string instead
#define MACOSX_MARKER "macosx_"
if( strncmp( key, MACOSX_MARKER, strlen(MACOSX_MARKER) ) == 0 )
{
key += strlen(MACOSX_MARKER);
}
#endif
//
// Make sure the this key isn't already used
if(_langTable.LookupTree(key))
{
//AppDebugOut( "Warning : found duplicate key '%s' in language file %s\n", key, _filename );
_langTable.RemoveData( key );
}
char *aString = strdup( in->GetRestOfLine() );
//
// Make sure a language key always has a some text with it
if( !aString || aString[0] == '\0' )
{
AppDebugOut( "Warning : found key '%s' with no translation in language file %s\n", key, _filename );
if( aString )
{
delete [] aString;
}
continue;
}
//
// Convert the string "\n" into a genuine '\n'
for( unsigned int i = 0; i < strlen(aString)-1; ++i )
{
if( aString[i] == '\\' && aString[i+1] == 'n' )
{
aString[i] = ' ';
aString[i+1] = '\n';
}
}
//
// Strip trailing '\n'
int stringLength = strlen( aString );
if( aString[stringLength-1] == '\n' )
{
aString[stringLength-1] = '\x0';
}
if( aString[stringLength-2] == '\r' )
{
aString[stringLength-2] = '\x0';
}
_langTable.PutData(key, aString);
}
delete in;
}
示例7: LoadCities
void EarthData::LoadCities()
{
float startTime = GetHighResTime();
m_cities.EmptyAndDelete();
TextReader *cities = g_fileSystem->GetTextReader( "data/earth/cities.dat" );
AppAssert( cities && cities->IsOpen() );
int numCities = 0;
while( cities->ReadLine() )
{
char *line = cities->GetRestOfLine();
char name[256];
char country[256];
float latitude, longitude;
int population;
int capital;
strncpy( name, line, 40 );
for( int i = 39; i >= 0; --i )
{
if( name[i] != ' ' )
{
name[i+1] = '\x0';
break;
}
}
strncpy( country, line+41, 40 );
for( int i = 39; i >= 0; --i )
{
if( country[i] != ' ' )
{
country[i+1] = '\x0';
break;
}
}
sscanf( line+82, "%f %f %d %d", &longitude, &latitude, &population, &capital );
City *city = new City();
city->m_name = strdup( strupr(name) );
city->m_country = strdup( strupr(country) );
city->m_longitude = Fixed::FromDouble(longitude);
city->m_latitude = Fixed::FromDouble(latitude);
city->m_population = population;
city->m_capital = capital;
city->SetRadarRange( Fixed::FromDouble(sqrtf( sqrtf(city->m_population) ) / 4.0f) );
m_cities.PutData( city );
++numCities;
}
delete cities;
float totalTime = GetHighResTime() - startTime;
AppDebugOut( "Parsing City data (%d cities) : %dms\n", numCities, int( totalTime * 1000.0f ) );
}
示例8: while
Game::Game()
: m_victoryTimer(-1),
m_recalcTimer(0),
m_winner(-1),
m_maxGameTime(-1),
m_gameTimeWarning(false),
m_lockVictoryTimer(false),
m_lastKnownDefcon(5),
m_gameMode(-1)
{
//
// Load game options
TextReader *in = g_fileSystem->GetTextReader( "data/gameoptions.txt" );
AppAssert(in && in->IsOpen());
while( in->ReadLine() )
{
if( !in->TokenAvailable() ) continue;
char *param = in->GetNextToken();
GameOption *option = new GameOption();
m_options.PutData( option );
strcpy( option->m_name, param );
option->m_min = atof( in->GetNextToken() );
option->m_max = atof( in->GetNextToken() );
option->m_default = atof( in->GetNextToken() );
option->m_change = atoi( in->GetNextToken() );
if( option->m_change == 0 )
{
// Drop down menu - so load the sub options
int numOptions = option->m_max - option->m_min;
numOptions ++;
for( int i = 0; i < numOptions; ++i )
{
in->ReadLine();
char *subOption = strdup( in->GetRestOfLine() );
// Strip trailing \n and \r
int stringLength = strlen(subOption);
if( subOption[stringLength-1] == '\n' ) subOption[stringLength-1] = '\x0';
if( subOption[stringLength-2] == '\r' ) subOption[stringLength-2] = '\x0';
option->m_subOptions.PutData( subOption );
}
}
if( option->m_change == -1 )
{
// String - load default
in->ReadLine();
strcpy( option->m_currentString, in->GetRestOfLine() );
}
}
delete in;
ResetOptions();
#ifdef TESTBED
GetOption("MaxTeams")->m_default = 2;
GetOption("MaxTeams")->m_currentValue = 2;
GetOption("MaxGameRealTime")->m_default = 15;
GetOption("MaxGameRealTime")->m_currentValue = 15;
#endif
m_score.Initialise(MAX_TEAMS);
m_nukeCount.Initialise(MAX_TEAMS);
m_totalNukes.Initialise(MAX_TEAMS);
for( int t = 0; t < MAX_TEAMS; ++t )
{
m_score[t] = 0;
m_nukeCount[t] = 0;
m_totalNukes[t] = 0;
}
}
示例9: SetCurrentLevel
Tutorial::Tutorial( int _startChapter )
: m_currentChapter(-1),
m_nextChapter(-1),
m_nextChapterTimer(0.0f),
m_objectHighlight(-1),
m_miscTimer(-1.0f),
m_worldInitialised(false),
m_startLevel(_startChapter)
{
m_levelName[0] = '\x0';
SetCurrentLevel(1);
//
// Parse the tutorial data file
TextReader *reader = g_fileSystem->GetTextReader( "data/tutorial.txt" );
AppAssert( reader && reader->IsOpen() );
while( reader->ReadLine() )
{
if( !reader->TokenAvailable() ) continue;
char *chapterHeading = reader->GetNextToken();
AppAssert( stricmp( chapterHeading, "CHAPTER" ) == 0 );
TutorialChapter *chapter = new TutorialChapter();
m_chapters.PutData( chapter );
chapter->m_name = strdup( reader->GetNextToken() );
char temp[256];
sprintf( temp, "tutorial_%s", chapter->m_name );
chapter->m_message = strdup( temp );
sprintf( temp, "tutorial_%s_obj", chapter->m_name );
chapter->m_objective = strdup( temp );
while( reader->ReadLine() )
{
if( !reader->TokenAvailable() ) continue;
char *field = reader->GetNextToken();
if( stricmp( field, "END" ) == 0 ) break;
char *value = reader->GetRestOfLine();
if( value ) value[ strlen(value) - 1 ] = '\x0';
if( stricmp( field, "MESSAGE" ) == 0 ) chapter->m_message = strdup(value);
if( stricmp( field, "OBJECTIVE" ) == 0 ) chapter->m_objective = strdup(value);
if( stricmp( field, "WINDOWHIGHLIGHT" ) == 0 ) chapter->m_windowHighlight = strdup(value);
if( stricmp( field, "BUTTONHIGHLIGHT" ) == 0 ) chapter->m_buttonHighlight = strdup(value);
if( stricmp( field, "NEXTCLICKABLE" ) == 0 )
{
chapter->m_nextClickable = true;
chapter->m_objective = strdup( "tutorial_clicknext" );
}
if( stricmp( field, "RESTARTCLICKABLE" ) == 0 )
{
chapter->m_restartClickable = true;
chapter->m_objective = strdup("tutorial_restart_mission");
}
}
}
}