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.
22 * @file shibsp/remoting/ddf.h
24 * C++ DDF abstraction for interpretive RPC
30 #include <shibsp/base.h>
38 * DDF objects are implemented with a handle-body idiom and require explicit
39 * destruction in order to allow stack objects to be freely mixed in structures
40 * with heap objects. When stack objects leave scope, only the handle is freed.
41 * Copying and assigning handle objects is a constant time operation equivalent
42 * to a single pointer assignment, handled by compiler-generated behavior.
51 DDF(const char* n, const char* val, bool safe=true);
52 DDF(const char* n, long val);
53 DDF(const char* n, double val);
54 DDF(const char* n, void* val);
56 DDF& destroy(); // deep destructor
57 DDF copy() const; // deep copy routine
60 const char* name() const; DDF& name(const char* n);
62 // basic type checking
65 bool isstring() const;
68 bool isstruct() const;
70 bool ispointer() const;
72 // type conversion and value extraction
73 const char* string() const; // legal for str
74 long integer() const; // legal for all types
75 double floating() const; // legal for float
76 void* pointer() const; // legal for pointer
78 // string helper methods
79 size_t strlen() const;
80 bool operator==(const char* s) const;
82 // destructive node conversion methods
84 DDF& string(char* val, bool copyit=true, bool safe=true);
85 DDF& string(const char* val);
86 DDF& unsafe_string(const char* val);
87 DDF& string(long val);
88 DDF& string(double val);
89 DDF& integer(long val);
90 DDF& integer(const char* val);
91 DDF& floating(double val);
92 DDF& floating(const char* val);
95 DDF& pointer(void* val);
97 // list/struct methods
99 DDF& addbefore(DDF& child, DDF& before);
100 DDF& addafter(DDF& child, DDF& after);
112 DDF operator[](unsigned long index) const;
113 DDF operator[](const char* path) const;
115 // named member access/creation
116 DDF addmember(const char* path);
117 DDF getmember(const char* path) const;
120 void dump(FILE* f=nullptr, int indent=0) const;
122 // serialization functions need private access
123 friend SHIBSP_API std::ostream& operator<<(std::ostream& os, const DDF& obj);
124 friend SHIBSP_API std::istream& operator>>(std::istream& is, DDF& obj);
127 struct ddf_body_t* m_handle;
131 * Serializes a DDF object to a stream.
133 * @param os output stream
134 * @param obj DDF object to serialize
135 * @return reference to the output stream
137 SHIBSP_API std::ostream& operator<<(std::ostream& os, const DDF& obj);
140 * Reconstitutes a DDF object from a stream.
142 * @param is input stream
143 * @param obj DDF object to reconstitute
144 * @return reference to the input stream
146 SHIBSP_API std::istream& operator>>(std::istream& is, DDF& obj);
149 * A "smart pointer" for disposing of DDF objects when they leave scope.
151 class SHIBSP_API DDFJanitor
154 DDFJanitor(DDF& obj) : m_obj(obj) {}
155 ~DDFJanitor() { m_obj.destroy(); }
158 DDFJanitor(const DDFJanitor&);
159 DDFJanitor& operator=(const DDFJanitor&);