diff options
author | Jay Berkenbilt <ejb@ql.org> | 2008-04-29 14:55:25 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2008-04-29 14:55:25 +0200 |
commit | 9a0b88bf7777c153dc46ace22db74ef24d51583a (patch) | |
tree | f567ac1cf2bf5071a611eb49323a935b6ac938ff /libqpdf/QPDF_Dictionary.cc | |
download | qpdf-9a0b88bf7777c153dc46ace22db74ef24d51583a.tar.zst |
update release date to actual daterelease-qpdf-2.0
git-svn-id: svn+q:///qpdf/trunk@599 71b93d88-0707-0410-a8cf-f5a4172ac649
Diffstat (limited to 'libqpdf/QPDF_Dictionary.cc')
-rw-r--r-- | libqpdf/QPDF_Dictionary.cc | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc new file mode 100644 index 00000000..654df688 --- /dev/null +++ b/libqpdf/QPDF_Dictionary.cc @@ -0,0 +1,84 @@ + +#include <qpdf/QPDF_Dictionary.hh> + +#include <qpdf/QPDF_Null.hh> +#include <qpdf/QPDF_Name.hh> + +QPDF_Dictionary::QPDF_Dictionary( + std::map<std::string, QPDFObjectHandle> const& items) : + items(items) +{ +} + +QPDF_Dictionary::~QPDF_Dictionary() +{ +} + +std::string +QPDF_Dictionary::unparse() +{ + std::string result = "<< "; + for (std::map<std::string, QPDFObjectHandle>::iterator iter = + this->items.begin(); + iter != this->items.end(); ++iter) + { + result += QPDF_Name::normalizeName((*iter).first) + + " " + (*iter).second.unparse() + " "; + } + result += ">>"; + return result; +} + +bool +QPDF_Dictionary::hasKey(std::string const& key) +{ + return ((this->items.count(key) > 0) && + (! this->items[key].isNull())); +} + +QPDFObjectHandle +QPDF_Dictionary::getKey(std::string const& key) +{ + // PDF spec says fetching a non-existent key from a dictionary + // returns the null object. + if (this->items.count(key)) + { + // May be a null object + return (*(this->items.find(key))).second; + } + else + { + return QPDFObjectHandle::newNull(); + } +} + +std::set<std::string> +QPDF_Dictionary::getKeys() +{ + std::set<std::string> result; + for (std::map<std::string, QPDFObjectHandle>::const_iterator iter = + this->items.begin(); + iter != this->items.end(); ++iter) + { + if (hasKey((*iter).first)) + { + result.insert((*iter).first); + } + } + return result; +} + +void +QPDF_Dictionary::replaceKey(std::string const& key, + QPDFObjectHandle const& value) +{ + // add or replace value + this->items[key] = value; +} + +void +QPDF_Dictionary::removeKey(std::string const& key) +{ + // no-op if key does not exist + this->items.erase(key); +} |