コード例 #1
0
ファイル: keyval.cpp プロジェクト: qwook/spine
KeyValue *KeyValueParser::parse() {
    KeyValueParser::Token t = getNextToken( dat, &offset, max );

    unsigned int i = 0;
    if (t.type == KeyValueParser::INTEGER) {
        return new KeyValue( KeyValue::INTEGER, t.value );
    } else if (t.type == KeyValueParser::FLOAT) {
        return new KeyValue( KeyValue::FLOAT, t.value );
    } else if (t.type == KeyValueParser::STRING) {
        return new KeyValue( KeyValue::STRING, t.value );
    } else if (t.type == KeyValueParser::OBJSTART) {
        KeyValue *map = new KeyValue( KeyValue::MAP );
        while (true) {
            KeyValueParser::Token t_expect = getNextTokenProtected( dat, &offset, max );
            if (t_expect.type == KeyValueParser::VARIABLE) {
                KeyValueParser::Token variable = getNextToken( dat, &offset, max );
                KeyValueParser::Token eq = getNextToken( dat, &offset, max );
                if (eq.type != KeyValueParser::SETOP) {
                    printf("Error?");
                    exit(1);
                }
                map->insert(variable.value, parse());
            } else {
                char *key = new char[50];
                sprintf(key, "%u", i);
                map->insert(std::string(key), parse());
                delete key;
                i++;
            }
            KeyValueParser::Token end = getNextToken( dat, &offset, max );
            if (end.type == KeyValueParser::COMMA) {
                continue;
            } else if (end.type == KeyValueParser::OBJEND) {
                break;
            }
            printf("Error?");
            throw(1);
        }
        return map;
    }
    printf("Error?");
    throw(1);
}
コード例 #2
0
ファイル: PathTemplate.cpp プロジェクト: gyengep/irrigation
bool PathTemplate::evaluate(const Path& otherPath, KeyValue& parameters) const {
	parameters.clear();

	if (path.size() != otherPath.size()) {
		return false;
	}

	for (size_t i = 0; i < path.size(); ++i) {
		if (isPathSegmentVariable[i]) {
			parameters.insert(std::make_pair(path[i], otherPath[i]));
		} else {
			if (path[i] != otherPath[i]) {
				parameters.clear();
				return false;
			}
		}
	}

	return true;
}