HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PyImathStringArray.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
4 //
5 
6 // clang-format off
7 
8 #ifndef _PyImathStringArray_h_
9 #define _PyImathStringArray_h_
10 
11 #include "PyImathFixedArray.h"
12 #include "PyImathStringTable.h"
13 
14 //
15 // A fixed lengy array class for string and wide string type in python.
16 // The implementation of StringArray is does not follow other FixeArray
17 // types. StringArray de-duplicate repeated strings using StringTable
18 // internally for compact memory usage.
19 //
20 namespace PyImath {
21 
22 template <class T>
23 class StringArrayT : public FixedArray<StringTableIndex>
24 {
25  public:
26  typedef T BaseType;
28 
30  static StringArrayT<T>* createUniformArray(const T& initialValue, size_t length);
31  static StringArrayT<T>* createFromRawArray(const T* rawArray, size_t length,
32  bool writable = true);
33 
35  size_t stride = 1, hboost::any tableHandle = hboost::any(),
36  bool writable = true);
37 
38  StringArrayT(StringTableT<T> &table, StringTableIndex *ptr, size_t length,
39  size_t stride, hboost::any handle, hboost::any tableHandle = hboost::any(),
40  bool writable = true);
41 
42  StringArrayT(const StringTableT<T> &table, const StringTableIndex *ptr, size_t length,
43  size_t stride = 1, hboost::any tableHandle = hboost::any());
44 
45  StringArrayT(const StringTableT<T> &table, const StringTableIndex *ptr, size_t length,
46  size_t stride, hboost::any handle, hboost::any tableHandle = hboost::any());
47 
49 
50  const StringTableT<T> & stringTable() const { return _table; }
51 
52  T getitem_string(Py_ssize_t index) const {return _table.lookup(getitem(index)); }
53  StringArrayT* getslice_string(PyObject *index) const;
55 
56  void setitem_string_scalar(PyObject *index, const T &data);
57 
58  void setitem_string_scalar_mask(const FixedArray<int> &mask, const T &data);
59  void setitem_string_vector(PyObject *index, const StringArrayT<T> &data);
61 
62  private:
63  typedef StringArrayT<T> this_type;
64 
65  StringTableT<T> &_table;
66  // StringArray can borrow a string table from somewhere else or maintain
67  // its own string table. This handle optionally stores a shared pointer to
68  // a allocated StringTable class instance
69  hboost::any _tableHandle;
70 };
71 
72 template<class T>
73 FixedArray<int> operator == (const StringArrayT<T> &a0, const StringArrayT<T> &a1);
74 template<class T>
75 FixedArray<int> operator == (const StringArrayT<T> &a0, const T &v1);
76 template<class T>
77 FixedArray<int> operator == (const T &v1,const StringArrayT<T> &a0);
78 template<class T>
79 FixedArray<int> operator != (const StringArrayT<T> &a0, const StringArrayT<T> &a1);
80 template<class T>
81 FixedArray<int> operator != (const StringArrayT<T> &a0, const T &v1);
82 template<class T>
83 FixedArray<int> operator != (const T &v1,const StringArrayT<T> &a0);
84 
87 
88 } // namespace PyImath
89 
90 #endif
const StringTableT< T > & stringTable() const
void setitem_string_vector_mask(const FixedArray< int > &mask, const StringArrayT< T > &data)
void setitem_string_scalar(PyObject *index, const T &data)
GLdouble s
Definition: glad.h:3009
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
FixedArray< int > operator!=(const StringArrayT< T > &a0, const StringArrayT< T > &a1)
bool any(const vbool4 &v)
Definition: simd.h:3600
FixedArray< StringTableIndex > super
void setitem_string_vector(PyObject *index, const StringArrayT< T > &data)
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
GLint GLuint mask
Definition: glcorearb.h:124
T getitem_string(Py_ssize_t index) const
GLenum GLenum GLsizei void * table
Definition: glad.h:5129
static StringArrayT< T > * createDefaultArray(size_t length)
StringArrayT< std::string > StringArray
StringArrayT * getslice_mask_string(const FixedArray< int > &mask)
StringArrayT(StringTableT< T > &table, StringTableIndex *ptr, size_t length, size_t stride=1, hboost::any tableHandle=hboost::any(), bool writable=true)
FixedArray< int > operator==(const StringArrayT< T > &a0, const StringArrayT< T > &a1)
GLuint index
Definition: glcorearb.h:786
static StringArrayT< T > * createUniformArray(const T &initialValue, size_t length)
GLfloat GLfloat v1
Definition: glcorearb.h:817
auto ptr(T p) -> const void *
Definition: format.h:4331
StringArrayT * getslice_string(PyObject *index) const
static StringArrayT< T > * createFromRawArray(const T *rawArray, size_t length, bool writable=true)
Definition: format.h:1821
StringArrayT< std::wstring > WstringArray
void setitem_string_scalar_mask(const FixedArray< int > &mask, const T &data)