Brief Introduction to Some Simple Classes: DSL arrays

From DSL

Jump to: navigation, search

The library defines several array types that help to store important data. Among them there are: DSL_intArray, DSL_doubleArray, DSL_stringArray, and DSL_idArray. In versions of SMILE:up to 1.1, all arrays were derived from DSL_array (which in turn derived from DSL_object.) In version 1.1, DSL_intArray and DSL_doubleArray have no base class due to performance issues with very large models. However, they support all DSL_array methods, so code using these classes should compile without problems.

SMILE: arrays are supposed to be a mixture of an array and a list, because sometimes is convenient to use the data as a list and sometimes as an array. You only have to be careful when "switching" from one mode of operation to the other.

These classes support the typical methods (Add, Delete, FindPosition, IsInList, etc).

  • DSL_intArray: includes two extra functions, AddExclusive (adds the element only if it is not already in the list) and DeleteDuplicates (deletes every duplication of an element, leaving only one of them). To avoid excessive memory allocations, DSL_intArray provides a built-in buffer containing up to 8 int elements.
  • DSL_doubleArray: behaves exactly as DSL_intArray. Built-in buffer holds up to 4 doubles.
  • DSL_stringArray: the strings in this array should be read with the [] operator but should be set using the function SetString to allow proper allocation/deallocation of memory.
  • DSL_idArray: this class behaves exactly like the DSL_stringArray except that it is more restrictive in the strings it can contain. In particular, it will not allow duplicated strings or strings that do not comply with SMILE: rules for identifiers (must start with a letter and can only contain letters, numbers and underscores). It facilitates the handling of lists of identifiers and gives the ability to automatically validate/create new identifiers through the functions CreateAndAddValidId, CreateAndInsertValidId and CreateValidId.
Personal tools