-
Notifications
You must be signed in to change notification settings - Fork 1
/
hogiterator.cpp
72 lines (59 loc) · 1.91 KB
/
hogiterator.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//===----------------------------------------------------------------------===//
//
// The Descent map loader
//
// NAME : HogIterator
// PURPOSE : Providing an iterator over items in the Descent .HOG format.
// COPYRIGHT : (c) 2011 Sean Donnellan. All Rights Reserved.
// AUTHORS : Sean Donnellan ([email protected])
// DESCRIPTION : Provides a forward iterator over the files in the HOG file
// format that is used by Parallax Software in the computer game
// Descent.
//
//===----------------------------------------------------------------------===//
#include "hogiterator.hpp"
#include "hogreader.hpp"
#include <assert.h>
#include <string.h>
#include <stdio.h>
HogReaderIterator::HogReaderIterator(HogReader& Reader)
: myReader(&Reader), myProgress(Reader.IsValid())
{
strncpy(myData.name, myReader->CurrentFileName(), 13);
myData.size = myReader->CurrentFileSize();
}
HogReaderIterator& HogReaderIterator::operator++()
{
// You can't increment the null so error.
myProgress = myReader->NextFile();
strncpy(myData.name, myReader->CurrentFileName(), 13);
myData.size = myReader->CurrentFileSize();
return *this;
}
const HogReaderIterator::value_type& HogReaderIterator::operator*() const
{
return myData;
}
const HogReaderIterator::value_type* HogReaderIterator::operator->() const
{
return &myData;
}
bool HogReaderIterator::operator==(const HogReaderIterator& o) const
{
if (myReader == nullptr || o.myReader == nullptr)
{
return myProgress == o.myProgress;
}
// You can't compare iterators from two HOG readers..
assert(myReader == o.myReader);
return (strcmp(myData.name, o.myData.name) == 0 &&
myData.size == o.myData.size);
}
bool HogReaderIterator::operator!=(const HogReaderIterator& o) const
{
return !(*this == o);
}
std::vector<uint8_t> HogReaderIterator::FileContents()
{
return myReader->CurrentFile();
}