Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vectordatacontainer.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_VECTORDATACONTAINER_H_
19 #define ION_BASE_VECTORDATACONTAINER_H_
20 
21 #include "base/macros.h"
22 #include "ion/base/datacontainer.h"
24 #include "ion/port/nullptr.h" // For kNullFunction.
25 
26 namespace ion {
27 namespace base {
28 
34 template <typename T>
35 class ION_API VectorDataContainer : public DataContainer {
36  public:
37  explicit VectorDataContainer(bool is_wipeable)
38  : DataContainer(kNullFunction, is_wipeable), vector_(*this) {}
39 
41  const AllocVector<T>& GetVector() const { return vector_; }
42 
44  AllocVector<T>* GetMutableVector() { return &vector_; }
45 
46  protected:
49  ~VectorDataContainer() override {}
50 
51  private:
57  void InternalWipeData() override { vector_ = AllocVector<T>(GetAllocator()); }
58 
61  void* GetDataPtr() const override {
62  return vector_.empty() ? NULL : &vector_[0];
63  }
64 
66  mutable AllocVector<T> vector_;
67 
68  DISALLOW_IMPLICIT_CONSTRUCTORS(VectorDataContainer);
69 };
70 
71 } // namespace base
72 } // namespace ion
73 
74 #endif // ION_BASE_VECTORDATACONTAINER_H_
AllocVector< T > * GetMutableVector()
Returns a pointer to the vector backing this instance.
const AllocVector< T > & GetVector() const
Returns a const reference to the vector backing this instance.
VectorDataContainer is a special kind of DataContainer that is backed by an AllocVector.
~VectorDataContainer() override
The destructor is protected because all base::Referent classes must have protected or private destruc...
The DataContainer class encapsulates arbitrary user data passed to Ion.
Definition: datacontainer.h:74
#define kNullFunction
Copyright 2016 Google Inc.
Definition: nullptr.h:38
This class can be used in place of std::vector to allow an Ion Allocator to be used for memory alloca...
Definition: allocvector.h:50