bool Phobos::System::KeyboardInputDevice::TryGetActionId(const String_t &name, UInt_t &out) const
{	
	if(name.length() == 1)
	{
		Char_t ch = name[0];

		if(IS_ASCII_CHAR(ch))
		{
			out = static_cast<UInt_t>(ch);
			return true;
		}
		else
			return false;
	}
	else
	{
		UInt_t i = 0;
		for(;stInputKeyNames_g[i].pstrzName != NULL; ++i)
		{				
			if(name.compare(stInputKeyNames_g[i].pstrzName) == 0)
			{
				out = stInputKeyNames_g[i].uKey;
				return true;
			}
		}

		return false;
	}
}
Beispiel #2
0
void Phobos::Register::Table::SetCharMatrix(const String_t &key, const String_t &data, UInt16_t numRows, UInt16_t numColumns)
{	
	CheckForKeyword(key);
	this->CheckInvalidKey(key, parszStringOnlyKeys_g, "should be string data, not matrix");

	if(numRows * numColumns == 0)
	{
		PH_RAISE(INVALID_PARAMETER_EXCEPTION, "Phobos::Register::Table::ParseSpecialValue", "Matrix cannot be empty");
	}

	if(numRows * numColumns != data.length())
	{
		std::stringstream stream;
		stream << "Matrix data size (" << data.length() << ") does not match width (" << numColumns << ") and height (" << numRows << ") parameters";
		PH_RAISE(INVALID_PARAMETER_EXCEPTION, "Phobos::Register::Table::ParseSpecialValue", stream.str());
	}		

	m_mapValues[key] = Value_s(data, numRows, numColumns);
}
Beispiel #3
0
int32_t equals(String_t* self, String_t* anObject) {
    if (self == anObject) {
        return 1;
    }

    String_t *anotherString = (String_t*) anObject;
    int32_t n = self->length(self);
    if (n == anotherString->length(anotherString)) {
        char* v1 = self->toString(self);
        char* v2 = anotherString->toString(anotherString);
        int i = 0;
        while (n-- != 0) {
            if (v1[i] != v2[i]) {
                return 0;
            }
            i++;
        }
        return 1;
    }
    return 0;
}
Beispiel #4
0
void Phobos::Register::Table::ParseSpecialValue(const String_t &idName, Parser &parser)
{
	String_t type;

	ParserTokens_e token;
	if((token = parser.GetToken(&type)) != TOKEN_ID)
	{
		RaiseParseException(parser, TOKEN_ID, token, type, "Phobos::Register::Table::ParseSpecialValue");
	}

	if(type.compare("CharMatrix") == 0)
	{
		if((token = parser.GetToken(NULL)) != TOKEN_OPEN_PAREN)
		{
			RaiseParseException(parser, TOKEN_OPEN_PAREN, token, type, "Phobos::Register::Table::ParseSpecialValue");
		}

		String_t matrix;
		String_t row;

		UInt16_t numColumns = 0;
		UInt16_t numRows = 0;

		bool first = true;
		for(;;)
		{
			token = parser.GetToken(&row);
			if(token == TOKEN_CLOSE_PAREN)
			{
				if(first)
				{
					//do not allow empty matrix
					RaiseParseException(parser, "matrix data", "closing parenthesis", "Phobos::Register::Table::ParseSpecialValue");
				}
					
				this->SetCharMatrix(idName, matrix, numRows, numColumns);
				break;
			}
			else if(token == TOKEN_STRING)
			{
				if(first)
				{
					numColumns = row.length();

					if(numColumns == 0)
						PH_RAISE(PARSER_EXCEPTION, "Phobos::Register::Table::ParseSpecialValue", "Matrix cannot be empty");

					first = false;
				}
				else if(numColumns != row.length())
				{
					PH_RAISE(PARSER_EXCEPTION, "Phobos::Register::Table::ParseSpecialValue", "Matrix rows should always have the same length");
				}

				matrix.append(row);
				++numRows;
			}
			else
			{
				RaiseParseException(parser, TOKEN_STRING, token, row, "Phobos::Register::Table::ParseSpecialValue");
			}
		}
	}	
	else
	{
		RaiseParseException(parser, " valid especial type, ie CharMatrix", type.c_str(), "Phobos::Register::Table::ParseSpecialValue");
	}
}