-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInteger.cpp
39 lines (30 loc) · 882 Bytes
/
Integer.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
#include "Integer.h"
#include "Exception.h"
#include "Indent.h"
Bencoding::Type Bencoding::Integer::getType()
{
return INTEGER;
}
boost::shared_ptr<Bencoding::Element> Bencoding::Integer::factory(const char* const buffer, unsigned& offset)
{
return boost::shared_ptr<Bencoding::Element>(new Bencoding::Integer(buffer, offset));
}
Bencoding::Integer::Integer(const char* const buffer, unsigned& offset)
{
if (buffer[offset] != 'i')
{
throw Exception("Expected 'i' in integer", offset);
}
offset++;
value = intValue(buffer, offset);
if (buffer[offset] != 'e')
{
throw Exception("Expected 'e' in integer", offset);
}
offset++;
}
std::ostream& operator<< (std::ostream& aStream, boost::shared_ptr<Bencoding::Integer> integer)
{
aStream << Bencoding::Indent::indent() << integer->getValue();
return aStream;
}