Skip to content

Commit

Permalink
TypeDesc: add utility function basevalues()
Browse files Browse the repository at this point in the history
  • Loading branch information
lgritz committed May 15, 2017
1 parent f29092e commit fc09dee
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/include/OpenImageIO/typedesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,20 @@ struct OIIO_API TypeDesc {
}

/// Return the number of elements: 1 if not an array, or the array
/// length.
/// length. Invalid to call this for arrays of undetermined size.
OIIO_CONSTEXPR14 size_t numelements () const {
DASSERT_MSG (arraylen >= 0, "Called numelements() on TypeDesc "
"of array with unspecified length (%d)", arraylen);
return (arraylen >= 1 ? arraylen : 1);
}

/// Return the number of basetype values: the aggregate count multiplied
/// by the array length (or 1 if not an array). Invalid to call this
/// for arrays of undetermined size.
OIIO_CONSTEXPR14 size_t basevalues () const {
return numelements() * aggregate;
}

/// Does this TypeDesc describe an array?
constexpr bool is_array () const { return (arraylen != 0); }

Expand Down
1 change: 1 addition & 0 deletions src/python/py_typedesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void declare_typedesc() {
// .def(init<TypeDesc::BASETYPE, TypeDesc::AGGREGATE, int>())
.def("c_str", &TypeDesc::c_str)
.def("numelements", &TypeDesc::numelements)
.def("basevalues", &TypeDesc::basevalues)
.def("size", &TypeDesc::size)
.def("elementtype", &TypeDesc::elementtype)
.def("elementsize", &TypeDesc::elementsize)
Expand Down
8 changes: 8 additions & 0 deletions testsuite/python-typedesc/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type '(default)'
size = 0
elementtype = unknown
numelements = 1
basevalues = 1
elementsize = 0
basesize = 0
type 'UINT8'
Expand All @@ -24,6 +25,7 @@ type 'UINT8'
size = 1
elementtype = uint8
numelements = 1
basevalues = 1
elementsize = 1
basesize = 1
type 'HALF, VEC3, COLOR'
Expand All @@ -36,6 +38,7 @@ type 'HALF, VEC3, COLOR'
size = 6
elementtype = colorh
numelements = 1
basevalues = 3
elementsize = 6
basesize = 2
type 'FLOAT, SCALAR, NOXFORM, array of 6'
Expand All @@ -48,6 +51,7 @@ type 'FLOAT, SCALAR, NOXFORM, array of 6'
size = 24
elementtype = float
numelements = 6
basevalues = 6
elementsize = 4
basesize = 4
type 'FLOAT, VEC3, POINT, array of 2'
Expand All @@ -60,6 +64,7 @@ type 'FLOAT, VEC3, POINT, array of 2'
size = 24
elementtype = point
numelements = 2
basevalues = 6
elementsize = 12
basesize = 4

Expand All @@ -73,6 +78,7 @@ type 'float[2]'
size = 8
elementtype = float
numelements = 2
basevalues = 2
elementsize = 4
basesize = 4
type 'normal'
Expand All @@ -85,6 +91,7 @@ type 'normal'
size = 12
elementtype = normal
numelements = 1
basevalues = 3
elementsize = 12
basesize = 4
type 'uint16'
Expand All @@ -97,6 +104,7 @@ type 'uint16'
size = 2
elementtype = uint16
numelements = 1
basevalues = 1
elementsize = 2
basesize = 2

Expand Down
1 change: 1 addition & 0 deletions testsuite/python-typedesc/src/test_typedesc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def breakdown_test(t, name="", verbose=True):
print " size =", t.size()
print " elementtype =", t.elementtype()
print " numelements =", t.numelements()
print " basevalues =", t.basevalues()
print " elementsize =", t.elementsize()
print " basesize =", t.basesize()

Expand Down

0 comments on commit fc09dee

Please sign in to comment.