Skip to content

DataMap

Clifford Bohm edited this page Jan 8, 2017 · 9 revisions

A DataMap is used to collect data about some object. The data is stored in a map, that is an unordered list of key-value pairs. Data can be added to and removed from the DataMap. The values in data maps can be bool, int, double or string. DataMaps also include functions to save their contents to files.

###Usage Set(), Get() and, Append() methods write values into and read values from a data Map.

  • Set(key,value) - set a value in a data map associated with key.
  • Append(key,value) - add a value to a list of values associated with key.
  • setOutputBehavior(key, outputBehavior) - define how data associated with key will be saved to file when saveToFile() is called. outputBehavior options are: LIST, AVE, FIRST (more will be implimented in the future). If more then one output behavior is needed, list them sperated with '|' (e.g. setOutputBehavior("score", DataMap::AVE | DataMap::LIST) )
  • GetBoolVector(key),GetIntVector(key),GetDoubleVector(key),GetStringVector(key) - get a vector of the given type associated with key.
  • GetStringOfVector(key) - convert the values associated key to a string
  • GetAverage(key) - retuns a double, which is the average of the values associated with key. If key is associated with string values, this will result in an error message.
  • Clear(key) - clear entry for key from a dataMap
  • ClearMap() - clear all elements from dataMap
  • fieldExists(key) - return true if this key is in map
  • writeToFile(fileName, keys, aveOnly) - save the contents of this DataMap to file 'fileName'. If keys are provided (a vector of string) then only write these keys data. If aveOnly (bool, default false), than only save average values (not lists, etc.)

    ###Interface

    void setOutputBehavior(const string& key, int _outputBehavior) { void Merge(DataMap otherDataMap, bool replace = 0) { Get*Vector(const string &key) GetStringOfVector(const string &key) // retrieve a string from a dataMap with "key" - if not already string,
    will be converted double GetAverage(string key) // take two strings (header and data), and a list of keys, and whether or not to save "{LIST}"s. convert data from data map to header and data strings

    inline void constructHeaderAndDataStrings(string& headerStr, string& dataStr, const vector& keys, bool aveOnly = false) {

    template void Set(const string &key, const Type& value)
    sets a key/value pair in DataMap
    string Get(const string &key);
    retrieve the value associated with "key"
    template void Append(const string &key, const Type &value)
    appends a value at "key" to a DataMap.
    This creates a list with the format "[Value1,Value2,Value3,...]" associated with key. If Set() is used on a list, it will overwrite the list. If Append() is used with value what was assigned with Set(), an error will be reported and MABE will terminate.

    vector getColumnNames(){

    void Clear(const string &key)
    Clear the key and it's data from the DataMap
    void ClearMap()
    clear all keys (and data) from the DataMap
    bool fieldExists(const string &key);
    retrun true DataMap contains key
    void writeToFile(const string &fileName, const vector& keys = { }) 
    write the contents of this DataMap to fileName
    This file will contain a header line with the key names. If keys is provided, then only write the values associated with keys.
    vector getKeys()
    return a vector with all of the keys in this DataMap
Clone this wiki locally