1 /******************************************************************************
3 * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
23 #include "base/i2-base.hpp"
24 #include "base/value.hpp"
25 #include <boost/range/iterator.hpp>
32 * An array of Value items.
36 class I2_BASE_API Array : public Object
39 DECLARE_PTR_TYPEDEFS(Array);
42 * An iterator that can be used to iterate over array elements.
44 typedef std::vector<Value>::iterator Iterator;
46 typedef std::vector<Value>::size_type SizeType;
48 Value Get(unsigned int index) const;
49 void Set(unsigned int index, const Value& value);
50 void Add(const Value& value);
55 size_t GetLength(void) const;
56 bool Contains(const String& value) const;
58 void Insert(unsigned int index, const Value& value);
59 void Remove(unsigned int index);
60 void Remove(Iterator it);
62 void Resize(size_t new_size);
65 void CopyTo(const Array::Ptr& dest) const;
66 Array::Ptr ShallowClone(void) const;
68 static Array::Ptr FromJson(cJSON *json);
69 cJSON *ToJson(void) const;
72 std::vector<Value> m_Data; /**< The data for the array. */
75 inline Array::Iterator range_begin(Array::Ptr x)
80 inline Array::Iterator range_end(Array::Ptr x)
91 struct range_mutable_iterator<icinga::Array::Ptr>
93 typedef icinga::Array::Iterator type;
97 struct range_const_iterator<icinga::Array::Ptr>
99 typedef icinga::Array::Iterator type;