-
Notifications
You must be signed in to change notification settings - Fork 1
/
List.cpp
49 lines (40 loc) · 1.2 KB
/
List.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <sstream>
#include <iostream>
#include "List.h"
#include "Exception.h"
#include "Indent.h"
Bencoding::Type Bencoding::List::getType()
{
return LIST;
}
boost::shared_ptr<Bencoding::Element> Bencoding::List::factory(const char* const buffer, unsigned& offset)
{
return boost::shared_ptr<Bencoding::Element>(new Bencoding::List(buffer, offset));
}
Bencoding::List::List(const char* const buffer, unsigned& offset)
{
if (buffer[offset] != 'l')
{
throw Exception("Expected 'l' in list", offset);
}
offset++;
while (buffer[offset] != 'e')
{
boost::shared_ptr<Bencoding::Element> e = Bencoding::Element::factory(buffer, offset);
list.push_back(e);
}
offset++;
}
std::ostream& operator<< (std::ostream& aStream, boost::shared_ptr<Bencoding::List> list)
{
aStream << Bencoding::Indent::indent() << "List:" << std::endl;
Bencoding::Indent::increase();
std::list<boost::shared_ptr<Bencoding::Element> > l = list->getList();
std::list<boost::shared_ptr<Bencoding::Element> >::iterator iter;
for (iter = l.begin(); iter != l.end(); iter++)
{
aStream << *iter;
}
Bencoding::Indent::decrease();
return aStream;
}