Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-sp.git] / shibsp / attribute / ScopedAttribute.h
1 /*
2  *  Copyright 2001-2009 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file shibsp/attribute/ScopedAttribute.h
19  * 
20  * An Attribute whose values are relations of a value and a scope.
21  */
22
23 #ifndef __shibsp_scopedattr_h__
24 #define __shibsp_scopedattr_h__
25
26 #include <shibsp/attribute/Attribute.h>
27
28 namespace shibsp {
29
30 #if defined (_MSC_VER)
31     #pragma warning( push )
32     #pragma warning( disable : 4251 )
33 #endif
34
35     /**
36      * An Attribute whose values are relations of a value and a scope.
37      * 
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
43      * unconstrained).
44      */
45     class SHIBSP_API ScopedAttribute : public Attribute
46     {
47     public:
48         /**
49          * Constructor.
50          * 
51          * @param ids   array with primary identifier in first position, followed by any aliases
52          * @param delimeter value/scope delimeter when serializing
53          */
54         ScopedAttribute(const std::vector<std::string>& ids, char delimeter='@');
55
56         /**
57          * Constructs based on a remoted ScopedAttribute.
58          * 
59          * @param in    input object containing marshalled ScopedAttribute
60          */
61         ScopedAttribute(DDF& in);
62         
63         virtual ~ScopedAttribute();
64
65         /**
66          * Returns the set of values encoded as UTF-8 strings.
67          * 
68          * <p>Each compound value is a pair containing the simple value and the scope. 
69          * 
70          * @return  a mutable vector of the values
71          */
72         std::vector< std::pair<std::string,std::string> >& getValues();
73
74         /**
75          * Returns the set of values encoded as UTF-8 strings.
76          * 
77          * <p>Each compound value is a pair containing the simple value and the scope. 
78          * 
79          * @return  an immutable vector of the values
80          */
81         const std::vector< std::pair<std::string,std::string> >& getValues() const;
82
83         // Virtual function overrides.
84         size_t valueCount() const;
85         void clearSerializedValues();
86         const char* getString(size_t index) const;
87         const char* getScope(size_t index) const;
88         void removeValue(size_t index);
89         const std::vector<std::string>& getSerializedValues() const;
90         DDF marshall() const;
91     
92     private:
93         char m_delimeter;
94         std::vector< std::pair<std::string,std::string> > m_values;
95     };
96
97 #if defined (_MSC_VER)
98     #pragma warning( pop )
99 #endif
100
101 };
102
103 #endif /* __shibsp_scopedattr_h__ */