1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
7 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
13 * This library is free software; you can redistribute it and/or modify it *
14 * under the terms of the GNU Library General Public License as published *
15 * by the Free Software Foundation, version 2. *
17 * This library is distributed in the hope that it will be useful, but *
18 * WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
20 * Library General Public License for more details. *
22 * You should have received a copy of the GNU Library General Public *
23 * License along with this library; if not, write to the Free Software *
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
35 \*---------------------------------------------------------------------------*/
37 //---------------------------------------------------------------------------
39 //---------------------------------------------------------------------------
43 /*! Provides read-only access to the keys multi-field of this attribute map.
44 Among other things, this can be used for iterating over the contents of
49 const MFString& StringAttributeMap::getKeys(void) const
51 return *StringAttributeMapBase::getMFKeys();
54 /*! Queries this attribute map attachment to determine if it includes the
55 named key. If it does, then true is returned. Otherwise, false is
60 bool StringAttributeMap::hasAttribute(const std::string &key) const
62 return getKeys().find(key) != getKeys().end();
65 /*! Attempts to look up the value associated with the named key in this
66 attribute map. If this attribute map does not include \p key, then an
67 empty string is returned. Otherwise, a copy of the value associated
68 with the named key is returned.
72 const std::string StringAttributeMap::getAttribute(const std::string &key) const
75 getAttribute(key, value);
79 /*! Provides index access to this attribute map following the semantics of
80 the STL map type. If this attribute map contains \p key, a reference to
81 the value associated with that key is returned. Otherwise, \p key is
82 added to this attribute map with an empty string as the value, and a
83 reference to that newly added value is returned.
85 It is the responsibility of the caller to use OSG::beginEditCP() and
86 OSG::endEditCP() accordingly. Both fields of this container (Keys and
87 Values) may be edited by this method depending on the usage. In the case
88 when a key/value pair is being changed or added, the fields will be
89 edited. In the case when an unknown key is used for querying a value,
90 both fields will be edited. When this operator is used solely to query an
91 existing key's value, then no fields will be edited.
99 std::string &StringAttributeMap::operator[](const std::string &key)
101 MFString *keys = this->StringAttributeMapBase::editMFKeys();
102 MFString *values = this->StringAttributeMapBase::editMFValues();
104 unsigned int index(0);
105 for (MFString::iterator i = keys->begin();
106 i != keys->end(); ++i, ++index )
110 return (*values)[index];
114 keys->push_back(key);
115 values->push_back(std::string(""));
117 // The value we want to return is at the end of _mfValues.
118 return (*values)[values->size() - 1];