NEXUS CLASS LIBRARY home | classes | functions

Class NxsSetReader



Data Members

block, max, nxsset, settype, token

Member Functions

AddRange, GetTokenValue, NxsSetReader, Run

Class Description

A class for reading NEXUS set objects and storing them in a set of int values. The NxsUnsignedSet nxsset will be cleared, and nxsset will be built up as the set is read, with each element in the list storing a member of the set (ranges are stored as individual elements). This class handles set descriptions of the following form:

 4-7 15 20-.3;
The above set includes every number from 4 to 7 (inclusive), 15 and every third number from 20 to max, where max would ordinarily be set to either the last character (if settype is `NxsSetReaderEnum::charset') or the last taxon (if settype is `NxsSetReaderEnum::taxset'). If max equaled 30, the example above would be stored as follows (remember that internally the numbers are stored with offset 0, even though in the NEXUS data file the numbers always start at 1.
 3, 4, 5, 6, 14, 19, 22, 25, 28
The following example of how NxsSetReader is used comes from the NxsCharactersBlock ::HandleEliminate function:
 NxsSetReader(token, ncharTotal, eliminated, *this, NxsSetReader::charset).Run();
This reads in a set of eliminated characters from a NEXUS data file, storing the resulting set in the data member eliminated. In this case max is set to ncharTotal (the total number of characters), and the block reference is set to the NxsCharactersBlock object, which provides a

Key to symbols and colors

public, protected, private, A = abstract, C = constructor, D = destructor, I = inline, S = static, V = virtual, F = friend


enum NxsSetReaderEnum
  generic = 1
    means expect a generic set (say, characters weights)
  charset = 2
    means expect a character set
  taxset = 3
    means expect a taxon set


Data Members
     NxsBlock   &block
reference to the block object used for looking up labels
     unsigned   max
maximum number of elements in the set
     NxsUnsignedSet   &nxsset
reference to the NxsUnsignedSet set being read
     unsigned   settype
the type of set being read (see the NxsSetReaderEnum enumeration)
     NxsToken   &token
reference to the token being used to parse the NEXUS data file


Member Functions
    bool   AddRange(unsigned first, unsigned last, unsigned modulus)
Adds the range specified by first, last, and modulus to the set. If modulus is zero it is ignored. The parameters first and last refer to numbers found in the data file itself, and thus have range [1..max]. They are stored in nxsset, however, with offset 0. For example, if the data file says "4-102" this function would be called with first = 4, last = 10 and modulus = 2, and the values stored in nxsset would be 3, 5, 7, 9. The return value is true unless last is greater than max, first is less than 1, or first is greater than last: in any of these cases, the return value is false to indicate failure to store this range.
    unsigned   GetTokenValue()
Tries to interpret token as a number. Failing that, tries to interpret token as a character or taxon label, which it then converts to a number. Failing that, it throws a NxsException exception.
C     NxsSetReader(NxsToken &t, unsigned maxValue, NxsUnsignedSet &iset, NxsBlock &nxsblk, unsigned type)
Initializes max to maxValue, settype to type, token to t, block to nxsblk and nxsset to iset, then clears nxsset.
    bool   Run()
Reads in a set from a NEXUS data file. Returns true if the set was terminated by a semicolon, false otherwise.