Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PointerTracker.h
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * PointerTracker.h
17  * Maintains a JsonPointer from a series of parse events.
18  * Copyright (C) 2014 Simon Newton
19  */
20 
21 #ifndef COMMON_WEB_POINTERTRACKER_H_
22 #define COMMON_WEB_POINTERTRACKER_H_
23 
24 #include <ola/base/Macro.h>
25 #include <ola/web/JsonPointer.h>
26 #include <sstream>
27 #include <string>
28 #include <vector>
29 
30 namespace ola {
31 namespace web {
32 
78  public:
79  explicit PointerTracker(JsonPointer *pointer)
80  : m_pointer(pointer) {
81  }
82 
86  void OpenObject();
87 
92  void SetProperty(const std::string &property);
93 
98  void CloseObject();
99 
105  void OpenArray();
106 
111  void CloseArray();
112 
117  void IncrementIndex();
118 
119  private:
120  enum TokenType {
121  TOKEN_OBJECT,
122  TOKEN_ARRAY,
123  };
124 
125  struct Token {
126  public:
127  TokenType type;
128  int index;
129  bool property_set;
130 
131  explicit Token(TokenType type)
132  : type(type), index(-1), property_set(false) {}
133  };
134 
135  JsonPointer *m_pointer;
136  std::vector<Token> m_tokens;
137 
138  DISALLOW_COPY_AND_ASSIGN(PointerTracker);
139 };
140 } // namespace web
141 } // namespace ola
142 #endif // COMMON_WEB_POINTERTRACKER_H_