2012-08-15 00:04:19 -07:00
|
|
|
//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-08-15 00:10:56 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-08-15 00:04:19 -07:00
|
|
|
|
|
|
|
#ifndef ChunkSet_h__
|
|
|
|
#define ChunkSet_h__
|
|
|
|
|
|
|
|
|
|
|
|
#include "Entries.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace safebrowsing {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store the chunks as an array of uint32.
|
|
|
|
* XXX: We should optimize this further to compress the
|
|
|
|
* many consecutive numbers.
|
|
|
|
*/
|
|
|
|
class ChunkSet {
|
|
|
|
public:
|
|
|
|
ChunkSet() {}
|
|
|
|
~ChunkSet() {}
|
|
|
|
|
|
|
|
nsresult Serialize(nsACString& aStr);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult Set(uint32_t aChunk);
|
|
|
|
nsresult Unset(uint32_t aChunk);
|
2012-08-15 00:04:19 -07:00
|
|
|
void Clear();
|
|
|
|
nsresult Merge(const ChunkSet& aOther);
|
|
|
|
nsresult Remove(const ChunkSet& aOther);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool Has(uint32_t chunk) const;
|
2012-08-15 00:04:19 -07:00
|
|
|
|
|
|
|
uint32 Length() const { return mChunks.Length(); }
|
|
|
|
|
|
|
|
nsresult Write(nsIOutputStream* aOut) {
|
|
|
|
return WriteTArray(aOut, mChunks);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult Read(nsIInputStream* aIn, uint32_t aNumElements) {
|
2012-08-15 00:04:19 -07:00
|
|
|
return ReadTArray(aIn, &mChunks, aNumElements);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 *Begin() { return mChunks.Elements(); }
|
|
|
|
uint32 *End() { return mChunks.Elements() + mChunks.Length(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsTArray<uint32> mChunks;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|