Open Lighting Architecture: common/web/PointerTracker.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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
30namespace ola {
31namespace web {
32
77 class PointerTracker {
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 PointerTracker(const PointerTracker &) = delete;
139 const PointerTracker &operator=(const PointerTracker &) = delete;
140};
141} // namespace web
142} // namespace ola
143#endif // COMMON_WEB_POINTERTRACKER_H_
JsonPointer.h
An implementation of Json Pointers (RFC 6901).
Macro.h
Helper macros.
ola::web::JsonPointer
A JSON pointer (RFC 6901) refers to a possible element in a JSON data structure.
Definition JsonPointer.h:66
ola::web::PointerTracker::OpenObject
void OpenObject()
Open a new Object Element.
Definition PointerTracker.cpp:33
ola::web::PointerTracker::OpenArray
void OpenArray()
Open a new Array Element Note that until IncrementIndex() is called, the array index will be -1....
Definition PointerTracker.cpp:71
ola::web::PointerTracker::CloseArray
void CloseArray()
Close an Array Element If we're not currently in an array this doesn't do anything.
Definition PointerTracker.cpp:78
ola::web::PointerTracker::SetProperty
void SetProperty(const std::string &property)
Set the property name within an Object element. Note if we're not currently in an object element this...
Definition PointerTracker.cpp:40
ola::web::PointerTracker::IncrementIndex
void IncrementIndex()
Increment an array index. If we're not current in an array this doesn't do anything.
Definition PointerTracker.cpp:91
ola::web::PointerTracker::CloseObject
void CloseObject()
Close an Object element. Note if we're not currently in an object element this has no effect.
Definition PointerTracker.cpp:57
ola::web
Classes to deal with web services.
Definition Json.cpp:29
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44