2 * Copyright 2001-2007 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.
18 * @file shibsp/attribute/ScopedAttribute.h
20 * An Attribute whose values are relations of a value and a scope.
23 #ifndef __shibsp_scopedattr_h__
24 #define __shibsp_scopedattr_h__
26 #include <shibsp/attribute/Attribute.h>
30 #if defined (_MSC_VER)
31 #pragma warning( push )
32 #pragma warning( disable : 4251 )
36 * An Attribute whose values are relations of a value and a scope.
38 * <p>In practice, scoped attributes are simple pairs of strings instead
39 * of a single string. They can be expressed as a string easily using a delimeter,
40 * typically an '@' symbol. The scope concept allows certain kinds of filtering to
41 * be performed more intelligently and efficiently, although not all scoped
42 * attributes can be effectively filtered (e.g. if the set of scope values is
45 class SHIBSP_API ScopedAttribute : public Attribute
51 * @param id Attribute identifier
53 ScopedAttribute(const char* id) : Attribute(id), m_caseSensitive(true) {}
56 * Constructs based on a remoted ScopedAttribute.
58 * @param in input object containing marshalled ScopedAttribute
60 ScopedAttribute(DDF& in) : Attribute(in), m_caseSensitive(in["case_insensitive"].isnull()) {
61 DDF val = in.first().first();
62 while (val.name() && val.string()) {
63 m_values.push_back(std::make_pair(val.name(), val.string()));
68 virtual ~ScopedAttribute() {}
70 bool isCaseSensitive() const {
71 return m_caseSensitive;
75 * Returns the set of values encoded as UTF-8 strings.
77 * <p>Each compound value is a pair containing the simple value and the scope.
79 * @return a mutable vector of the values
81 std::vector< std::pair<std::string,std::string> >& getValues() {
85 size_t valueCount() const {
86 return m_values.size();
89 void clearSerializedValues() {
93 const std::vector<std::string>& getSerializedValues() const {
94 if (m_serialized.empty()) {
95 for (std::vector< std::pair<std::string,std::string> >::const_iterator i=m_values.begin(); i!=m_values.end(); ++i)
96 m_serialized.push_back(i->first + '@' + i->second);
98 return Attribute::getSerializedValues();
101 DDF marshall() const {
102 DDF ddf = Attribute::marshall();
104 if (!m_caseSensitive)
105 ddf.addmember("case_insensitive");
106 DDF vlist = ddf.first();
107 for (std::vector< std::pair<std::string,std::string> >::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
108 DDF val = DDF(i->first.c_str()).string(i->second.c_str());
115 bool m_caseSensitive;
116 std::vector< std::pair<std::string,std::string> > m_values;
119 #if defined (_MSC_VER)
120 #pragma warning( pop )
125 #endif /* __shibsp_scopedattr_h__ */