Remove some stale code
[shibboleth/cpp-sp.git] / shibsp / attribute / ScopedAttribute.cpp
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 /**
22  * ScopedAttribute.cpp
23  *
24  * An Attribute whose values are relations of a value and a scope.
25  */
26
27 #include "internal.h"
28 #include "attribute/ScopedAttribute.h"
29
30 using namespace shibsp;
31 using namespace std;
32
33 namespace shibsp {
34     SHIBSP_DLLLOCAL Attribute* ScopedAttributeFactory(DDF& in) {
35         return new ScopedAttribute(in);
36     }
37 };
38
39 ScopedAttribute::ScopedAttribute(const vector<string>& ids, char delimeter) : Attribute(ids), m_delimeter(delimeter)
40 {
41 }
42
43 ScopedAttribute::ScopedAttribute(DDF& in) : Attribute(in), m_delimeter('@')
44 {
45     DDF val = in["_delimeter"];
46     if (val.isint())
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();
52     }
53 }
54
55 ScopedAttribute::~ScopedAttribute()
56 {
57 }
58
59 vector< pair<string,string> >& ScopedAttribute::getValues()
60 {
61     return m_values;
62 }
63
64 const vector< pair<string,string> >& ScopedAttribute::getValues() const
65 {
66     return m_values;
67 }
68
69 size_t ScopedAttribute::valueCount() const
70 {
71     return m_values.size();
72 }
73
74 void ScopedAttribute::clearSerializedValues()
75 {
76     m_serialized.clear();
77 }
78
79 const char* ScopedAttribute::getString(size_t index) const
80 {
81     return m_values[index].first.c_str();
82 }
83
84 const char* ScopedAttribute::getScope(size_t index) const
85 {
86     return m_values[index].second.c_str();
87 }
88
89 void ScopedAttribute::removeValue(size_t index)
90 {
91     Attribute::removeValue(index);
92     if (index < m_values.size())
93         m_values.erase(m_values.begin() + index);
94 }
95
96 const vector<string>& ScopedAttribute::getSerializedValues() const
97 {
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);
101     }
102     return Attribute::getSerializedValues();
103 }
104
105 DDF ScopedAttribute::marshall() const
106 {
107     DDF ddf = Attribute::marshall();
108     ddf.name("Scoped");
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());
114         vlist.add(val);
115     }
116     return ddf;
117 }