Skip to content

Modify list writer to use the smallest counter type that will fit.#59

Open
gilgamec wants to merge 1 commit into
nmwsharp:masterfrom
gilgamec:master
Open

Modify list writer to use the smallest counter type that will fit.#59
gilgamec wants to merge 1 commit into
nmwsharp:masterfrom
gilgamec:master

Conversation

@gilgamec
Copy link
Copy Markdown

@gilgamec gilgamec commented May 7, 2026

Let's try this again (as somehow #57 was closed during my mucking about). Fixes #56.

The modification adds a size-type template parameter to TypedListProperty. It only allows appropriate unsigned integral sizes (anything else throws from the constructor). (Since the code was already implicitly changing signed integers to unsigned, I figure this cements that.) The most significant changes outside TypedListProperty itself are to accessors in Element (e.g. getListPropertyType, getDataFromListPropertyRecursive) to triple the number of dynamic_casts we have to do in order to find the correct type for TypedListProperty.

The existing Element method addListProperty is joined by addSizedListProperty, which counts the sizes of the input vectors to find the longest, then creates a TypedListProperty with a size-type which is the smallest that can store the count. In this way, lists of fewer than 256 elements are still saved with a uchar, but longer lists can still be saved.

I also added some tests, though I tested only int and float list elements rather than the entire panoply of list type options.

- Only unsigned integral types allowed by PLY (uint8/16/32_t)
  are allowed; all other instantiations cause an exception
  in the constructor. Signed types used in a PLY file are
  interpreted as their unsigned equivalents.
- Added addSizedListProperty method to Element to choose which
  instantiation to use based on the number of elements
  in the provided lists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow list counters of more than 8 bits

1 participant