1 | /*
|
---|
2 | ###############################################################################
|
---|
3 | #
|
---|
4 | # Temboo Arduino library
|
---|
5 | #
|
---|
6 | # Copyright 2014, Temboo Inc.
|
---|
7 | #
|
---|
8 | # Licensed under the Apache License, Version 2.0 (the "License");
|
---|
9 | # you may not use this file except in compliance with the License.
|
---|
10 | # You may obtain a copy of the License at
|
---|
11 | #
|
---|
12 | # http://www.apache.org/licenses/LICENSE-2.0
|
---|
13 | #
|
---|
14 | # Unless required by applicable law or agreed to in writing,
|
---|
15 | # software distributed under the License is distributed on an
|
---|
16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
---|
17 | # either express or implied. See the License for the specific
|
---|
18 | # language governing permissions and limitations under the License.
|
---|
19 | #
|
---|
20 | ###############################################################################
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include <string.h>
|
---|
24 | #include "ChoreoInputSet.h"
|
---|
25 |
|
---|
26 | ChoreoInputSet::ChoreoInputSet() {
|
---|
27 | m_first = NULL;
|
---|
28 | }
|
---|
29 |
|
---|
30 | ChoreoInputSet::~ChoreoInputSet() {
|
---|
31 | ChoreoInput* i = m_first;
|
---|
32 | ChoreoInput* next = NULL;
|
---|
33 | while (i != NULL) {
|
---|
34 | next = i->getNext();
|
---|
35 | delete i;
|
---|
36 | i = next;
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | void ChoreoInputSet::put(const char* name, const char* value) {
|
---|
41 |
|
---|
42 | // Haven't set ANY inputs yet?
|
---|
43 | // Just create a new one.
|
---|
44 | if (m_first == NULL) {
|
---|
45 | m_first = new ChoreoInput(NULL, name, value);
|
---|
46 | } else {
|
---|
47 | // Some inputs already set.
|
---|
48 | // See if we already have this input.
|
---|
49 | ChoreoInput* last = NULL;
|
---|
50 | ChoreoInput* i = m_first;
|
---|
51 | while(i != NULL) {
|
---|
52 | if (strcmp(i->getName(), name) == 0) {
|
---|
53 | // We already have an input with this name.
|
---|
54 | // Just update the value.
|
---|
55 | i->setValue(value);
|
---|
56 | break;
|
---|
57 | }
|
---|
58 | last = i;
|
---|
59 | i = i->getNext();
|
---|
60 | }
|
---|
61 |
|
---|
62 | // We don't have an input with this name
|
---|
63 | // So we need to create a new one.
|
---|
64 | if (i == NULL) {
|
---|
65 | new ChoreoInput(last, name, value);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | const char* ChoreoInputSet::get(const char* name) const {
|
---|
71 | ChoreoInput* i = m_first;
|
---|
72 | while(i != NULL) {
|
---|
73 | if (strcmp(i->getName(), name) == 0) {
|
---|
74 | return i->getValue();
|
---|
75 | }
|
---|
76 | i = i->getNext();
|
---|
77 | }
|
---|
78 | return NULL;
|
---|
79 | }
|
---|
80 |
|
---|