ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/rpc/json/iterator.C
Revision: 1.1
Committed: Thu Jul 19 08:24:56 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

# User Rev Content
1 pippijn 1.1 //>>>>>>>>>>> iterator.C <<<<<<<<<<<//
2    
3     #include <json/value.h>
4    
5     namespace json
6     {
7     // class ValueIteratorBase
8     ValueIteratorBase::ValueIteratorBase ()
9     {
10     }
11    
12    
13     ValueIteratorBase::ValueIteratorBase (const Value::ObjectValues::iterator &current)
14     : current_ (current)
15     {
16     }
17    
18     Value &
19     ValueIteratorBase::deref () const
20     {
21     return current_->second;
22     }
23    
24    
25     void
26     ValueIteratorBase::increment ()
27     {
28     ++current_;
29     }
30    
31    
32     void
33     ValueIteratorBase::decrement ()
34     {
35     --current_;
36     }
37    
38    
39     ValueIteratorBase::difference_type
40     ValueIteratorBase::computeDistance (const SelfType &other) const
41     {
42     return difference_type (std::distance (current_, other.current_));
43     }
44    
45    
46     bool
47     ValueIteratorBase::isEqual (const SelfType &other) const
48     {
49     return current_ == other.current_;
50     }
51    
52    
53     void
54     ValueIteratorBase::copy (const SelfType &other)
55     {
56     current_ = other.current_;
57     }
58    
59    
60     Value
61     ValueIteratorBase::key () const
62     {
63     const Value::CZString czstring = (*current_).first;
64     if (czstring.c_str ())
65     {
66     if (czstring.isStaticString ())
67     return Value (StaticString (czstring.c_str ()));
68     return Value (czstring.c_str ());
69     }
70     return Value (czstring.index ());
71     }
72    
73    
74     unsigned
75     ValueIteratorBase::index () const
76     {
77     const Value::CZString czstring = (*current_).first;
78     if (!czstring.c_str ())
79     return czstring.index ();
80     return unsigned (-1);
81     }
82    
83    
84     char const *
85     ValueIteratorBase::memberName () const
86     {
87     char const *name = (*current_).first.c_str ();
88     return name ? name : "";
89     }
90    
91    
92     // class ValueConstIterator
93     ValueConstIterator::ValueConstIterator ()
94     {
95     }
96    
97    
98     ValueConstIterator::ValueConstIterator (const Value::ObjectValues::iterator &current)
99     : ValueIteratorBase (current)
100     {
101     }
102    
103     ValueConstIterator &
104     ValueConstIterator::operator = (const ValueIteratorBase &other)
105     {
106     copy (other);
107     return *this;
108     }
109    
110    
111     // class ValueIterator
112     ValueIterator::ValueIterator ()
113     {
114     }
115    
116    
117     ValueIterator::ValueIterator (const Value::ObjectValues::iterator &current)
118     : ValueIteratorBase (current)
119     {
120     }
121    
122     ValueIterator::ValueIterator (const ValueConstIterator &other)
123     : ValueIteratorBase (other)
124     {
125     }
126    
127     ValueIterator::ValueIterator (const ValueIterator &other)
128     : ValueIteratorBase (other)
129     {
130     }
131    
132     ValueIterator &
133     ValueIterator::operator = (const SelfType &other)
134     {
135     copy (other);
136     return *this;
137     }
138     }