Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkDataTable.h
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkDataTable_DEFINED
9 #define SkDataTable_DEFINED
10 
11 #include "../private/SkTDArray.h"
12 #include "SkData.h"
13 #include "SkString.h"
14 
20 class SK_API SkDataTable : public SkRefCnt {
21 public:
25  bool isEmpty() const { return 0 == fCount; }
26 
30  int count() const { return fCount; }
31 
36  size_t atSize(int index) const;
37 
45  const void* at(int index, size_t* size = NULL) const;
46 
47  template <typename T>
48  const T* atT(int index, size_t* size = NULL) const {
49  return reinterpret_cast<const T*>(this->at(index, size));
50  }
51 
56  const char* atStr(int index) const {
57  size_t size;
58  const char* str = this->atT<const char>(index, &size);
59  SkASSERT(strlen(str) + 1 == size);
60  return str;
61  }
62 
63  typedef void (*FreeProc)(void* context);
64 
65  static sk_sp<SkDataTable> MakeEmpty();
66 
76  static sk_sp<SkDataTable> MakeCopyArrays(const void * const * ptrs,
77  const size_t sizes[], int count);
78 
87  static sk_sp<SkDataTable> MakeCopyArray(const void* array, size_t elemSize, int count);
88 
89  static sk_sp<SkDataTable> MakeArrayProc(const void* array, size_t elemSize, int count,
90  FreeProc proc, void* context);
91 
92 private:
93  struct Dir {
94  const void* fPtr;
95  uintptr_t fSize;
96  };
97 
98  int fCount;
99  size_t fElemSize;
100  union {
101  const Dir* fDir;
102  const char* fElems;
103  } fU;
104 
105  FreeProc fFreeProc;
106  void* fFreeProcContext;
107 
108  SkDataTable();
109  SkDataTable(const void* array, size_t elemSize, int count,
110  FreeProc, void* context);
111  SkDataTable(const Dir*, int count, FreeProc, void* context);
112  virtual ~SkDataTable();
113 
114  friend class SkDataTableBuilder; // access to Dir
115 
116  typedef SkRefCnt INHERITED;
117 };
118 
119 #endif
const char * atStr(int index) const
Returns the index'th entry as a c-string, and assumes that the trailing null byte had been copied int...
Definition: SkDataTable.h:56
Like SkData, SkDataTable holds an immutable data buffer.
Definition: SkDataTable.h:20
Definition: SkRefCnt.h:125
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:246
int count() const
Return the number of entries in the table.
Definition: SkDataTable.h:30
bool isEmpty() const
Returns true if the table is empty (i.e.
Definition: SkDataTable.h:25
Definition: SkDataTable.h:93