Rudiments
listcollectioninlines.h
1// Copyright (c) 1999-2018 David Muse
2// See the COPYING file for more information
3
4template <class valuetype>
5inline
8
9template <class valuetype>
10inline
14
15template <class valuetype>
16inline
18 return "list";
19}
20
21template <class valuetype>
22inline
23void listcollection<valuetype>::prepend(valuetype *values, uint64_t count) {
24 for (uint64_t i=count; i>0; i--) {
25 prepend(values[i-1]);
26 }
27}
28
29template <class valuetype>
30inline
31void listcollection<valuetype>::append(valuetype *values, uint64_t count) {
32 for (uint64_t i=0; i<count; i++) {
33 append(values[i]);
34 }
35}
36
37template <class valuetype>
38inline
40 valuetype *values, uint64_t count) {
41 for (uint64_t i=0; i<count; i++) {
42 insertBefore(node,values[i]);
43 }
44}
45
46template <class valuetype>
47inline
49 valuetype *values, uint64_t count) {
50 for (uint64_t i=count; i>0; i--) {
51 insertAfter(node,values[i-1]);
52 }
53}
54
55template <class valuetype>
56inline
58 return write(&stdoutput);
59}
60
61template <class valuetype>
62inline
64 return writeJson(out,true);
65}
66
67template< class valuetype >
68inline
70 return writeJson(&stdoutput,true);
71}
72
73template< class valuetype >
74inline
76 return writeJson(&stdoutput,indent);
77}
78
79template< class valuetype >
80inline
82 return writeJson(out,true);
83}
84
85template< class valuetype >
86inline
87ssize_t listcollection<valuetype>::writeJson(output *out, bool indent) {
88 ssize_t retval=0;
89 uint64_t i=0;
90 listnode<valuetype> *node=getFirst();
91 this->incOrErr(&retval,out->write('['),1);
92 while (node && retval>-1) {
93 ((i)?this->incOrErr(&retval,out->write(','),1):true) &&
94 ((indent)?this->incOrErr(&retval,out->write("\n ",2),2):true) &&
95 this->incOrErr(&retval,
96 this->writeJsonValue(out,node->getValue()));
97 node=node->getNext();
98 i++;
99 }
100 ((indent)?this->incOrErr(&retval,out->write('\n'),1):true) &&
101 this->incOrErr(&retval,out->write(']'),1) &&
102 ((indent)?this->incOrErr(&retval,out->write('\n'),1):true);
103 return retval;
104}
Definition avltree.h:11
avltreenode(valuetype value)
Definition avltreeinlines.h:555
treenode< valuetype > * getNext()
Definition avltreeinlines.h:671
valuetype getValue()
Definition avltreeinlines.h:578
virtual void prepend(valuetype value)=0
virtual ssize_t write()
Definition listcollectioninlines.h:57
virtual void insertBefore(listnode< valuetype > *node, valuetype value)=0
virtual ssize_t writeJson()
Definition listcollectioninlines.h:69
virtual void insertAfter(listnode< valuetype > *node, valuetype value)=0
virtual void append(valuetype value)=0
listcollection()
Definition listcollectioninlines.h:6
virtual const char * getType()
Definition listcollectioninlines.h:17
Definition nodecollection.h:31
Definition output.h:11
virtual ssize_t write(const byte_t *string, size_t size)=0