Data

Stores data of many different kinds in string-based hash maps.  The Data class provides public read-access to data, but gives no public method for changing data, which must be provided by derived classes.  By using hash maps with strings as keys, any class with write access can add new data fields dynamically and instantly, with little overhead.  Data provides data hashes for the following types: integer, integer arrays, two-dimensional integer arrays, integer hashes, floats, strings, string arrays, and date/times.

Project

ModelCore

Include

Data.h

Summary
Stores data of many different kinds in string-based hash maps.
Reads a keyed value from a hash map.
Provides specialized read-only access for integer hash data.
The Data destructor.
Gives direct access to data in a hash map.
Erases the given key from the hash map.
Copies data from a given Data class to this one.
Reads data from an input stream.
Writes data to an output stream.
The hash of integers.
The hash of arrays of integers.
The hash of two-dimensional arrays of integers.
The hash of hashes of integers.
The hash of floats.
The hash of wxStrings.
The hash of arrays of wxStrings.
The hash of date/times.

Public

Summary
Reads a keyed value from a hash map.
Provides specialized read-only access for integer hash data.

Functions

read

template <typename T> const T& read(const wxString &key) const

Reads a keyed value from a hash map.  If the key does not exist in the hash map, an error is raised in a popup window specifying the key and the type of data that was attempting to be read.

Parameters

keyThe key to look up in the data hash.

Returns

A const reference to the data corresponding to the key.  It is read-only.

read

wxInt32 read(const wxString &key,
const wxString &hashKey)

Provides specialized read-only access for integer hash data.  Because a wxWidgets hash map does not have a const [] operator, it is unsafe to just look up specific integer hash data without a key, so this function is necessary.

Parameters

keyThe key that finds an integer hash.
hashKeyThe key to look up in the integer hash.

Returns

The data corresponding to the key.

Protected

Summary
The Data destructor.
Gives direct access to data in a hash map.
Erases the given key from the hash map.
Copies data from a given Data class to this one.
Reads data from an input stream.
Writes data to an output stream.

Destructor

~Data

virtual ~Data()=0

The Data destructor.  It is pure virtual because this class must be derived from to be used.

Functions

data

template <typename T> T& data(const wxString &key, 
bool safety = false)

Gives direct access to data in a hash map.  If the type of the data does not match one of the hash maps, the code will not compile.

Parameters

keyThe key to access in the hash.
safetyA flag to ensure the key exists.  If true, the key is first searched for before writing to it, and if the key does not exist, an error message is shown on the screen and the default constructed value for that data type.

Returns

A reference to the data corresponding to the key.  It is writable.

erase

template <typename T> void erase(const wxString &key)

Erases the given key from the hash map.

Parameters

keyThe key to erase in the hash.

copy

void copy(const Data &data)

Copies data from a given Data class to this one.

Parameters

dataThe data to copy from.

load

void load(wxDataInputStream &stream)

Reads data from an input stream.

Parameters

streamThe input stream.

save

void save(wxDataOutputStream &stream) const

Writes data to an output stream.

Parameters

streamThe output stream.

Private

Summary
The hash of integers.
The hash of arrays of integers.
The hash of two-dimensional arrays of integers.
The hash of hashes of integers.
The hash of floats.
The hash of wxStrings.
The hash of arrays of wxStrings.
The hash of date/times.

Variables

mInts

IntHash mInts

The hash of integers.

mIntArrays

IntArrayHash mIntArrays

The hash of arrays of integers.

mInt2Arrays

IntArray2Hash mInt2Arrays

The hash of two-dimensional arrays of integers.

mIntHashes

IntHashHash mIntHashes

The hash of hashes of integers.

mFloats

FloatHash mFloats

The hash of floats.

mStrings

StringHash mStrings

The hash of wxStrings.

mStringArrays

StringArrayHash mStringArrays

The hash of arrays of wxStrings.

mTimes

DateTimeHash mTimes

The hash of date/times.

template <typename T> const T& read(const wxString &key) const
Reads a keyed value from a hash map.
virtual ~Data()=0
The Data destructor.
template <typename T> T& data(const wxString &key, 
bool safety = false)
Gives direct access to data in a hash map.
template <typename T> void erase(const wxString &key)
Erases the given key from the hash map.
void copy(const Data &data)
Copies data from a given Data class to this one.
void load(wxDataInputStream &stream)
Reads data from an input stream.
void save(wxDataOutputStream &stream) const
Writes data to an output stream.
IntHash mInts
The hash of integers.
IntArrayHash mIntArrays
The hash of arrays of integers.
IntArray2Hash mInt2Arrays
The hash of two-dimensional arrays of integers.
IntHashHash mIntHashes
The hash of hashes of integers.
FloatHash mFloats
The hash of floats.
StringHash mStrings
The hash of wxStrings.
StringArrayHash mStringArrays
The hash of arrays of wxStrings.
DateTimeHash mTimes
The hash of date/times.
ModelCore provides all of the data classes and associated helper classes and functions required to represent a complete game.