~ubuntu-branches/ubuntu/utopic/sflphone/utopic

« back to all changes in this revision

Viewing changes to daemon/src/config/yamlnode.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-06-30 11:40:56 UTC
  • mfrom: (4.1.18 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130630114056-0np50jkyqo6vnmii
Tags: 1.2.3-2
* changeset_r92d62cfc54732bbbcfff2b1d36c096b120b981a5.diff 
  - fixes automatic endian detection 
* Update Vcs: fixes vcs-field-not-canonical

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3
3
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
4
4
 *
5
5
 *  This program is free software; you can redistribute it and/or modify
14
14
 *
15
15
 *  You should have received a copy of the GNU General Public License
16
16
 *  along with this program; if not, write to the Free Software
17
 
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
18
18
 *
19
19
 *  Additional permission under GNU GPL version 3 section 7:
20
20
 *
55
55
    for (Sequence::iterator it = doc_.begin(); it != doc_.end(); ++it) {
56
56
        YamlNode *yamlNode = static_cast<YamlNode *>(*it);
57
57
 
58
 
        switch (yamlNode->getType()) {
59
 
            case DOCUMENT:
60
 
                break;
61
 
            case SEQUENCE: {
62
 
                SequenceNode *sequence = static_cast<SequenceNode *>(yamlNode);
63
 
                sequence->deleteChildNodes();
64
 
                delete sequence;
65
 
                sequence = NULL;
66
 
            }
67
 
            break;
68
 
            case MAPPING: {
69
 
                MappingNode *mapping = static_cast<MappingNode *>(yamlNode);
70
 
                mapping->deleteChildNodes();
71
 
                delete mapping;
72
 
                mapping = NULL;
73
 
            }
74
 
            break;
75
 
            case SCALAR: {
76
 
                ScalarNode *scalar = static_cast<ScalarNode *>(yamlNode);
77
 
                delete scalar;
78
 
                scalar = NULL;
79
 
            }
80
 
            break;
81
 
            default:
82
 
                break;
83
 
        }
 
58
        yamlNode->deleteChildNodes();
 
59
        delete yamlNode;
 
60
        yamlNode = NULL;
84
61
    }
85
62
}
86
63
 
89
66
    setKeyValue(tmpKey_, node);
90
67
}
91
68
 
92
 
typedef std::map<std::string, YamlNode*> Mapping;
93
69
 
94
70
void MappingNode::setKeyValue(const std::string &key, YamlNode *value)
95
71
{
98
74
 
99
75
void MappingNode::removeKeyValue(const std::string &key)
100
76
{
101
 
    Mapping::iterator it = map_.find(key);
 
77
    YamlNodeMap::iterator it = map_.find(key);
102
78
    map_.erase(it);
103
79
}
104
80
 
105
81
YamlNode *MappingNode::getValue(const std::string &key) const
106
82
{
107
 
    Mapping::const_iterator it = map_.find(key);
108
 
 
109
 
 
 
83
    YamlNodeMap::const_iterator it = map_.find(key);
110
84
 
111
85
    if (it != map_.end())
112
86
        return it->second;
126
100
 
127
101
void MappingNode::getValue(const std::string &key, int *i) const
128
102
{
129
 
    ScalarNode *node = dynamic_cast<ScalarNode*>(getValue(key));
 
103
    ScalarNode *node = static_cast<ScalarNode*>(getValue(key));
130
104
    if (!node) {
131
105
        ERROR("node %s not found", key.c_str());
132
106
        return;
137
111
 
138
112
void MappingNode::getValue(const std::string &key, std::string *v) const
139
113
{
140
 
    ScalarNode *node = dynamic_cast<ScalarNode*>(getValue(key));
 
114
    ScalarNode *node = static_cast<ScalarNode*>(getValue(key));
141
115
 
142
116
    if (!node) {
143
117
        ERROR("node %s not found", key.c_str());
150
124
 
151
125
void MappingNode::deleteChildNodes()
152
126
{
153
 
    for (Mapping::iterator it = map_.begin(); it != map_.end(); ++it) {
154
 
        YamlNode *yamlNode = dynamic_cast<YamlNode *>(it->second);
 
127
    for (YamlNodeMap::iterator it = map_.begin(); it != map_.end(); ++it) {
 
128
        YamlNode *yamlNode = static_cast<YamlNode *>(it->second);
155
129
 
156
130
        if (!yamlNode)
157
131
            continue;
158
132
 
159
 
        switch (yamlNode->getType()) {
160
 
            case DOCUMENT:
161
 
                break;
162
 
            case SEQUENCE: {
163
 
                SequenceNode *sequence = dynamic_cast<SequenceNode *>(yamlNode);
164
 
                sequence->deleteChildNodes();
165
 
                delete sequence;
166
 
                sequence = NULL;
167
 
            }
168
 
            break;
169
 
            case MAPPING: {
170
 
                MappingNode *mapping = dynamic_cast<MappingNode *>(yamlNode);
171
 
                mapping->deleteChildNodes();
172
 
                delete mapping;
173
 
                mapping = NULL;
174
 
            }
175
 
            break;
176
 
            case SCALAR: {
177
 
                ScalarNode *scalar = dynamic_cast<ScalarNode *>(yamlNode);
178
 
                delete scalar;
179
 
                scalar = NULL;
180
 
            }
181
 
            break;
182
 
            default:
183
 
                break;
184
 
        }
 
133
        yamlNode->deleteChildNodes();
 
134
        delete yamlNode;
 
135
        yamlNode = NULL;
185
136
    }
186
137
}
187
138
 
196
147
    for (Sequence::iterator it = seq_.begin(); it != seq_.end(); ++it) {
197
148
        YamlNode *yamlNode = static_cast<YamlNode *>(*it);
198
149
 
199
 
        switch (yamlNode->getType()) {
200
 
            case DOCUMENT:
201
 
                break;
202
 
            case SEQUENCE: {
203
 
                SequenceNode *sequence = static_cast<SequenceNode *>(yamlNode);
204
 
                sequence->deleteChildNodes();
205
 
                delete sequence;
206
 
            }
207
 
            break;
208
 
            case MAPPING: {
209
 
                MappingNode *mapping = static_cast<MappingNode *>(yamlNode);
210
 
                mapping->deleteChildNodes();
211
 
                delete mapping;
212
 
            }
213
 
            break;
214
 
            case SCALAR: {
215
 
                ScalarNode *scalar = static_cast<ScalarNode *>(yamlNode);
216
 
                delete scalar;
217
 
            }
218
 
            break;
219
 
            default:
220
 
                break;
221
 
        }
 
150
        yamlNode->deleteChildNodes();
 
151
        delete yamlNode;
 
152
        yamlNode = NULL;
222
153
    }
223
154
}
224
155