summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/record_data.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/storage/record_data.h')
-rw-r--r--src/mongo/db/storage/record_data.h113
1 files changed, 62 insertions, 51 deletions
diff --git a/src/mongo/db/storage/record_data.h b/src/mongo/db/storage/record_data.h
index 612408f84c6..03409d911ea 100644
--- a/src/mongo/db/storage/record_data.h
+++ b/src/mongo/db/storage/record_data.h
@@ -35,58 +35,69 @@
namespace mongo {
- // TODO: Does this need to have move support?
- /**
- * A replacement for the Record class. This class represents data in a record store.
- * The _dataPtr attribute is used to manage memory ownership. If _dataPtr is NULL, then
- * the memory pointed to by _data is owned by the RecordStore. If _dataPtr is not NULL, then
- * it must point to the same array as _data.
- */
- class RecordData {
- public:
- RecordData() : _data( NULL ), _size( 0 ) {}
- RecordData(const char* data, int size): _data(data), _size(size) { }
-
- RecordData(SharedBuffer ownedData, int size)
- : _data(ownedData.get()), _size(size), _ownedData(std::move(ownedData)) {
- }
-
- const char* data() const { return _data; }
-
- int size() const { return _size; }
-
- /**
- * Returns true if this owns its own memory, and false otherwise
- */
- bool isOwned() const { return _ownedData.get(); }
-
- SharedBuffer releaseBuffer() {
- return std::move(_ownedData);
- }
-
- BSONObj toBson() const { return isOwned() ? BSONObj(_ownedData) : BSONObj(_data); }
-
- BSONObj releaseToBson() { return isOwned() ? BSONObj(releaseBuffer()) : BSONObj(_data); }
-
- // TODO uncomment once we require compilers that support overloading for rvalue this.
- // BSONObj toBson() && { return releaseToBson(); }
+// TODO: Does this need to have move support?
+/**
+ * A replacement for the Record class. This class represents data in a record store.
+ * The _dataPtr attribute is used to manage memory ownership. If _dataPtr is NULL, then
+ * the memory pointed to by _data is owned by the RecordStore. If _dataPtr is not NULL, then
+ * it must point to the same array as _data.
+ */
+class RecordData {
+public:
+ RecordData() : _data(NULL), _size(0) {}
+ RecordData(const char* data, int size) : _data(data), _size(size) {}
- RecordData getOwned() const {
- if (isOwned()) return *this;
- auto buffer = SharedBuffer::allocate(_size);
- memcpy(buffer.get(), _data, _size);
- return RecordData(buffer, _size);
- }
+ RecordData(SharedBuffer ownedData, int size)
+ : _data(ownedData.get()), _size(size), _ownedData(std::move(ownedData)) {}
- void makeOwned() {
- if (isOwned()) return;
- *this = getOwned();
- }
+ const char* data() const {
+ return _data;
+ }
- private:
- const char* _data;
- int _size;
- SharedBuffer _ownedData;
- };
+ int size() const {
+ return _size;
+ }
-} // namespace mongo
+ /**
+ * Returns true if this owns its own memory, and false otherwise
+ */
+ bool isOwned() const {
+ return _ownedData.get();
+ }
+
+ SharedBuffer releaseBuffer() {
+ return std::move(_ownedData);
+ }
+
+ BSONObj toBson() const {
+ return isOwned() ? BSONObj(_ownedData) : BSONObj(_data);
+ }
+
+ BSONObj releaseToBson() {
+ return isOwned() ? BSONObj(releaseBuffer()) : BSONObj(_data);
+ }
+
+ // TODO uncomment once we require compilers that support overloading for rvalue this.
+ // BSONObj toBson() && { return releaseToBson(); }
+
+ RecordData getOwned() const {
+ if (isOwned())
+ return *this;
+ auto buffer = SharedBuffer::allocate(_size);
+ memcpy(buffer.get(), _data, _size);
+ return RecordData(buffer, _size);
+ }
+
+ void makeOwned() {
+ if (isOwned())
+ return;
+ *this = getOwned();
+ }
+
+private:
+ const char* _data;
+ int _size;
+ SharedBuffer _ownedData;
+};
+
+} // namespace mongo