00001 /*MT* 00002 00003 MediaTomb - http://www.mediatomb.cc/ 00004 00005 dictionary.h - this file is part of MediaTomb. 00006 00007 Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>, 00008 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc> 00009 00010 Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>, 00011 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>, 00012 Leonhard Wimmer <leo@mediatomb.cc> 00013 00014 MediaTomb is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU General Public License version 2 00016 as published by the Free Software Foundation. 00017 00018 MediaTomb is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 version 2 along with MediaTomb; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00026 00027 $Id: dictionary.h 2081 2010-03-23 20:18:00Z lww $ 00028 */ 00029 00032 #ifndef __DICTIONARY_H__ 00033 #define __DICTIONARY_H__ 00034 00035 #include "zmmf/zmmf.h" 00036 #include "sync.h" 00037 00039 class DictionaryElement : public zmm::Object 00040 { 00041 public: 00043 DictionaryElement(zmm::String key, zmm::String value); 00044 00047 void setKey(zmm::String key); 00048 00051 void setValue(zmm::String value); 00052 00054 zmm::String getKey(); 00055 00057 zmm::String getValue(); 00058 00059 protected: 00060 zmm::String key; 00061 zmm::String value; 00062 }; 00063 00065 class Dictionary : public zmm::Object 00066 { 00067 protected: 00069 zmm::Ref<zmm::Array<DictionaryElement> > elements; 00071 zmm::String _encode(char sep1, char sep2); 00072 public: 00073 00075 Dictionary(); 00076 00078 void put(zmm::String key, zmm::String value); 00079 00081 zmm::String get(zmm::String key); 00082 00084 int size(); 00085 00087 void remove(zmm::String key); 00088 00090 zmm::String encode(); 00091 00094 zmm::String encodeSimple(); 00095 00097 void clear(); 00098 00100 void decode(zmm::String url); 00101 00103 void decodeSimple(zmm::String url); 00104 00106 zmm::Ref<Dictionary> clone(); 00107 00110 void merge(zmm::Ref<Dictionary> other); 00111 00113 bool isSubsetOf(zmm::Ref<Dictionary> other); 00114 00116 bool equals(zmm::Ref<Dictionary> other); 00117 00118 zmm::Ref<zmm::Array<DictionaryElement> > getElements(); 00119 00121 inline void optimize() { elements->optimize(); } 00122 }; 00123 00124 00126 class Dictionary_r : public Dictionary 00127 { 00128 public: 00129 Dictionary_r() : Dictionary() 00130 { 00131 mutex = zmm::Ref<Mutex>(new Mutex(true)); 00132 } 00133 00134 inline void put(zmm::String key, zmm::String value) 00135 { 00136 mutex->lock(); 00137 Dictionary::put(key, value); 00138 mutex->unlock(); 00139 } 00140 00141 inline zmm::String get(zmm::String key) 00142 { 00143 mutex->lock(); 00144 zmm::String ret = Dictionary::get(key); 00145 mutex->unlock(); 00146 return ret; 00147 } 00148 00149 inline void remove(zmm::String key) 00150 { 00151 mutex->lock(); 00152 Dictionary::remove(key); 00153 mutex->unlock(); 00154 } 00155 00156 inline zmm::String encode() 00157 { 00158 mutex->lock(); 00159 zmm::String ret = Dictionary::encode(); 00160 mutex->unlock(); 00161 return ret; 00162 } 00163 00164 inline void clear() 00165 { 00166 mutex->lock(); 00167 Dictionary::clear(); 00168 mutex->unlock(); 00169 } 00170 00171 inline void decode(zmm::String url) 00172 { 00173 mutex->lock(); 00174 Dictionary::decode(url); 00175 mutex->unlock(); 00176 } 00177 00178 inline zmm::Ref<Dictionary_r> clone() 00179 { 00180 mutex->lock(); 00181 zmm::Ref<Dictionary_r> ret = RefCast(Dictionary::clone(), Dictionary_r); 00182 mutex->unlock(); 00183 return ret; 00184 } 00185 00186 inline bool isSubsetOf(zmm::Ref<Dictionary> other) 00187 { 00188 mutex->lock(); 00189 bool ret = Dictionary::isSubsetOf(other); 00190 mutex->unlock(); 00191 return ret; 00192 } 00193 00194 inline bool equals(zmm::Ref<Dictionary> other) 00195 { 00196 mutex->lock(); 00197 bool ret = Dictionary::equals(other); 00198 mutex->unlock(); 00199 return ret; 00200 } 00201 00202 inline zmm::Ref<zmm::Array<DictionaryElement> > getElements() 00203 { 00204 mutex->lock(); 00205 zmm::Ref<zmm::Array<DictionaryElement> > ret = Dictionary::getElements(); 00206 mutex->unlock(); 00207 return ret; 00208 } 00209 00210 inline void optimize() 00211 { 00212 mutex->lock(); 00213 Dictionary::optimize(); 00214 mutex->unlock(); 00215 } 00216 00217 protected: 00218 zmm::Ref<Mutex> mutex; 00219 }; 00220 00221 #endif // __DICTIONARY_H__
1.6.1