Fixed a bug in MallocObserver::notify().
[aesalon.git] / src / interface / gdb / StringFollower.cpp
blob30609bd3a32523c9f8a69eabd6c616018f4227f2
1 #include <sstream>
3 #include "StringFollower.h"
5 #include "misc/String.h"
7 namespace Aesalon {
8 namespace Interface {
9 namespace GDB {
11 std::string StringFollower::follow(std::string path) {
12 std::stringstream stream;
13 stream << path;
15 std::string token;
17 while(stream >> token) {
18 if(token[0] == '[') { /* list element */
19 if(token[token.length()-1] != ']') {
20 throw StringFollowerInvalidPathException("Expected terminating ']' at end of token");
22 int number;
23 Misc::String::to<int>(token.substr(1, token.length()-2), number);
25 data = data.to<ParseList>()->get_element(number);
27 else if(token[0] == '\'') { /* tuple element */
28 if(token[token.length()-1] != '\'') {
29 throw StringFollowerInvalidPathException("Expected terminating \' at end of token");
31 std::string key = token.substr(1, token.length()-2);
32 data = data.to<ParseTuple>()->get_element(key);
34 else if(token[0] == '\"') { /* tuple element */
35 if(token[token.length()-1] != '\"') {
36 throw StringFollowerInvalidPathException("Expected terminating \" at end of token");
38 std::string key = token.substr(1, token.length()-2);
39 data = data.to<ParseTuple>()->get_element(key);
41 else if(token == "lhs") { /* left side of a result */
42 data = new ParseString(data.to<ParseResult>()->get_name());
44 else if(token == "rhs") { /* right side of a result */
45 Misc::SmartPointer<ParseResult> result = data.to<ParseResult>();
46 data = result->get_value();
49 if(!data.is_valid()) throw StringFollowerException("NULL value in StringFollower resolution");
52 return data.to<ParseString>()->get_data();
55 } // namespace GDB
56 } // namespace Interface
57 } // namespace Aesalon