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 {
|
|
|
|
|
|
|
|
/**
|
2012-10-11 16:38:04 -07:00
|
|
|
* Store the chunks as an array of uint32_t.
|
2012-08-15 00:04:19 -07:00
|
|
|
* 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
|
|
|
|
2012-10-11 16:38:04 -07:00
|
|
|
uint32_t Length() const { return mChunks.Length(); }
|
2012-08-15 00:04:19 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-10-11 16:38:04 -07:00
|
|
|
uint32_t *Begin() { return mChunks.Elements(); }
|
|
|
|
uint32_t *End() { return mChunks.Elements() + mChunks.Length(); }
|
2012-08-15 00:04:19 -07:00
|
|
|
|
|
|
|
private:
|
2012-10-11 16:38:04 -07:00
|
|
|
nsTArray<uint32_t> mChunks;
|
2012-08-15 00:04:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|