namespace OpenMS { MetaInfoRegistry MetaInfo::registry_ = MetaInfoRegistry(); MetaInfo::MetaInfo() { } MetaInfo::MetaInfo(const MetaInfo & rhs) { *this = rhs; } MetaInfo::~MetaInfo() { } MetaInfo & MetaInfo::operator=(const MetaInfo & rhs) { if (this == &rhs) return *this; index_to_value_ = rhs.index_to_value_; return *this; } bool MetaInfo::operator==(const MetaInfo & rhs) const { return index_to_value_ == rhs.index_to_value_; } bool MetaInfo::operator!=(const MetaInfo & rhs) const { return !(operator==(rhs)); } const DataValue & MetaInfo::getValue(const String & name) const { map<UInt, DataValue>::const_iterator it = index_to_value_.find(registry_.getIndex(name)); if (it != index_to_value_.end()) { return it->second; } return DataValue::EMPTY; } const DataValue & MetaInfo::getValue(UInt index) const { map<UInt, DataValue>::const_iterator it = index_to_value_.find(index); if (it != index_to_value_.end()) { return it->second; } return DataValue::EMPTY; } void MetaInfo::setValue(const String & name, const DataValue & value) { UInt index = registry_.registerName(name); // no-op if name is already registered index_to_value_[index] = value; } void MetaInfo::setValue(UInt index, const DataValue & value) { // @TODO: check if that index is registered in MetaInfoRegistry? index_to_value_[index] = value; } MetaInfoRegistry & MetaInfo::registry() { return registry_; } bool MetaInfo::exists(const String & name) const { UInt index = registry_.getIndex(name); if (index != UInt(-1)) { return (index_to_value_.find(index) != index_to_value_.end()); } return false; } bool MetaInfo::exists(UInt index) const { return (index_to_value_.find(index) != index_to_value_.end()); } void MetaInfo::removeValue(const String & name) { map<UInt, DataValue>::iterator it = index_to_value_.find(registry_.getIndex(name)); if (it != index_to_value_.end()) { index_to_value_.erase(it); } } void MetaInfo::removeValue(UInt index) { map<UInt, DataValue>::iterator it = index_to_value_.find(index); if (it != index_to_value_.end()) { index_to_value_.erase(it); } } void MetaInfo::getKeys(vector<String> & keys) const { keys.resize(index_to_value_.size()); UInt i = 0; for (map<UInt, DataValue>::const_iterator it = index_to_value_.begin(); it != index_to_value_.end(); ++it) { keys[i++] = registry_.getName(it->first); } } void MetaInfo::getKeys(vector<UInt> & keys) const { keys.resize(index_to_value_.size()); UInt i = 0; for (map<UInt, DataValue>::const_iterator it = index_to_value_.begin(); it != index_to_value_.end(); ++it) { keys[i++] = it->first; } } bool MetaInfo::empty() const { return index_to_value_.empty(); } void MetaInfo::clear() { index_to_value_.clear(); } } //namespace
namespace OpenMS { MetaInfoRegistry MetaInfo::registry_ = MetaInfoRegistry(); MetaInfo::MetaInfo() { } MetaInfo::MetaInfo(const MetaInfo & rhs) { *this = rhs; } MetaInfo::~MetaInfo() { } MetaInfo & MetaInfo::operator=(const MetaInfo & rhs) { if (this == &rhs) return *this; index_to_value_ = rhs.index_to_value_; return *this; } bool MetaInfo::operator==(const MetaInfo & rhs) const { return index_to_value_ == rhs.index_to_value_; } bool MetaInfo::operator!=(const MetaInfo & rhs) const { return !(operator==(rhs)); } const DataValue & MetaInfo::getValue(const String & name) const { map<UInt, DataValue>::const_iterator it = index_to_value_.find(registry_.getIndex(name)); if (it != index_to_value_.end()) { return it->second; } return DataValue::EMPTY; } const DataValue & MetaInfo::getValue(UInt index) const { map<UInt, DataValue>::const_iterator it = index_to_value_.find(index); if (it != index_to_value_.end()) { return it->second; } return DataValue::EMPTY; } void MetaInfo::setValue(const String & name, const DataValue & value) { index_to_value_[registry_.getIndex(name)] = value; } void MetaInfo::setValue(UInt index, const DataValue & value) { index_to_value_[index] = value; } MetaInfoRegistry & MetaInfo::registry() { return registry_; } bool MetaInfo::exists(const String & name) const { try { if (index_to_value_.find(registry_.getIndex(name)) == index_to_value_.end()) { return false; } } catch (Exception::InvalidValue) { return false; } return true; } bool MetaInfo::exists(UInt index) const { if (index_to_value_.find(index) == index_to_value_.end()) { return false; } return true; } void MetaInfo::removeValue(const String & name) { map<UInt, DataValue>::iterator it = index_to_value_.find(registry_.getIndex(name)); if (it != index_to_value_.end()) { index_to_value_.erase(it); } } void MetaInfo::removeValue(UInt index) { map<UInt, DataValue>::iterator it = index_to_value_.find(index); if (it != index_to_value_.end()) { index_to_value_.erase(it); } } void MetaInfo::getKeys(vector<String> & keys) const { keys.resize(index_to_value_.size()); UInt i = 0; for (map<UInt, DataValue>::const_iterator it = index_to_value_.begin(); it != index_to_value_.end(); ++it) { keys[i++] = registry_.getName(it->first); } } void MetaInfo::getKeys(vector<UInt> & keys) const { keys.resize(index_to_value_.size()); UInt i = 0; for (map<UInt, DataValue>::const_iterator it = index_to_value_.begin(); it != index_to_value_.end(); ++it) { keys[i++] = it->first; } } bool MetaInfo::empty() const { return index_to_value_.empty(); } void MetaInfo::clear() { index_to_value_.clear(); } } //namespace