Skip to content

Commit c7a5fab

Browse files
committed
add more methods and fix some known issues
1 parent 5ea6de6 commit c7a5fab

File tree

12 files changed

+77
-26
lines changed

12 files changed

+77
-26
lines changed

include/plist/Array.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public :
4343
typedef std::vector<Node*>::const_iterator const_iterator;
4444

4545
Node* operator[](unsigned int index);
46+
Node *back();
47+
Node *Back();
4648
iterator Begin();
4749
iterator begin();
4850
iterator End();
@@ -52,20 +54,18 @@ public :
5254
const_iterator End() const;
5355
const_iterator end() const;
5456
size_t size() const;
55-
void Append(Node* node);
56-
void Insert(Node* node, unsigned int pos);
57+
void Append(const Node &node);
58+
void Append(const Node* node);
59+
void Insert(const Node &node, unsigned int pos);
60+
void Insert(const Node* node, unsigned int pos);
5761
void Remove(Node* node);
5862
void Remove(unsigned int pos);
5963
unsigned int GetNodeIndex(Node* node) const;
60-
template <typename T>
61-
T* at(unsigned int index)
62-
{
63-
return (T*)(_array.at(index));
64+
template <typename T> T *at(unsigned int index) {
65+
return (T *)(_array.at(index));
6466
}
65-
template <typename T>
66-
T* At(unsigned int index)
67-
{
68-
return (T*)(_array.at(index));
67+
template <typename T> T *At(unsigned int index) {
68+
return (T *)(_array.at(index));
6969
}
7070

7171
private :

include/plist/Data.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public :
3636
Data(const Data& d);
3737
Data& operator=(const Data& b);
3838
Data(const std::vector<char>& buff);
39+
Data(const char *bin, uint64_t size);
3940
virtual ~Data();
4041

4142
Node* Clone() const;

include/plist/Dictionary.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,13 @@ public :
5555
const_iterator end() const;
5656
size_t size() const;
5757
const_iterator Find(const std::string& key) const;
58-
iterator Set(const std::string& key, const Node* node);
5958
iterator Set(const std::string& key, const Node& node);
59+
iterator Set(const std::string& key, const Node* node);
6060
void Remove(Node* node);
6161
void Remove(const std::string& key);
6262
std::string GetNodeKey(Node* node);
63-
template <typename T>
64-
T* Get(const std::string& key)
65-
{
66-
return (T*)(_map[key]);
63+
template <typename T> T *Get(const std::string &key) {
64+
return (T *)(_map[key]);
6765
}
6866

6967
private :

include/plist/Integer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public :
3636
Integer& operator=(const Integer& i);
3737
Integer(uint64_t i);
3838
Integer(int64_t i);
39+
Integer(unsigned long i);
40+
Integer(long i);
3941
virtual ~Integer();
4042

4143
Node* Clone() const;

include/plist/String.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ public :
3434
String(Node* parent = NULL);
3535
String(plist_t node, Node* parent = NULL);
3636
String(const String& s);
37+
String(const char *s);
3738
String& operator=(const String& s);
38-
String& operator=(const char* s);
39+
String &operator=(const char *s);
3940
String(const std::string& s);
4041
virtual ~String();
4142

include/plist/Structure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public :
4343

4444
static Structure* FromXml(const std::string& xml);
4545
static Structure* FromBin(const std::vector<char>& bin);
46-
static Structure* FromBin(const char* bin, uint64_t size);
46+
static Structure *FromBuffer(const char *bin, uint64_t size);
4747

4848
protected:
4949
Structure(Node* parent = NULL);

src/Array.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ static void array_fill(Array *_this, std::vector<Node*> &array, plist_t node)
4040
do {
4141
subnode = NULL;
4242
plist_array_next_item(node, iter, &subnode);
43-
array.push_back( Node::FromPlist(subnode, _this) );
43+
if (subnode != NULL) {
44+
array.push_back( Node::FromPlist(subnode, _this) );
45+
}
4446
} while (subnode);
4547
free(iter);
4648
}
@@ -88,6 +90,16 @@ Node* Array::operator[](unsigned int array_index)
8890
return _array.at(array_index);
8991
}
9092

93+
Node *Array::back()
94+
{
95+
return _array.back();
96+
}
97+
98+
Node *Array::Back()
99+
{
100+
return _array.back();
101+
}
102+
91103
Array::iterator Array::Begin()
92104
{
93105
return _array.begin();
@@ -132,7 +144,7 @@ size_t Array::size() const {
132144
return _array.size();
133145
}
134146

135-
void Array::Append(Node* node)
147+
void Array::Append(const Node* node)
136148
{
137149
if (node)
138150
{
@@ -143,7 +155,15 @@ void Array::Append(Node* node)
143155
}
144156
}
145157

146-
void Array::Insert(Node* node, unsigned int pos)
158+
void Array::Append(const Node &node)
159+
{
160+
Node *clone = node.Clone();
161+
UpdateNodeParent(clone);
162+
plist_array_append_item(_node, clone->GetPlist());
163+
_array.push_back(clone);
164+
}
165+
166+
void Array::Insert(const Node* node, unsigned int pos)
147167
{
148168
if (node)
149169
{
@@ -156,6 +176,10 @@ void Array::Insert(Node* node, unsigned int pos)
156176
}
157177
}
158178

179+
void Array::Insert(const Node &node, unsigned int pos)
180+
{
181+
Insert(&node, pos);
182+
}
159183
void Array::Remove(Node* node)
160184
{
161185
if (node)

src/Data.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ Data::Data(const std::vector<char>& buff) : Node(PLIST_DATA)
5050
plist_set_data_val(_node, &buff[0], buff.size());
5151
}
5252

53+
Data::Data(const char *bin, uint64_t size) : Node(PLIST_DATA)
54+
{
55+
plist_set_data_val(_node, bin, size);
56+
}
57+
5358
Data::~Data()
5459
{
5560
}

src/Integer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ Integer::Integer(int64_t i) : Node(PLIST_INT)
5555
plist_set_int_val(_node, i);
5656
}
5757

58+
Integer::Integer(unsigned long i) : Node(PLIST_INT)
59+
{
60+
plist_set_uint_val(_node, i);
61+
}
62+
63+
Integer::Integer(long i) : Node(PLIST_INT)
64+
{
65+
plist_set_int_val(_node, i);
66+
}
67+
5868
Integer::~Integer()
5969
{
6070
}

src/String.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ String& String::operator=(const PList::String& s)
4545
return *this;
4646
}
4747

48-
String& String::operator=(const char* s)
48+
String &String::operator=(const char *s)
4949
{
5050
plist_free(_node);
5151
_node = plist_new_string(s);
@@ -57,6 +57,11 @@ String::String(const std::string& s) : Node(PLIST_STRING)
5757
plist_set_string_val(_node, s.c_str());
5858
}
5959

60+
String::String(const char *s) : Node(PLIST_STRING)
61+
{
62+
plist_set_string_val(_node, s);
63+
}
64+
6065
String::~String()
6166
{
6267
}

0 commit comments

Comments
 (0)