19 typedef Eegeo::unordered_set<std::string>::type TContainer;
24 const unsigned int Sentinel;
33 TContainer::const_iterator First()
const {
return m_members.begin(); }
34 TContainer::const_iterator End()
const {
return m_members.end(); }
36 bool Contains(
const std::string& item) {
37 return m_members.find(item) != m_members.end();
40 void Add(
const std::string& item) {
41 m_members.insert(item);
44 void Remove(
const std::string& item) {
45 TContainer::iterator it = m_members.find(item);
46 Eegeo_ASSERT(it != m_members.end());
50 void FromFile(
const std::string& file)
58 if(m_fileIO.OpenFile(stream, size, file))
60 int sentinelContainer = 0;
61 stream.read((
char*)&sentinelContainer,
sizeof(
unsigned int));
63 if(sentinelContainer != Sentinel)
71 unsigned char labelSize = 0;
72 for(
size_t index =
sizeof(
unsigned int); index < size -
sizeof(
unsigned int);)
75 stream.read((
char*)&labelSize,
sizeof(
unsigned char));
78 std::vector<char> readBuffer(labelSize);
79 stream.read((
char*)&readBuffer[0],
sizeof(
char)*labelSize);
83 member.assign(&readBuffer[0], labelSize);
85 m_members.insert(member);
87 index += (
sizeof(char) + (
sizeof(
char) * labelSize));
90 sentinelContainer = 0;
91 stream.read((
char*)&sentinelContainer,
sizeof(
unsigned int));
93 if(sentinelContainer != Sentinel)
105 void ToFile(std::string file)
112 for(TContainer::const_iterator member = m_members.begin(); member != m_members.end(); ++ member)
114 Eegeo_ASSERT(member->size() <= std::numeric_limits<unsigned char>::max());
115 size +=
sizeof(char);
116 size +=
sizeof(char) * member->size();
122 std::vector<Byte> buffer;
126 *(
unsigned int*)(&buffer[writeHead]) = Sentinel;
129 for(TContainer::const_iterator member = m_members.begin(); member != m_members.end(); ++ member)
131 unsigned char stringLength = (
unsigned char)member->size();
133 buffer[writeHead] = stringLength;
134 writeHead +=
sizeof(
unsigned char);
136 memcpy(&buffer[writeHead], member->c_str(), stringLength);
137 writeHead +=
sizeof(char) * stringLength;
140 *(
unsigned int*)(&buffer[writeHead]) = Sentinel;
143 Eegeo_ASSERT(writeHead == size);
145 if(!m_fileIO.WriteFile(&buffer[0], size, file))
147 Eegeo_ASSERT(
false,
"CACHE MANIFEST UPDATE FAILED");