ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/rpc/json/iterator.C
Revision: 1.3
Committed: Wed Sep 5 11:23:15 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -2 lines
Log Message:
removed GPLed code and put license back to BSD

File Contents

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