SoundPtr ResourceConfig::SafeReadSound(StringParser &theVal) { theVal.SkipWhitespace(); SoundDescriptor aDesc; std::string aName; if(theVal.GetChar()=='(') { theVal.IncrementPos(); theVal.ReadString(aName); EnsureComma(theVal); int aFlags = 0; while(true) { std::string aFlagStr; theVal.ReadString(aFlagStr,true); if(aFlagStr.empty()) break; if(stricmp(aFlagStr.c_str(),"Preload")==0) aFlags |= SoundFlag_Preload; else if(stricmp(aFlagStr.c_str(),"Music")==0) aFlags |= SoundFlag_Music; else if(stricmp(aFlagStr.c_str(),"Muted")==0) aFlags |= SoundFlag_Muted; else throw ConfigObjectException("Unknown sound flag: " + aFlagStr); } aDesc.SetSoundFlags(aFlags,true); EnsureCloseParen(theVal); } else theVal.ReadString(aName); aDesc.mFilePath = ComponentConfig::GetResourceFile(aName); SoundPtr aSound = WindowManager::GetDefaultWindowManager()->DecodeSound(aDesc); if(aSound.get()==NULL) throw ConfigObjectException("Failed to decode sound: " + aDesc.mFilePath); return aSound; }
int ResourceConfig::SafeReadColor(StringParser &theVal) { theVal.SkipWhitespace(); if(theVal.GetChar()=='(') { // special color (std or dec) std::string aType; theVal.IncrementPos(); theVal.ReadString(aType); int aColor = 0; if(stricmp(aType.c_str(),"STD")==0) // standard color { EnsureComma(theVal); std::string aName; theVal.ReadString(aName); const char *aPtr = aName.c_str(); if(stricmp(aPtr,"3DDarkShadow")==0) aColor = ColorScheme::GetColorRef(StandardColor_3DDarkShadow); else if(stricmp(aPtr,"3DFace")==0) aColor = ColorScheme::GetColorRef(StandardColor_3DFace); else if(stricmp(aPtr,"3DHilight")==0) aColor = ColorScheme::GetColorRef(StandardColor_3DHilight); else if(stricmp(aPtr,"3DShadow")==0) aColor = ColorScheme::GetColorRef(StandardColor_3DShadow); else if(stricmp(aPtr,"Scrollbar")==0) aColor = ColorScheme::GetColorRef(StandardColor_Scrollbar); else if(stricmp(aPtr,"ButtonText")==0) aColor = ColorScheme::GetColorRef(StandardColor_ButtonText); else if(stricmp(aPtr,"GrayText")==0) aColor = ColorScheme::GetColorRef(StandardColor_GrayText); else if(stricmp(aPtr,"Hilight")==0) aColor = ColorScheme::GetColorRef(StandardColor_Hilight); else if(stricmp(aPtr,"HilightText")==0) aColor = ColorScheme::GetColorRef(StandardColor_HilightText); else if(stricmp(aPtr,"ToolTipBack")==0) aColor = ColorScheme::GetColorRef(StandardColor_ToolTipBack); else if(stricmp(aPtr,"ToolTipText")==0) aColor = ColorScheme::GetColorRef(StandardColor_ToolTipText); else if(stricmp(aPtr,"MenuBack")==0) aColor = ColorScheme::GetColorRef(StandardColor_MenuBack); else if(stricmp(aPtr,"MenuText")==0) aColor = ColorScheme::GetColorRef(StandardColor_MenuText); else if(stricmp(aPtr,"Back")==0) aColor = ColorScheme::GetColorRef(StandardColor_Back); else if(stricmp(aPtr,"Text")==0) aColor = ColorScheme::GetColorRef(StandardColor_Text); else if(stricmp(aPtr,"Link")==0) aColor = ColorScheme::GetColorRef(StandardColor_Link); else if(stricmp(aPtr,"LinkDown")==0) aColor = ColorScheme::GetColorRef(StandardColor_LinkDown); else throw ConfigObjectException("Invalid standard color: " + aType); } else if(stricmp(aType.c_str(),"DEC")==0) { EnsureComma(theVal); int r,g,b; theVal.ReadValue(r); EnsureComma(theVal); theVal.ReadValue(g); EnsureComma(theVal); theVal.ReadValue(b); aColor = ((r&0xff)<<16) | ((g&0xff)<<8) | (b&0xff); } EnsureCloseParen(theVal); return aColor; } int aColor = 0; for(int i=0; i<6; i++) { aColor<<=4; int aDigit = ResourceConfig_GetHexDigit(theVal.GetChar()); if(aDigit<0) throw ConfigObjectException("Invalid color specification."); aColor |= aDigit; theVal.IncrementPos(); } return aColor; }
bool Arguments::Construct(char * data, int size) { String::Construct(data,size); StringParser parser; parser.Assign(*this); bool error = false; while ( !error && !parser.Eof() ) { if (parser.Is('-')) { parser.Next(); if (parser.Is('-')) parser.Next(); Path * path = new Path(); Append(path); if (parser.ParseWord()) { if (parser.Eof() || parser.SkipWhitespace()) { Path * name = new Path(); Path * value = new Path(); path->Append(name); path->Append(value); name->Assign(parser.Token); if (!parser.Is('-')) { parser.Mark(); while (!parser.Eof() && !parser.IsWhitespace()) parser.Next(); parser.Trap(); if (!parser.Token.IsEmpty()) value->Assign(parser.Token); } } else { error = true; } } else { error = true; } } else { parser.Mark(); while (!parser.Eof() && !parser.IsWhitespace()) parser.Next(); parser.Trap(); if (!parser.Token.IsEmpty()) { Path * path = new Path(); path->Assign(parser.Token); Append(path); } } if ( !error && !parser.Eof() && !parser.SkipWhitespace() && !parser.Is('-')) error = true; } if (error) { Release(false); OutputError("Arguments::Construct - Invalid token in arguments at column %d.",parser.Column()); return false; } else { return true; } }