3
MediaTomb - http://www.mediatomb.cc/
5
dictionary.h - this file is part of MediaTomb.
7
Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
8
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
10
Copyright (C) 2006-2007 Gena Batyan <bgeradz@mediatomb.cc>,
11
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
12
Leonhard Wimmer <leo@mediatomb.cc>
14
MediaTomb is free software; you can redistribute it and/or modify
15
it under the terms of the GNU General Public License version 2
16
as published by the Free Software Foundation.
18
MediaTomb is distributed in the hope that it will be useful,
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
GNU General Public License for more details.
23
You should have received a copy of the GNU General Public License
24
version 2 along with MediaTomb; if not, write to the Free Software
25
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
27
$Id: dictionary.h 1294 2007-05-13 16:28:24Z lww $
30
/// \file dictionary.h
31
/// \brief Definiton of the DictionaryElement and Dictionary classes.
32
#ifndef __DICTIONARY_H__
33
#define __DICTIONARY_H__
35
#include "zmmf/zmmf.h"
38
/// \brief This class should never be used directly, it is being used by the Dictionary class.
39
class DictionaryElement : public zmm::Object
42
/// \brief Constructor, stores the key and the value.
43
DictionaryElement(zmm::String key, zmm::String value);
45
/// \brief Changes the name of the key.
46
/// \param key new key name.
47
void setKey(zmm::String key);
49
/// \brief Changes the key value.
50
/// \param value new value.
51
void setValue(zmm::String value);
53
/// \brief Returns the key for this DictionaryElement.
56
/// \brief Returns the value for this DictionaryElement.
57
zmm::String getValue();
64
/// \brief This class stores key:value pairs of String data and provides functions to access them.
65
class Dictionary : public zmm::Object
68
/// \brief Array of DictionaryElements, representing our Dictionary.
69
zmm::Ref<zmm::Array<DictionaryElement> > elements;
72
/// \brief Constructor, initializes the dictionary.
75
/// \brief Adds a new key:value pair to the dictionary.
76
void put(zmm::String key, zmm::String value);
78
/// \brief Returns the value for a given key.
79
zmm::String get(zmm::String key);
81
/// \brief Returns the number of elements in the dictinary.
84
/// \brief Deletes a key value pair
85
void remove(zmm::String key);
87
/// \brief Returns an url encoded version of the whole dictionary.
90
/// \brief Removes all elements from the dictionary.
93
/// \brief Makes a dictionary out of url encoded data.
94
void decode(zmm::String url);
96
/// \brief Makes a shallow copy of the dictionary
97
zmm::Ref<Dictionary> clone();
99
/// \brief returns true if the dictionary is a subset of another dictionary.#
100
bool isSubsetOf(zmm::Ref<Dictionary> other);
102
/// \brief checks two dictionaries for equality
103
bool equals(zmm::Ref<Dictionary> other);
105
zmm::Ref<zmm::Array<DictionaryElement> > getElements();
107
/// \brief Frees unnecessary memory
108
inline void optimize() { elements->optimize(); }
112
/// \brief Reentrant version of the dictionary
113
class Dictionary_r : public Dictionary
116
Dictionary_r() : Dictionary()
118
mutex = zmm::Ref<Mutex>(new Mutex(true));
121
inline void put(zmm::String key, zmm::String value)
124
Dictionary::put(key, value);
128
inline zmm::String get(zmm::String key)
131
zmm::String ret = Dictionary::get(key);
136
inline void remove(zmm::String key)
139
Dictionary::remove(key);
143
inline zmm::String encode()
146
zmm::String ret = Dictionary::encode();
158
inline void decode(zmm::String url)
161
Dictionary::decode(url);
165
inline zmm::Ref<Dictionary_r> clone()
168
zmm::Ref<Dictionary_r> ret = RefCast(Dictionary::clone(), Dictionary_r);
173
inline bool isSubsetOf(zmm::Ref<Dictionary> other)
176
bool ret = Dictionary::isSubsetOf(other);
181
inline bool equals(zmm::Ref<Dictionary> other)
184
bool ret = Dictionary::equals(other);
189
inline zmm::Ref<zmm::Array<DictionaryElement> > getElements()
192
zmm::Ref<zmm::Array<DictionaryElement> > ret = Dictionary::getElements();
197
inline void optimize()
200
Dictionary::optimize();
205
zmm::Ref<Mutex> mutex;
208
#endif // __DICTIONARY_H__