BDE.cc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2009 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #include "BDE.h"
  36. namespace aria2 {
  37. const BDE BDE::none;
  38. BDE::BDE():_type(TYPE_NONE), _bobject(new BObject()) {}
  39. BDE::BDE(Integer integer):_type(TYPE_INTEGER),
  40. _bobject(new BInteger(integer)) {}
  41. BDE::BDE(const std::string& string):_type(TYPE_STRING),
  42. _bobject(new BString(std::string(string))) {}
  43. BDE::BDE(const char* cstring):_type(TYPE_STRING),
  44. _bobject(new BString(std::string(cstring))) {}
  45. BDE::BDE(const char* data, size_t length):
  46. _type(TYPE_STRING),
  47. _bobject(new BString(std::string(&data[0], &data[length]))) {}
  48. BDE::BDE(const unsigned char* data, size_t length):
  49. _type(TYPE_STRING),
  50. _bobject(new BString(std::string(&data[0], &data[length]))) {}
  51. BDE BDE::dict()
  52. {
  53. BDE bde;
  54. bde._type = TYPE_DICT;
  55. bde._bobject.reset(new BDict());
  56. return bde;
  57. }
  58. BDE BDE::list()
  59. {
  60. BDE bde;
  61. bde._type = TYPE_LIST;
  62. bde._bobject.reset(new BList());
  63. return bde;
  64. }
  65. // Test for Null data
  66. bool BDE::isNone() const
  67. {
  68. return _type == TYPE_NONE;
  69. }
  70. // Integer Interface
  71. bool BDE::isInteger() const
  72. {
  73. return _type == TYPE_INTEGER;
  74. }
  75. BDE::Integer BDE::i() const
  76. {
  77. return _bobject->i();
  78. }
  79. // String Interface
  80. bool BDE::isString() const
  81. {
  82. return _type == TYPE_STRING;
  83. }
  84. const std::string& BDE::s() const
  85. {
  86. return _bobject->s();
  87. }
  88. const unsigned char* BDE::uc() const
  89. {
  90. return _bobject->uc();
  91. }
  92. // Dictionary Interface
  93. bool BDE::isDict() const
  94. {
  95. return _type == TYPE_DICT;
  96. }
  97. BDE& BDE::operator[](const std::string& key)
  98. {
  99. return _bobject->operator[](key);
  100. }
  101. const BDE& BDE::operator[](const std::string& key) const
  102. {
  103. if(_bobject->containsKey(key)) {
  104. return _bobject->operator[](key);
  105. } else {
  106. return none;
  107. }
  108. }
  109. bool BDE::containsKey(const std::string& key) const
  110. {
  111. return _bobject->containsKey(key);
  112. }
  113. void BDE::removeKey(const std::string& key)
  114. {
  115. _bobject->removeKey(key);
  116. }
  117. BDE::Dict::iterator BDE::dictBegin()
  118. {
  119. return _bobject->dictBegin();
  120. }
  121. BDE::Dict::const_iterator BDE::dictBegin() const
  122. {
  123. return _bobject->dictBegin();
  124. }
  125. BDE::Dict::iterator BDE::dictEnd()
  126. {
  127. return _bobject->dictEnd();
  128. }
  129. BDE::Dict::const_iterator BDE::dictEnd() const
  130. {
  131. return _bobject->dictEnd();
  132. }
  133. // List Interface
  134. bool BDE::isList() const
  135. {
  136. return _type == TYPE_LIST;
  137. }
  138. void BDE::append(const BDE& bde)
  139. {
  140. _bobject->append(bde);
  141. }
  142. void BDE::operator<<(const BDE& bde)
  143. {
  144. _bobject->operator<<(bde);
  145. }
  146. BDE& BDE::operator[](size_t index)
  147. {
  148. return _bobject->operator[](index);
  149. }
  150. const BDE& BDE::operator[](size_t index) const
  151. {
  152. return _bobject->operator[](index);
  153. }
  154. BDE::List::iterator BDE::listBegin()
  155. {
  156. return _bobject->listBegin();
  157. }
  158. BDE::List::const_iterator BDE::listBegin() const
  159. {
  160. return _bobject->listBegin();
  161. }
  162. BDE::List::iterator BDE::listEnd()
  163. {
  164. return _bobject->listEnd();
  165. }
  166. BDE::List::const_iterator BDE::listEnd() const
  167. {
  168. return _bobject->listEnd();
  169. }
  170. // Callable from List and Dict
  171. size_t BDE::size() const
  172. {
  173. return _bobject->size();
  174. }
  175. // Callable from List and Dict
  176. bool BDE::empty() const
  177. {
  178. return _bobject->empty();
  179. }
  180. } // namespace aria2