VCF::Dictionary Class Reference
The
Dictionary class is a utility class useful storing a collection of key-value pairs.
More...
#include <vcf/FoundationKit/Dictionary.h>
Inheritance diagram for VCF::Dictionary:
List of all members.
Detailed Description
The
Dictionary class is a utility class useful storing a collection of key-value pairs.
It is not a separate implementation, but instead uses the STL std::map as it's underlying data member. Usage of the class is the same as the std::map, and it is basically the same as working with a std::map<String,VariantData>. The class is intended for use when you want to have a named collection of various values. Using the VariantData as the value type, allows you to easily store any type of value. For example:
Dictionary dict;
dict["size"] = 200;
dict["Name"] = "Bob";
We now have two entries, one name "Name" and one named "size".
The other primary difference from a std::map<String,VariantData> is the support for persistence. The Dictionary class implements the Persistable interface, and can be written to, or read from, an OutputStream or InputStream (respectively). For example, to save to a file:
FileOutputStream fs("test.dict.txt");
fs << &dict;
And to read from a file:
FileInputStream fs("test.dict.txt");
fs >> &dict;
The reason for deriving the Dictionary class from the Object root class is so that a Dictionary instance may itself be a value in a "parent" dictionary. For example:
Dictionary stuff;
Dictionary moreStuff;
stuff["food"] = "empty";
moreStuff["paintings"] = 10;
moreStuff["lightbulbs"] = 1298;
stuff["junk"] = &moreStuff;
If you'd like a fancier persistence scheme, in the Dictionaries example there's a simple implementation of reading and writing the dictionary to an xml based stream. The format for the xml tags is the same as that used Apple's PList xml format. See http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/Concepts/XMLPListsConcept.html for more information on this format.
Member Typedef Documentation
Constructor & Destructor Documentation
| VCF::Dictionary::Dictionary |
( |
|
) |
|
|
| VCF::Dictionary::Dictionary |
( |
const Dictionary & |
rhs |
) |
|
|
| virtual VCF::Dictionary::~Dictionary |
( |
|
) |
[virtual] |
|
Member Function Documentation
| void VCF::Dictionary::clear |
( |
|
) |
|
|
| virtual Object* VCF::Dictionary::clone |
( |
bool |
deep = false |
) |
const [inline, virtual] |
|
|
|
Makes a complete clone of this object.
A typical implementation might be: virtual Object* clone( bool deep ) {
return new MyObject( this );
}
In which the implementer simply creates a new instance on the heap and calls the copy constructor. Objects which support cloning should also have a copy constructor defined as well.
- Parameters:
-
| bool | deep if deep is true then any object instances that this object owns should probably be cloned as well, with full new copies made. Otherwise it would be acceptable to simply copy the pointer values. The default value is for deep cloning to be false. |
- Returns:
- Object a new instance that should be an copy of this. If the object doesn't support cloning the return will value will be NULL.
Reimplemented from VCF::Object. |
| bool VCF::Dictionary::empty |
( |
|
) |
const |
|
|
|
Returns true if the dictionary has no values in it, otherwise returns false.
|
| Value VCF::Dictionary::get |
( |
const Key & |
key |
) |
const |
|
| Value& VCF::Dictionary::get |
( |
const Key & |
key |
) |
|
|
| bool VCF::Dictionary::getOwnsObjectValues |
( |
|
) |
const [inline] |
|
|
|
Returns whether or not the dictionary "owns" the object values in it.
If it does it will clean up these instances when the dictionary is destroyed. |
| void VCF::Dictionary::insert |
( |
const Key & |
key, |
|
|
const Value & |
value |
|
) |
|
|
| bool VCF::Dictionary::keyExists |
( |
const Key & |
key |
) |
const |
|
|
|
Returns whether or not the specified key exists in the collection.
|
|
|
Read the object from the specified input stream.
- Parameters:
-
| InputStream | |
| MIMEType | indicates how to read the data from the stream. For example, if the object was some sort of image object, and had an array of pixels, then the type might indicate how the data in the stream should be interpreted, such as the JPEG format ("image/jpeg"), or the PNG format ("image/png"). |
Implements VCF::Persistable.
Reimplemented in VCF::PropertyListing. |
| size_type VCF::Dictionary::max_size |
( |
|
) |
const |
|
|
|
returns the maximum size of the dictionary.
|
| Value VCF::Dictionary::operator[] |
( |
const Key & |
key |
) |
const |
|
| Value& VCF::Dictionary::operator[] |
( |
const Key & |
key |
) |
|
|
| void VCF::Dictionary::remove |
( |
const Key & |
key |
) |
|
|
|
|
Write the object to the specified output stream.
- Parameters:
-
| OutputStream | |
| MIMEType | indicates how the object should write it's data. For example, if the object was some sort of image object, and had an array of pixels, then the type might indicate what kind of image type to write the data in, such as the JPEG format ("image/jpeg"), or the PNG format ("image/png"). |
Implements VCF::Persistable.
Reimplemented in VCF::PropertyListing. |
| void VCF::Dictionary::setOwnsObjectValues |
( |
const bool & |
val |
) |
[inline] |
|
|
|
Sets the owns object value flag, which tells the dictionary whether or not it should clean up object values when the dictionary is destroyed.
|
|
|
returns the number of elements in the dictionary.
|
Member Data Documentation
The documentation for this class was generated from the following file: