本文整理汇总了C++中rString类的典型用法代码示例。如果您正苦于以下问题:C++ rString类的具体用法?C++ rString怎么用?C++ rString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了rString类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: GetIPFromString
NETWORK_API void NetworkUtility::GetIPAndPortFromString( const rString& input, rString& outIP, unsigned short& outPort )
{
if ( input == "" )
return;
outIP = "";
outPort = INVALID_PORT;
size_t colonCount = std::count( input.begin(), input.end(), ':' );
if ( colonCount == 1 )
{
outIP = GetIPFromString( input );
size_t colonPosition = input.find( ':' );
rString portString = input.substr( colonPosition + 1 );
if ( StringUtility::IsDigitsOnly( portString ) )
{
outPort = GetPortFromString( portString );
}
}
else if ( StringUtility::IsDigitsOnly( input ) )
{
outPort = GetPortFromString( input );
}
else
{
outIP = GetIPFromString( input );
}
}
开发者ID:Robograde,项目名称:Robograde,代码行数:29,代码来源:NetworkUtility.cpp
示例2: CreateSample
//+---------------------------------------------------+
//|bool CreateSample(const rString &path, AudioBuffer* &buffer, const SDL_AudioSpec* sysSpec)
//\---------------------------------------------------+
bool SoundSDL::CreateSample(const rString &path, AudioBuffer* &buffer, const SDL_AudioSpec* sysSpec)
{
///Load the wav and recieve the buffer containing the audio data
if(!m_AudioFile->LoadSample(path.c_str(), m_BufferData))
{
fprintf(stderr, "Failed to load sample %s\n", path.c_str());
return false;
}
buffer->chunkSize = buffer->spec.size;
///Create audio converter using the data from the wav header
int ret = RebuildAudioCVT(m_BufferData, sysSpec);
if(ret < 0)
{
fprintf(stderr, "Failed to build converter: %s\n", path.c_str());
return false;
}
//Convert the loaded data into matching engine format
//If ret == 1 the loaded audio needs not to be converted
if(ret == 1)
{
if(!ConvertBufferData(buffer, m_AudioCVT))
{
fprintf(stderr, "Failed to convert audio: %s\n", path.c_str());
return false;
}
}
return true;
}
开发者ID:Robograde,项目名称:Robograde,代码行数:35,代码来源:SoundSDL.cpp
示例3: RegisterType
/// <summary>
/// Registers a type of logging message.
/// <para>This function should be run once for each type of message the programmer creates.</para>
/// <para>If a parent is supplied the supplied <paramref name="name"/> will be a child to this parent. If a parent
/// is registered with <see cref="Logger::RegisterInterest"/> the childs logging messages will
/// also be seen.</para>
/// <para><paramref name="parent"/> can be left empty if a parent is not desired.</para>
/// <remarks>The parent name supplied with <paramref name="parent"/> needs to be registered before
/// any children can be added</remarks>
/// </summary>
/// <param name="name">Name of the logging message</param>
/// <param name="parent">Parent of the supplied name (optional)</param>
void Logger::RegisterType ( const rString& name, const rString& parent )
{
if ( parent != "" )
{
// If a parent is supplied, find it
rMap<std::string, LogType>::iterator it = LogTypes.find ( parent.c_str( ) );
// Check if parent was found
if ( it != LogTypes.end() )
{
// Create LogType, emplace it and record the child in the parent.
LogType lt;
lt.Parent = parent;
LogTypes.emplace ( name.c_str( ), lt );
it->second.Children.push_back ( name );
}
else
{
cerr << Colors::BRed << "Failed to find parent log type for log type: " << name << Colors::Reset <<
endl;
return;
}
}
else
{
// No parent was supplied so create LogType with no parent.
LogType lt;
lt.Parent = "";
LogTypes.emplace ( name.c_str( ), lt );
}
}
开发者ID:Robograde,项目名称:Robograde,代码行数:43,代码来源:Logger.cpp
示例4: Initialize
//+----------------------------------------------------------------------------+
//|bool Initialize(AudioEngine* engine, const rString &path, SoundType type)
//\----------------------------------------------------------------------------+
bool SoundSDL::Initialize(AudioEngine* engine, const rString &path, SoundType type)
{
AudioEngineSDL* audioEngine = reinterpret_cast<AudioEngineSDL*>(engine);
const SDL_AudioSpec* sysSpec = audioEngine->GetSystemSpec();
m_AudioEngine = audioEngine;
m_Type = type;
m_Name = path;
m_ChunkSize = sysSpec->size;
m_AudioCVT = pNew(SDL_AudioCVT);
m_BufferData = tNew(AudioBuffer);
m_AudioFile = nullptr;
///Check which file format the requested audiofile are
///Only wav and ogg are supported
///Is wave file
if(path.find(".wav", 0) != std::string::npos)
{
m_AudioFile = pNew(WavFileReader);
}
///Is ogg file
else if(path.find(".ogg", 0) != std::string::npos)
{
m_AudioFile = pNew(OggFileReader);
}
///Not supported format
else
{
fprintf(stderr, "SoundSDL. Trying to load unsupported file format %s \n", path.c_str());
return false;
}
m_AudioFile->Initialize();
///Read as sample, read everything into buffer
if(type == SoundType::SAMPLE)
{
CreateSample(path, m_BufferData, sysSpec);
}
///Read as stream, prepare for buffer streaming
else if(type == SoundType::STREAM)
{
CreateStream(path, m_BufferData, sysSpec);
}
else
{
///This should not happend..
fprintf(stderr, "SoundSDL. Unexpected error loading %s while setting sound type \n", path.c_str());
return false;
}
return true;
}
开发者ID:Robograde,项目名称:Robograde,代码行数:57,代码来源:SoundSDL.cpp
示例5: memset
rString NetworkUtility::GetIPFromDNS( const rString& input )
{
rString ip = "";
size_t colonPos = input.find_first_of( ":" );
rString dns = input;
if ( colonPos != std::string::npos )
dns = input.substr( 0, colonPos );
addrinfo* result = nullptr;
addrinfo hints;
memset(&hints, 0, sizeof( addrinfo ) );
hints.ai_family = AF_INET; // TODODB: When IPv6 implemented change this to AF_UNSPEC, for now force IPv4
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
#if PLATFORM == PLATFORM_WINDOWS
DWORD returnValue;
#elif PLATFORM == PLATFORM_LINUX
int returnValue;
#endif
returnValue = getaddrinfo( dns.c_str(), nullptr, &hints, &result );
if ( returnValue != 0 )
{
// TODODB: Handle dns lookup failure somehow
Logger::Log( "Failed DNS lookup with error: " + rString( gai_strerror( returnValue ) ), "Network", LogSeverity::WARNING_MSG );
return ip;
}
// result will be a linked list, use the first entry
void *addr;
if(result->ai_family == AF_INET)
{
sockaddr_in *ipv4 = (struct sockaddr_in *)result->ai_addr;
addr = &(ipv4->sin_addr);
char ipstr[INET_ADDRSTRLEN];
// convert the IP to a string and print it:
inet_ntop(result->ai_family, addr, ipstr, sizeof( ipstr ) );
ip = rString( ipstr );
}
// TODODB: Handle IPv6 when implemented and move inet_ntop to relevant place
//} else { // Is IPv6
//struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
//addr = &(ipv6->sin6_addr);
//}
// Free the linked list
freeaddrinfo( result );
return ip;
}
开发者ID:Robograde,项目名称:Robograde,代码行数:53,代码来源:NetworkUtility.cpp
示例6: CreateShaderProgram
unsigned int rOpenGLGraphicsDevice::CreateShaderProgram(const rString& vertex, const rString& fragment){
GLuint vertexShader;
GLuint fragmentShader;
GLuint programObject;
GLint linked;
vertexShader = CompileShader(GL_VERTEX_SHADER, vertex.c_str());
if (!vertexShader)
return 0;
fragmentShader = CompileShader(GL_FRAGMENT_SHADER, fragment.c_str());
if (!fragmentShader){
glDeleteShader(vertexShader);
return 0;
}
programObject = glCreateProgram();
if (!programObject)
return 0;
glAttachShader(programObject, vertexShader);
glAttachShader(programObject, fragmentShader);
glLinkProgram(programObject);
glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
if (!linked){
GLint infoLen = 0;
glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
if (infoLen > 1){
char* infoLog = new char[infoLen];
glGetProgramInfoLog(programObject, infoLen, NULL, infoLog);
m_lastError.assign(infoLog, infoLen);
delete [] infoLog;
}
glDeleteProgram(programObject);
return 0;
}
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
m_lastError.clear();
return programObject;
}
开发者ID:aedotcom,项目名称:recondite,代码行数:53,代码来源:rOpenGLGraphicsDevice.cpp
示例7:
rString gfx::MaterialBank::GetDir(rString& filename)
{
bool found = false;
for (int i = static_cast<int>(filename.size()); i > 0; i--)
{
if (filename.c_str()[i] == '/' || filename.c_str()[i] == '\\' )
found = true;
if (!found)
{
filename.erase(i);
}
}
return filename;
}
开发者ID:Robograde,项目名称:Robograde,代码行数:15,代码来源:MaterialBank.cpp
示例8:
rString gfx::ShaderProgram::GetDir ( rString filename )
{
bool found = false;
for ( int i = static_cast<int> ( filename.size() ); i > 0; i-- )
{
if ( filename.c_str() [i] == '/' )
{
found = true;
}
if ( !found )
{
filename.erase ( i );
}
}
return filename;
}
开发者ID:Robograde,项目名称:Robograde,代码行数:16,代码来源:ShaderProgram.cpp
示例9: getline
//Creates a shader with defines
void gfx::ShaderProgram::CreateShader ( ifstream* FileStream, GLenum shaderType, const rString& filename,bool print, ShaderDefineContainer& container )
{
rString line;
size_t found;
rString shaderText;
getline(*FileStream, line);
shaderText += line;
shaderText += "\n";
shaderText += container.GetAllDefineLines();
shaderText += container.GetDefinesShaderStage ( shaderType );
bool end = false;
while ( !end )
{
getline ( *FileStream, line );
//search for the end of the shader
found = line.find ( "#include " );
if ( found != rString::npos )
{
int i = static_cast<int> ( found ) + 9; //found + "#include "
rString s;
while ( i < static_cast<int> ( line.length() ) )
{
s += line[i];
i++;
}
rString str = GetDir ( rString ( filename.c_str() ) ) + s;
shaderText += LoadText ( str.c_str() );
shaderText += "\n";
}
else
{
found = line.find ( "#end_shader" );
if ( found != rString::npos )
{
//break loop
end = true;
break;
}
else if ( FileStream->eof() )
{
Logger::Log( "Could not find end of file " + filename, "ShaderProgram", LogSeverity::ERROR_MSG );
return;
}
else
{
shaderText += line;
shaderText += '\n';
}
}
}
if ( shaderText.length() > 0 )
{
Shader* shader = tNew( Shader );
shader->CreateFromString ( shaderText, shaderType, filename,print );
m_Shaders.push_back ( shader );
shaderText.clear();
}
}
开发者ID:Robograde,项目名称:Robograde,代码行数:61,代码来源:ShaderProgram.cpp
示例10: ParseColorProperty
void ruiStylesheetLoader::ParseColorProperty(const rString& name, const rString& value){
int r,g,b,a;
if (sscanf(value.c_str(), "%i %i %i %i", &r, &g, &b, &a) == 4){
m_currentStyle->SetColor(name, rColor(r,g,b,a));
}
}
开发者ID:matthewcpp,项目名称:recondite,代码行数:7,代码来源:ruiStylesheetLoader.cpp
示例11: WrapText
void WrapText(Face* face, const rString& text, const rSize& size, std::function<void(Glyph**, size_t, int, int)> wordFunc){
std::vector<Font::Glyph*> wordGlyphs;
int xPos = 0;
int yPos = face->GetAscender();
int wordWidth = 0;
int spaceLeft = size.x;
int lineCount = 0;
for (size_t i = 0; i < text.size(); i++){
int c = text[i];
if (c == '\n'){
if (wordWidth > spaceLeft){ //current word will not fit on this line
yPos += face->GetLineHeight();
xPos = 0;
}
wordFunc(wordGlyphs.data(), wordGlyphs.size(), xPos, yPos);
wordGlyphs.clear();
yPos += face->GetLineHeight();
xPos = 0;
spaceLeft = size.x;
wordWidth = 0;
}
else{
Font::Glyph* glyph = face->GetGlyph(c);
if (c == ' '){
if (wordWidth + glyph->advance > spaceLeft){ //current word will not fit on this line
yPos += face->GetLineHeight();
xPos = 0;
spaceLeft = size.x;
}
wordFunc(wordGlyphs.data(), wordGlyphs.size(), xPos, yPos);
wordGlyphs.clear();
spaceLeft -= wordWidth + glyph->advance;
xPos += wordWidth + glyph->advance;
wordWidth = 0;
}
else{
wordWidth += glyph->advance;
wordGlyphs.push_back(glyph);
}
}
}
if (wordGlyphs.size() > 0){
wordFunc(wordGlyphs.data(), wordGlyphs.size(), xPos, yPos);
wordGlyphs.clear();
}
}
开发者ID:matthewcpp,项目名称:recondite,代码行数:59,代码来源:rFont.cpp
示例12:
rString gfx::TextureAtlas::GetDir ( rString str )
{
bool found = false;
for ( int i = static_cast<int> ( str.size() ); i > 0; i-- )
{
if ( str.c_str() [i] == '/' )
{
found = true;
}
if ( !found )
{
str.erase ( i );
}
}
return str;
}
开发者ID:Robograde,项目名称:Robograde,代码行数:17,代码来源:TextureAtlas.cpp
示例13: rString
void GUIEngine::SetWindowClickThrough( const rString& name, bool clickThrough )
{
auto windowIt = m_Windows.find( name ) ;
if( windowIt != m_Windows.end() )
windowIt->second->SetClickThrough( clickThrough );
else
Logger::Log( "Couldn't get window: " + rString( name.c_str()) + ", it doesn't exist.", "GUIEngine", LogSeverity::ERROR_MSG );
}
开发者ID:Robograde,项目名称:Robograde,代码行数:8,代码来源:GUIEngine.cpp
示例14: GetParseItemMethod
ruiOverlayLoader::ruiParseItemMethod ruiOverlayLoader::GetParseItemMethod (const rString& itemName){
rString item = itemName;
for (size_t i =0; i < itemName.size(); i++)
item[i] = tolower(itemName[i]);
if (s_parseItemMap.count(item))
return s_parseItemMap[item];
else
return NULL;
}
开发者ID:aedotcom,项目名称:recondite,代码行数:11,代码来源:ruiOverlayLoader.cpp
示例15: SDL_GetScancodeFromName
bool KeyBindingCollection::AddMappingWithName( const rString& keyName, ActionIdentifier action, KeyBindingType keyBindType, bool overwrite,
bool clearConflicting, rString* errorString ) {
SDL_Scancode scanCode = SDL_GetScancodeFromName( keyName.c_str() );
if ( scanCode != SDL_SCANCODE_UNKNOWN ) {
return AddMappingWithScancode( scanCode, action, keyBindType, overwrite, clearConflicting, errorString );
} else {
LogInput( "Failed to get scancode from name: " + keyName, "KeyBindings", LogSeverity::WARNING_MSG );
if ( errorString != nullptr ) {
*errorString = "Failed to get scancode from name: " + keyName;
}
return false;
}
}
开发者ID:PeterMerkert,项目名称:input-toi,代码行数:13,代码来源:KeyBindingCollection.cpp
示例16: RegisterInterest
/// <summary>
/// Registers interest in a type of logging message that has been registered with
/// <see cref="Logger::RegisterType"/>.
/// <para>If a parent is registered all its children will also be registered</para>
/// </summary>
/// <param name="name">Path to the file to be read</param>
/// <param name="severityMask">Bitmask of type <see cref="LogSeverity::BitFlag"/></param>
void Logger::RegisterInterest ( const rString& name, int severityMask )
{
rMap<std::string, LogType>::iterator it = LogTypes.find ( name.c_str( ) );
if ( it != LogTypes.end() )
{
// Create interest entry with supplied severitymask and name.
InterestEntry ie;
ie.Parent = it->second.Parent;
ie.SeverityMask = severityMask;
InterestedLogTypes.emplace ( name.c_str( ), ie );
// Add all children as well.
for ( rVector<rString>::iterator chit = it->second.Children.begin();
chit != it->second.Children.end(); ++chit )
{
RegisterInterest ( *chit, severityMask );
}
}
else
{
cerr << Colors::BRed << "Failed to find log type " << name
<< " interest not registered." << Colors::Reset << endl;
}
}
开发者ID:Robograde,项目名称:Robograde,代码行数:30,代码来源:Logger.cpp
示例17: CreateStream
//+---------------------------------------------------+
//|bool CreateStream(const rString &path, AudioBuffer* &buffer, const SDL_AudioSpec* sysSpec)
//\---------------------------------------------------+
bool SoundSDL::CreateStream(const rString &path, AudioBuffer* &buffer, const SDL_AudioSpec* sysSpec)
{
if(!m_AudioFile->OpenStream(path.c_str(), m_ChunkSize, buffer))
{
fprintf(stderr, "Failed to open wav stream %s\n", path.c_str());
return false;
}
///Load the first chunk into memory
if(!m_AudioFile->ReadStream(m_BufferData, m_ChunkSize))
{
fprintf(stderr, "Failed to stream data %s\n", m_Name.c_str());
return false;
}
///Create audio converter using the data from the wav header
int ret = RebuildAudioCVT(m_BufferData, sysSpec);
if(ret < 0)
{
fprintf(stderr, "Failed to build converter: %s\n", path.c_str());
return false;
}
//Convert the loaded data into matching engine format
//If ret == 0 the loaded audio needs not to be converted
if(ret == 1)
{
if(!ConvertBufferData(buffer, m_AudioCVT))
{
fprintf(stderr, "Failed to convert audio: %s\n", path.c_str());
return false;
}
}
return true;
}
开发者ID:Robograde,项目名称:Robograde,代码行数:39,代码来源:SoundSDL.cpp
示例18: GetIPFromDNS
rString NetworkUtility::GetIPFromString( const rString& input )
{
if ( input.find_first_not_of( ".0123456789:" ) != std::string::npos ) // Check if DNS
{
return GetIPFromDNS( input );
}
size_t dotCount = std::count( input.begin(), input.end(), '.' );
if ( dotCount != DOTS_IN_IPv4ADDRESS )
return "";
unsigned int adressParts[4];
rString portString;
rString processString = input;
for ( int i = 0; i < 4; ++i )
{
size_t pos = processString.find_first_of( ".:" );
rString currentAdressPart = processString.substr( 0, pos );
try
{
adressParts[i] = static_cast<unsigned int>( std::stoul( currentAdressPart.c_str() ) );
}
catch ( ... )
{
return "";
}
if ( adressParts[i] >= 256 )
{
return "";
}
processString.erase( 0, pos + 1 );
}
rOStringStream iposs;
iposs << adressParts[0] << "." << adressParts[1] << "." << adressParts[2] << "." << adressParts[3];
return iposs.str();
}
开发者ID:Robograde,项目名称:Robograde,代码行数:36,代码来源:NetworkUtility.cpp
示例19: GetKeyByIndex
bool Archive::GetKeyByIndex(size_t index, rString& key) {
if (index >= _impl->header.entryCount) {
return false;
}
else {
PathData pathData;
_impl->GetEntryInfo(index, pathData);
std::vector<char> searchPathBuffer(pathData.pathSize);
_impl->archiveStream->Seek(_impl->AbsolutePathOffset(pathData.pathOffset), rSeekMode::Beginning);
_impl->archiveStream->Read(searchPathBuffer.data(), pathData.pathSize);
key.assign(searchPathBuffer.data(), searchPathBuffer.size());
return true;
}
}
开发者ID:matthewcpp,项目名称:recondite,代码行数:16,代码来源:rArchive.cpp
示例20: GetParentString
rString Logger::GetParentString ( const rString& name, unsigned int treeHeight )
{
if ( treeHeight == 0 )
{
return "";
}
rMap<std::string, LogType>::const_iterator pit = LogTypes.find ( name.c_str( ) );
if ( pit == LogTypes.end() )
{
return name;
}
else if ( pit->second.Parent == "" )
{
return name;
}
return GetParentString ( pit->second.Parent, treeHeight - 1 ) + NameSeparator.c_str( ) + name;
}
开发者ID:Robograde,项目名称:Robograde,代码行数:17,代码来源:Logger.cpp
注:本文中的rString类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论