2 * Copyright 2009 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * An Attribute whose values are relations of a value and a scope.
24 #include "attribute/ScopedAttribute.h"
26 using namespace shibsp;
30 SHIBSP_DLLLOCAL Attribute* ScopedAttributeFactory(DDF& in) {
31 return new ScopedAttribute(in);
35 ScopedAttribute::ScopedAttribute(const vector<string>& ids, char delimeter) : Attribute(ids), m_delimeter(delimeter)
39 ScopedAttribute::ScopedAttribute(DDF& in) : Attribute(in), m_delimeter('@')
41 DDF val = in["_delimeter"];
43 m_delimeter = static_cast<char>(val.integer());
44 val = in.first().first();
45 while (val.name() && val.string()) {
46 m_values.push_back(make_pair(string(val.name()), string(val.string())));
47 val = in.first().next();
51 ScopedAttribute::~ScopedAttribute()
55 vector< pair<string,string> >& ScopedAttribute::getValues()
60 const vector< pair<string,string> >& ScopedAttribute::getValues() const
65 size_t ScopedAttribute::valueCount() const
67 return m_values.size();
70 void ScopedAttribute::clearSerializedValues()
75 const char* ScopedAttribute::getString(size_t index) const
77 return m_values[index].first.c_str();
80 const char* ScopedAttribute::getScope(size_t index) const
82 return m_values[index].second.c_str();
85 void ScopedAttribute::removeValue(size_t index)
87 Attribute::removeValue(index);
88 if (index < m_values.size())
89 m_values.erase(m_values.begin() + index);
92 const vector<string>& ScopedAttribute::getSerializedValues() const
94 if (m_serialized.empty()) {
95 for (vector< pair<string,string> >::const_iterator i=m_values.begin(); i!=m_values.end(); ++i)
96 m_serialized.push_back(i->first + m_delimeter + i->second);
98 return Attribute::getSerializedValues();
101 DDF ScopedAttribute::marshall() const
103 DDF ddf = Attribute::marshall();
105 if (m_delimeter != '@')
106 ddf.addmember("_delimeter").integer(m_delimeter);
107 DDF vlist = ddf.first();
108 for (vector< pair<string,string> >::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
109 DDF val = DDF(i->first.c_str()).string(i->second.c_str());