Google

C++ Portable Types Library (PTypes) Version 1.7


Top: Basic types: Lists

  • objlist - dynamic list of unknown objects
  • strlist - dynamic list of string/object pairs
  • strmap - associative array of unknown objects

PTypes provides three different types of dynamic arrays: list of objects (objlist), list of string/object pairs, optionally sorted (strlist), and associative array of objects mapped through strings (strmap). Unlike STL, PTypes uses no templates: lists always work with objects of type unknown or any derivative class. A list (naturally) can contain objects of different types simultaneously.

PTypes lists can optionally free member objects whenever an item is deleted or the entire list is destroyed. This mechanism called "owning objects" can be turned on or off during construction of a list object.

Lists themselves are derived from unknown, thus allowing to construct more complex dynamic structures, such like multidimensional arrays or trees.

Like with string and cset classes, most of the list manipulator functions are defined outside of the classes definitions, i.e. as friend functions. For example, you write add(list, item) instead of list.add(item). This style imitates built-in language types and produces lesser member function calls in your program. In our opinion this style helps to improve readability of your code.

All three list classes have their equivalents declared as templates with a prefix 't' in their names, e.g. tstrlist. These templates are provided for better type checking at compile time. They are fully inlined and do not produce any extra code. An argument to the template can be of any type derived from unknown. For example, if you declare a variable of type tstrlist<myclass>, all pointers accepted or returned by the manipulation functions will be checked for compatibility with myclass at compile-time.

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

See also: unknown


PTypes home