本文整理汇总了C++中IString::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ IString::c_str方法的具体用法?C++ IString::c_str怎么用?C++ IString::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IString
的用法示例。
在下文中一共展示了IString::c_str方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ItemToButton
void LumosGame::ItemToButton( const GameItem* item, gamui::Button* button )
{
CStr<64> text;
// Set the text to the proper name, if we have it.
// Then an icon for what it is, and a check
// mark if the object is in use.
int value = item->GetValue();
const char* name = item->ProperName() ? item->ProperName() : item->Name();
if ( value ) {
text.Format( "%s\n%d", name, value );
}
else {
text.Format( "%s\n ", name );
}
button->SetText( text.c_str() );
IString decoName = item->keyValues.GetIString( "uiIcon" );
RenderAtom atom = LumosGame::CalcUIIconAtom( decoName.c_str(), true );
atom.renderState = (const void*) UIRenderer::RENDERSTATE_UI_DECO_DISABLED;
RenderAtom atomD = LumosGame::CalcUIIconAtom( decoName.c_str(), false );
atomD.renderState = (const void*) UIRenderer::RENDERSTATE_UI_DECO_DISABLED;
button->SetDeco( atom, atomD );
}
示例2: NewDenizen
Chit* LumosChitBag::NewDenizen( const grinliz::Vector2I& pos, int team )
{
const ChitContext* context = Context();
IString itemName;
switch (Team::Group(team)) {
case TEAM_HOUSE: itemName = (random.Bit()) ? ISC::humanFemale : ISC::humanMale; break;
case TEAM_GOB: itemName = ISC::gobman; break;
case TEAM_KAMAKIRI: itemName = ISC::kamakiri; break;
default: GLASSERT(0); break;
}
Chit* chit = NewChit();
const GameItem& root = ItemDefDB::Instance()->Get(itemName.safe_str());
chit->Add( new RenderComponent(root.ResourceName()));
chit->Add( new PathMoveComponent());
const char* altName = 0;
if (Team::Group(team) == TEAM_HOUSE) {
altName = "human";
}
AddItem(root.Name(), chit, context->engine, team, 0, 0, altName);
ReserveBank::Instance()->WithdrawDenizen(chit->GetWallet());
chit->GetItem()->GetTraitsMutable()->Roll( random.Rand() );
chit->GetItem()->GetPersonalityMutable()->Roll( random.Rand(), &chit->GetItem()->Traits() );
chit->GetItem()->FullHeal();
IString nameGen = chit->GetItem()->keyValues.GetIString( "nameGen" );
if ( !nameGen.empty() ) {
LumosChitBag* chitBag = chit->Context()->chitBag;
if ( chitBag ) {
chit->GetItem()->SetProperName(chitBag->NameGen(nameGen.c_str(), chit->ID()));
}
}
AIComponent* ai = new AIComponent();
chit->Add( ai );
chit->Add( new HealthComponent());
chit->SetPosition( (float)pos.x+0.5f, 0, (float)pos.y+0.5f );
chit->GetItem()->SetSignificant(GetNewsHistory(), ToWorld2F(pos), NewsEvent::DENIZEN_CREATED, NewsEvent::DENIZEN_KILLED, 0);
if (XenoAudio::Instance()) {
Vector3F pos3 = ToWorld3F(pos);
XenoAudio::Instance()->PlayVariation(ISC::rezWAV, random.Rand(), &pos3);
}
return chit;
}
示例3: Console
void NewsEvent::Console(GLString* str, ChitBag* chitBag, int shortNameID) const
{
*str = "";
Vector2I sector = ToSector(ToWorld2I(pos));
const GameItem* first = ItemDB::Instance()->Active(firstItemID);
// const GameItem* second = ItemDB::Instance()->Active(secondItemID);
IString firstName = IDToName(firstItemID, firstItemID == shortNameID);
IString secondName = IDToName(secondItemID, secondItemID == shortNameID);
if (firstName.empty()) firstName = StringPool::Intern("[unknown]");
if (secondName.empty()) secondName = StringPool::Intern("[unknown]");
float age = float(double(date) / double(AGE_IN_MSEC));
IString domain;
if (chitBag->Context()->worldMap) {
const SectorData& sd = chitBag->Context()->worldMap->GetSectorData(sector);
domain = sd.name;
}
IString firstTeamName = Team::IsCoreController(firstTeam) ? Team::Instance()->TeamName(firstTeam) : IString();
IString secondTeamName = Team::IsCoreController(secondTeam) ? Team::Instance()->TeamName(secondTeam) : IString();
switch (what) {
case DENIZEN_CREATED:
str->Format("%.2f: Denizen %s " MOB_created " at %s with %s.", age,
firstName.c_str(), domain.safe_str(), firstTeamName.safe_str());
break;
case DENIZEN_KILLED:
str->Format("%.2f: Denizen %s (%s) " MOB_destroyed " at %s by %s.", age,
firstName.safe_str(),
Team::IsRogue(firstTeam) ? "rogue" : firstTeamName.safe_str(),
domain.safe_str(), secondName.safe_str());
break;
case GREATER_MOB_CREATED:
// They get created at the center, then sent. So the domain is meaningless.
str->Format("%.2f: %s " MOB_created ".", age, firstName.safe_str());
break;
case DOMAIN_CREATED:
// "taken over" is interesting; a domain getting created is not.
*str = "";
break;
case ROGUE_DENIZEN_JOINS_TEAM:
str->Format("%.2f: Rogue Denizen %s joins at %s with %s.", age,
firstName.safe_str(), domain.safe_str(), firstTeamName.safe_str() );
break;
case GREATER_MOB_KILLED:
str->Format("%.2f: %s " MOB_destroyed " at %s by %s.", age,
firstName.safe_str(), domain.safe_str(), secondName.safe_str());
break;
case DOMAIN_DESTROYED:
GLASSERT(firstTeam); // how is a neutral destroyed??
str->Format("%.2f: %s domain %s " MOB_destroyed " by %s.", age,
firstTeamName.safe_str(), domain.safe_str(), secondName.safe_str());
break;
// Neutral domains are taken over.
// Subdomains are conquored.
case DOMAIN_TAKEOVER:
str->Format("%.2f: %s occupied by %s.", age, domain.safe_str(), firstTeamName.safe_str());
break;
case DOMAIN_CONQUER:
str->Format("%.2f: %s is conquered by %s.", age, domain.safe_str(), firstTeamName.safe_str() );
break;
case SUPERTEAM_DELETED:
GLASSERT(firstTeam);
str->Format("%.2f: %s super domain %s " MOB_destroyed ". Sub-domains are now self controlled.", age, firstTeamName.safe_str(), domain.safe_str());
break;
case SUBTEAM_DELETED:
GLASSERT(firstTeam);
GLASSERT(secondTeam);
str->Format("%.2f: %s no longer controlled by %s.", age, firstTeamName.safe_str(), secondTeamName.safe_str());
break;
case FORGED:
str->Format("%.2f: %s forged %s at %s.", age, secondName.safe_str(), firstName.c_str(), domain.safe_str());
break;
case UN_FORGED:
str->Format("%.2f: %s " MOB_destroyed " %s at %s.", age, secondName.c_str(), firstName.c_str(), domain.c_str());
break;
case PURCHASED:
if (first) {
str->Format("%.2f: %s purchased %s at %s for %d (%d tax).", age, secondName.c_str(), firstName.c_str(), domain.c_str(),
first->GetValue(), int(first->GetValue() * SALES_TAX));
}
else {
str->Format("%.2f: %s purchased %s at %s.", age, secondName.c_str(), firstName.c_str(), domain.c_str());
}
break;
//.........这里部分代码省略.........
示例4: Play
void XenoAudio::Play(const IString& iSound, const Vector3F* pos)
{
if (!audioOn) return;
// The listener will get updated at the end of the frame,
// so this isn't quite correct. But hopefully good enough
// to prevent saturating the game with sounds all
// over the world.
if ( pos
&& (*pos - listenerPos).LengthSquared() > (MAX_DISTANCE*MAX_DISTANCE))
{
return;
}
Mix_Chunk* chunk = 0;
chunks.Query(iSound, &chunk);
if (!chunk) {
const gamedb::Item* data = database->Root()->Child("data");
const gamedb::Item* item = data->Child(iSound.c_str());
SDL_RWops* fp = 0;
bool needClose = false;
#if 0
// Search external path first.
GLString path;
GLString inPath = "res/";
inPath.append(iSound.c_str());
inPath.append(".wav");
GetSystemPath(GAME_APP_DIR, inPath.c_str(), &path);
fp = SDL_RWFromFile(path.c_str(), "rb");
if (fp) {
needClose = true;
}
#endif
// Now check the database
if (!fp) {
int size = 0;
const void* mem = database->AccessData(item, "binary", &size);
GLASSERT(mem);
fp = SDL_RWFromConstMem(mem, size);
needClose = true;
}
if (fp) {
//U8* buf = 0;
//U32 len = 0;
chunk = Mix_LoadWAV_RW(fp, false);
if (!chunk) {
GLOUTPUT(("Audio error: %s\n", Mix_GetError()));
}
else {
chunks.Add(iSound, chunk);
}
if (needClose) {
SDL_RWclose(fp);
}
}
}
GLASSERT(chunk);
if (chunk) {
int channel = Mix_PlayChannel(-1, chunk, 0);
if (channel >= 0 && channel < CHANNELS ) {
sounds[channel].channel = channel;
sounds[channel].pos.Zero();
if (pos) {
sounds[channel].pos = *pos;
}
SetChannelPos(channel);
}
}
}
示例5: IsisMain
void IsisMain() {
// Get the projection
UserInterface &ui = Application::GetUserInterface();
Pvl pvl(ui.GetFileName("FROM"));
proj = (TProjection *) ProjectionFactory::CreateFromCube(pvl);
// Determine ground range to crop and/or trim
if(ui.WasEntered("MINLAT")) {
slat = ui.GetDouble("MINLAT");
elat = ui.GetDouble("MAXLAT");
slon = ui.GetDouble("MINLON");
elon = ui.GetDouble("MAXLON");
}
else if(proj->HasGroundRange()) {
slat = proj->MinimumLatitude();
elat = proj->MaximumLatitude();
slon = proj->MinimumLongitude();
elon = proj->MaximumLongitude();
}
else {
string msg = "Latitude and longitude range not defined in projection";
throw IException(IException::User, msg, _FILEINFO_);
}
QString mode = ui.GetString("MODE");
IString tempFileName;
if(mode != "TRIM") {
smallestLine = smallestSample = INT_MAX;
biggestLine = biggestSample = -INT_MAX;
ProcessByLine p;
p.SetInputCube("FROM");
p.StartProcess(getSize);
p.EndProcess();
int samples = biggestSample - smallestSample + 1;
int lines = biggestLine - smallestLine + 1;
// Run external crop
QString cropParams = "";
cropParams += "from=" + ui.GetFileName("FROM");
if(mode == "CROP") {
cropParams += " to=" + ui.GetAsString("TO");
}
else {
tempFileName = FileName::createTempFile("TEMPORARYcropped.cub").name();
cropParams += " to=" + tempFileName.ToQt();
}
cropParams += " sample= " + toString(smallestSample);
cropParams += " nsamples= " + toString(samples);
cropParams += " line= " + toString(smallestLine);
cropParams += " nlines= " + toString(lines);
try {
ProgramLauncher::RunIsisProgram("crop", cropParams);
}
catch(IException &e) {
QString msg = "Could not execute crop with params: [" + cropParams + "]";
throw IException(IException::Programmer, msg, _FILEINFO_);
}
if(mode == "BOTH") {
delete proj;
proj = NULL;
Pvl pvl(tempFileName.ToQt());
proj = (TProjection *) ProjectionFactory::CreateFromCube(pvl);
}
}
// Trim image if necessary
if(mode != "CROP") {
ProcessByLine p;
CubeAttributeInput att;
if(mode == "BOTH") {
p.SetInputCube(tempFileName.ToQt(), att);
}
else { //if its trim
p.SetInputCube("FROM");
}
p.SetOutputCube("TO");
p.StartProcess(trim);
p.EndProcess();
if(mode == "BOTH") {
remove(tempFileName.c_str());
}
}
// Add mapping to print.prt
PvlGroup mapping = proj->Mapping();
Application::Log(mapping);
delete proj;
proj = NULL;
}
示例6: NewBuilding
Chit* LumosChitBag::NewBuilding(const Vector2I& pos, const char* name, int team)
{
const ChitContext* context = Context();
Chit* chit = NewChit();
const GameItem& rootItem = ItemDefDB::Instance()->Get(name);
GameItem* item = rootItem.Clone();
// Hack...how to do this better??
if (item->IResourceName() == "pyramid0") {
CStr<32> str;
str.Format("pyramid%d", random.Rand(3));
item->SetResource(str.c_str());
}
if (item->IResourceName() == ISC::kiosk) {
switch (random.Rand(4)) {
case 0: item->SetResource("kiosk.n"); break;
case 1: item->SetResource("kiosk.m"); break;
case 2: item->SetResource("kiosk.s"); break;
default:item->SetResource("kiosk.c"); break;
}
}
int size = 1;
rootItem.keyValues.Get(ISC::size, &size);
int porch = 0;
rootItem.keyValues.Get(ISC::porch, &porch);
const int circuit = 0;
// Should be pre-cleared. But recover from weird situations by clearing.
// Note that water is a real problem.
Rectangle2I r;
r.Set(pos.x, pos.y, pos.x + size - 1, pos.y + size - 1);
for (Rectangle2IIterator it(r); !it.Done(); it.Next()) {
const WorldGrid& wg = context->worldMap->GetWorldGrid(it.Pos());
GLASSERT(wg.IsLand());
(void)wg;
context->worldMap->SetRock(it.Pos().x, it.Pos().y, 0, false, 0);
context->worldMap->SetPlant(it.Pos().x, it.Pos().y, 0, 0);
}
MapSpatialComponent* msc = new MapSpatialComponent();
msc->SetBuilding(size, porch != 0, circuit);
msc->SetBlocks((rootItem.flags & GameItem::PATH_NON_BLOCKING) ? false : true);
chit->Add(msc);
MapSpatialComponent::SetMapPosition(chit, pos.x, pos.y);
chit->Add(new RenderComponent(item->ResourceName()));
chit->Add(new HealthComponent());
AddItem(item, chit, context->engine, team, 0);
IString script = rootItem.keyValues.GetIString("script");
if (!script.empty()) {
Component* s = ComponentFactory::Factory(script.c_str(), &chitContext);
GLASSERT(s);
chit->Add(s);
}
IString proc = rootItem.keyValues.GetIString("procedural");
if (!proc.empty()) {
ProcRenderInfo info;
AssignProcedural(chit->GetItem(), &info);
chit->GetRenderComponent()->SetProcedural(0, info);
}
IString consumes = rootItem.keyValues.GetIString(ISC::zone);
if (!consumes.empty()) {
Component* s = ComponentFactory::Factory("EvalBuildingScript", &chitContext);
GLASSERT(s);
chit->Add(s);
}
IString nameGen = rootItem.keyValues.GetIString( "nameGen");
if ( !nameGen.empty() ) {
IString p = Context()->chitBag->NameGen(nameGen.c_str(), chit->random.Rand());
chit->GetItem()->SetProperName( p );
}
#if 0 // debugging
SectorPort sp;
sp.sector.Set( pos.x/SECTOR_SIZE, pos.y/SECTOR_SIZE );
sp.port = 1;
worldMap->SetRandomPort( sp );
#endif
context->engine->particleSystem->EmitPD( ISC::constructiondone, ToWorld3F( pos ), V3F_UP, 0 );
if (XenoAudio::Instance()) {
Vector3F pos3 = ToWorld3F(pos);
XenoAudio::Instance()->PlayVariation(ISC::rezWAV, random.Rand(), &pos3);
}
return chit;
}
示例7: run
//! Starts the socket thread
void SocketThread::run() {
std::string p_socketFile = ("/tmp/isis_qview_" + Application::UserName()).toAscii().data();
struct sockaddr_un p_socketName;
p_socketName.sun_family = AF_UNIX;
strcpy(p_socketName.sun_path, p_socketFile.c_str());
int p_socket;
// Create a socket
if((p_socket = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
std::string msg = "Unable to create socket";
std::cerr << msg << std::endl;
remove(p_socketFile.c_str());
return;
}
// Setting a timeout didn't work for Mac, so we're using a non-blocking mode
// instead.
fcntl(p_socket, F_SETFL, O_NONBLOCK);
// Bind the file to the socket
int status = bind(p_socket, (struct sockaddr *)&p_socketName, sizeof(p_socketName));
if(status < 0) {
std::string msg = "Unable to bind to socket [" + p_socketFile + "]";
std::cerr << msg << std::endl;
remove(p_socketFile.c_str());
return;
}
// Set up to listen to the socket
if(listen(p_socket, 5) < 0) {
std::string msg = "Unable to listen to socket [" + p_socketFile + "]";
std::cerr << msg << std::endl;
remove(p_socketFile.c_str());
return;
}
p_done = false;
while(!p_done) {
// Accept Socket
socklen_t len = sizeof(&p_socketName);
int childSocket = accept(p_socket, (struct sockaddr *)&p_socketName, &len);
if (childSocket < 0)
if (errno == EWOULDBLOCK) {
msleep(100);
continue; // probably timed out, we cant do anything about this anyways
}
// Receive Data
int bytes;
// This used to be char buf[1024*1024]; but when that line existed the
// mac OS's would crash unpredictably, even when the code on that
// line wasn't executed.
QScopedPointer< char, QScopedPointerArrayDeleter<char> > buf(
new char[1024*1024]);
if((bytes = recv(childSocket, buf.data(), 1024 * 1024, 0)) < 0) {
std::string msg = "Unable to read from socket [" + p_socketFile + "]";
std::cerr << msg << std::endl;
remove(p_socketFile.c_str());
return;
}
// Push everything onto our string buffer
IString buffer;
for(int i = 0; i < bytes; i++) buffer += buf.data()[i];
while(buffer.size() > 0) {
IString token = buffer.Token(" ");
if(token == "raise") {
emit focusApp();
}
else emit newImage(token.c_str());
}
};
}
示例8: str
bool IString::operator !=(const char c) {
IString str ( c ) ;
return this->compare(str.c_str());
}
示例9:
bool IString::operator ==(const IString& string1) {
return !this->compare(string1.c_str());
}