Open Lighting Architecture  Latest Git
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 
139 };
140 } // namespace web
141 } // namespace ola
142 #endif // COMMON_WEB_POINTERTRACKER_H_
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
void CloseObject()
Close an Object element. Note if we&#39;re not currently in an object element this has no effect...
Definition: PointerTracker.cpp:57
void CloseArray()
Close an Array Element If we&#39;re not currently in an array this doesn&#39;t do anything.
Definition: PointerTracker.cpp:78
void IncrementIndex()
Increment an array index. If we&#39;re not current in an array this doesn&#39;t do anything.
Definition: PointerTracker.cpp:91
void SetProperty(const std::string &property)
Set the property name within an Object element. Note if we&#39;re not currently in an object element this...
Definition: PointerTracker.cpp:40
void OpenArray()
Open a new Array Element Note that until IncrementIndex() is called, the array index will be -1...
Definition: PointerTracker.cpp:71
void OpenObject()
Open a new Object Element.
Definition: PointerTracker.cpp:33
A JSON pointer (RFC 6901) refers to a possible element in a JSON data structure.
Definition: JsonPointer.h:66
Helper macros.
An implementation of Json Pointers (RFC 6901).
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Maintains a Json Pointer (RFC 6901) given a set of Json parse events.
Definition: PointerTracker.h:77