2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
24 * An Attribute whose values are relations of a value and a scope.
28 #include "attribute/ScopedAttribute.h"
30 using namespace shibsp;
34 SHIBSP_DLLLOCAL Attribute* ScopedAttributeFactory(DDF& in) {
35 return new ScopedAttribute(in);
39 ScopedAttribute::ScopedAttribute(const vector<string>& ids, char delimeter) : Attribute(ids), m_delimeter(delimeter)
43 ScopedAttribute::ScopedAttribute(DDF& in) : Attribute(in), m_delimeter('@')
45 DDF val = in["_delimeter"];
47 m_delimeter = static_cast<char>(val.integer());
48 val = in.first().first();
49 while (val.name() && val.string()) {
50 m_values.push_back(make_pair(string(val.name()), string(val.string())));
51 val = in.first().next();
55 ScopedAttribute::~ScopedAttribute()
59 vector< pair<string,string> >& ScopedAttribute::getValues()
64 const vector< pair<string,string> >& ScopedAttribute::getValues() const
69 size_t ScopedAttribute::valueCount() const
71 return m_values.size();
74 void ScopedAttribute::clearSerializedValues()
79 const char* ScopedAttribute::getString(size_t index) const
81 return m_values[index].first.c_str();
84 const char* ScopedAttribute::getScope(size_t index) const
86 return m_values[index].second.c_str();
89 void ScopedAttribute::removeValue(size_t index)
91 Attribute::removeValue(index);
92 if (index < m_values.size())
93 m_values.erase(m_values.begin() + index);
96 const vector<string>& ScopedAttribute::getSerializedValues() const
98 if (m_serialized.empty()) {
99 for (vector< pair<string,string> >::const_iterator i=m_values.begin(); i!=m_values.end(); ++i)
100 m_serialized.push_back(i->first + m_delimeter + i->second);
102 return Attribute::getSerializedValues();
105 DDF ScopedAttribute::marshall() const
107 DDF ddf = Attribute::marshall();
109 if (m_delimeter != '@')
110 ddf.addmember("_delimeter").integer(m_delimeter);
111 DDF vlist = ddf.first();
112 for (vector< pair<string,string> >::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
113 DDF val = DDF(i->first.c_str()).string(i->second.c_str());