mirror hosted by tehsausage.com
PTypes: lists

C++ Portable Types Library (PTypes) Version 2.1


Top: Basic types: Lists


PTypes offers a set of list templates/classes that were designed to eliminate the template 'code bloat' problem and also to allow reallocating of dynamic arrays in the most efficient way.

Why not STL containers? Or, why there is no universal container for arbitrary types, like std::vector, in PTypes? There are 3 main reasons for this:


Overview of PTypes list templates. As a replacement of a universal vector-like container PTypes offers two separate templates: tpodlist and tobjlist. Each of them have certain limitations in return for the following advantages: dynamic arrays are reallocated in the most efficient way, templates produce no or very little code during instantiation.

The tpodlist template is intended for use with small POD (plain-old-data) objects. For bigger structures or for arbitrary non-POD types in general the library offers a list of pointers, tobjlist, that has the ability to automatically destroy objects when they are removed from the list. Tobjlist never reallocates items themselves, instead, it only deals with pointers.

As a universal way of holding string/object pairs in an indexed list the library offers the tstrlist template. When constructed as a sorted list, this template can also serve as a map indexed by textual keys. And finally, the textmap class provides a simple interface for mapping strings to strings, i.e. textual keys to values.

Historically, PTypes was using list classes that required the list item to be derived from unknown. These list classes (objlist, strlist and strmap) are still present in the library for backward compatibility. There is no such limitation in the newer versions of the library, however, deriving your classes from unknown can still give you an advantage of automatically detecting memory leaks in your program.

Bounds checking. All list operations that involve indexes can be checked for validity at run-time. If an index value is invalid, the library generates an unrecoverable (fatal) error. Bounds checking is done when compiling your code in debug mode (i.e. if macro DEBUG is defined). You may also enable it explicitly for your release builds by defining CHECK_BOUNDS. Note that the bounds checking code is fully inlined and the library itself is not affected by these macros.

The list class family is declared in <ptypes.h>.

See also: unknown


PTypes home