/usr/include/camp/userobject.hpp is in libcamp0.7-dev 0.7.1.1-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | /****************************************************************************
**
** Copyright (C) 2009-2010 TECHNOGERMA Systems France and/or its subsidiary(-ies).
** Contact: Technogerma Systems France Information (contact@technogerma.fr)
**
** This file is part of the CAMP library.
**
** CAMP is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CAMP is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with CAMP. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef CAMP_USEROBJECT_HPP
#define CAMP_USEROBJECT_HPP
#include <camp/args.hpp>
#include <camp/classcast.hpp>
#include <camp/errors.hpp>
#include <camp/detail/objecttraits.hpp>
#include <camp/detail/objectholder.hpp>
#ifndef Q_MOC_RUN
#include <boost/operators.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/utility/enable_if.hpp>
#endif
#include <string>
namespace camp
{
class Property;
class UserProperty;
class Value;
class ParentObject;
/**
* \brief Wrapper to manipulate user objects in the CAMP system
*
* camp::UserObject is an abstract representation of object instances, which can safely
* be passed to and manipulated by all the entities in CAMP.
*
* \sa EnumObject
*/
class CAMP_API UserObject : boost::totally_ordered<UserObject>
{
public:
/**
* \brief Default constructor
*
* Constructs an empty/invalid object
*/
UserObject();
/**
* \brief Construct the user object from an instance
*
* This constructor is equivalent to calling UserObject::ref(object),
* i.e. the object is stored by reference.
*
* \param object Instance to store in the user object
*/
template <typename T>
UserObject(const T& object);
template<typename T>
UserObject(const T& object, std::string type);
/**
* \brief Construct the user object from a parent object and a member property
*
* This constructor allows to create user objects that are accessed through a property
* of another user object, and that cannot be stored in memory.
*
* \param parent Parent user object
* \param member Member of \a parent used to access the actual object
*/
UserObject(const UserObject& parent, const UserProperty& member);
/**
* \brief Copy constructor
*
* \param copy Instance to copy
*/
UserObject(const UserObject& copy);
/**
* \brief Retrieve the instance stored in the user object
*
* The template parameter T is the type to convert the instance to.
* T must be compatible with the original type of the instance.
*
* \return Reference to the instance of the stored object
*
* \throw NullObject the stored object is invalid
* \throw ClassNotFound T has not metaclass
* \throw ClassUnrelated the type of the object is not compatible with T
*/
template <typename T>
typename detail::ObjectTraits<T>::RefReturnType get() const;
/**
* \brief Retrieve the address of the stored object
*
* This function must be used with caution, as the returned address
* may not be what you expect it to be!
*
* \return Pointer to the stored object
*/
void* pointer() const;
/**
* \brief Retrieve the metaclass of the stored instance
*
* \return Reference to the instance's metaclass
*
* \throw NullObject the stored object has no metaclass
*/
const Class& getClass() const;
/**
* \brief Get the value of an object's property
*
* This function is defined for convenience, it is a shortcut
* for <tt>object.getClass().property(name).get(object);</tt>
*
* \param property Name of the property to get
*
* \return Current value of the property
*
* \throw PropertyNotFound \a property is not a property of the object
* \throw ForbiddenRead \a property is not readable
*/
Value get(const std::string& property) const;
/**
* \brief Set the value of an object's property
*
* This function is defined for convenience, it is a shortcut
* for <tt>object.getClass().property(name).set(object, value);</tt>
*
* \param property Name of the property to set
* \param value Value to set
*
* \throw PropertyNotFound \a property is not a property of the object
* \throw ForbiddenWrite \a property is not writable
* \throw BadType \a value can't be converted to the property's type
*/
void set(const std::string& property, const Value& value) const;
/**
* \brief Call an object's function
*
* This function is defined for convenience, it is a shortcut
* for <tt>object.getClass().function(name).call(object, args);</tt>
*
* \param function Name of the function to call
* \param args Arguments to pass to the function
*
* \return Value returned by the function
*
* \throw FunctionNotFound \a function is not a function of the object class
* \throw ForbiddenCall \a function is not callable
* \throw NotEnoughArguments too few arguments are provided
* \throw BadArgument one of the arguments can't be converted to the requested type
*/
Value call(const std::string& function, const Args& args = Args::empty) const;
/**
* \brief Assignment operator
*
* \param other User object to assign
*
* \return Reference to this
*/
UserObject& operator=(const UserObject& other);
/**
* \brief Operator == to compare equality between two user objects
*
* Two user objects are equal if their metaclasses and pointers are both equal
*
* \param other User object to compare with this
*
* \return True if both user objects are the same, false otherwise
*/
bool operator==(const UserObject& other) const;
/**
* \brief Operator < to compare two user objects
*
* \param other User object to compare with this
*
* \return True if this < other
*/
bool operator<(const UserObject& other) const;
public:
/**
* \brief Special UserObject instance representing an empty object
*/
static const UserObject nothing;
/**
* \brief Construct a user object from a reference to an object
*
* This functions is equivalent to calling UserObject(object).
*
* \param object Instance to store in the user object
*
* \return UserObject containing a reference to \a object
*/
template <typename T>
static UserObject ref(T& object);
/**
* \brief Construct a user object from a const reference to an object
*
* This functions is NOT equivalent to calling UserObject(object).
*
* \param object Instance to store in the user object
*
* \return UserObject containing a const reference to \a object
*/
template <typename T>
static UserObject ref(const T& object);
/**
* \brief Construct a user object with a copy of an object
*
* This functions is NOT equivalent to calling UserObject(object).
*
* \param object Instance to store in the user object
*
* \return UserObject containing a copy of \a object
*/
template <typename T>
static UserObject copy(const T& object);
private:
friend class Property;
/**
* \brief Assign a new value to a property of the object
*
* This functions is meant to be used only by Property, and
* is needed for proper propagation of the modification to the
* parent objects.
*
* \param property Property to modify
* \param value New value to assign
*/
void set(const Property& property, const Value& value) const;
/**
* \brief Recursively set a property
*
* See the description of UserObject::set(property, value).
*
* \param object Object to modify
* \param property Property to set when the recursion is over
* \param value Value to assign when the recursion is over
*/
void cascadeSet(const UserObject& object, const Property& property, const Value& value) const;
private:
const Class* m_class; ///< Metaclass of the stored object
boost::shared_ptr<detail::AbstractObjectHolder> m_holder; ///< Optional abstract holder storing the object
boost::scoped_ptr<ParentObject> m_parent; ///< Optional parent object
const UserObject* m_child; ///< Optional pointer to the child object (m_parent.object.m_child == this)
};
/**
* \brief Structure holding the informations about a parent object
*
* A parent object is composed of a <object, property> pair.
*/
class ParentObject : boost::noncopyable
{
public:
/**
* \brief Default constructor
*/
ParentObject(const UserObject& obj, const UserProperty& mem) : object(obj), member(mem) {}
UserObject object; ///< Parent object
const UserProperty& member; ///< Member of the parent giving access to the child object
UserObject lastValue; ///< Last value of the object (stored here for persistency)
};
} // namespace camp
#include <camp/userobject.inl>
#endif // CAMP_USEROBJECT_HPP
|