/usr/include/camp/classbuilder.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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | /****************************************************************************
**
** 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_CLASSBUILDER_HPP
#define CAMP_CLASSBUILDER_HPP
#include <camp/type.hpp>
#include <camp/classget.hpp>
#include <camp/detail/functionimpl.hpp>
#include <camp/detail/functiontraits.hpp>
#include <camp/detail/constructorimpl.hpp>
#include <camp/detail/propertyfactory.hpp>
#ifndef Q_MOC_RUN
#include <boost/noncopyable.hpp>
#include <boost/mpl/if.hpp>
#include <boost/function_types/function_type.hpp>
#endif
#include <cassert>
#include <string>
namespace camp
{
/**
* \brief Proxy class which fills a metaclass with its members
*
* This class is returned by Class::declare<T> in order construct a
* new metaclass. It contains functions to declare and bind metaproperties,
* metafunctions, base metaclasses, metaconstructors, etc. with many overloads
* in order to accept as many types of binds as possible.
*
* ClassBuilder also contains functions to set attributes of metafunctions
* and metaproperties.
*
* This class should never be explicitely instanciated, unless you
* need to split the metaclass creation in multiple parts.
*/
template <typename T>
class ClassBuilder
{
public:
/**
* \brief Construct the builder with a target metaclass to fill
*
* \param target Metaclass to build
*/
ClassBuilder(Class& target);
/**
* \brief Declare a base metaclass
*
* The template parameter U is the C++ base class of T.
*
* This function makes the target metaclass inherit of all the metaproperties and
* metafunctions of the given base metaclass.
*
* \return Reference to this, in order to chain other calls
*
* \throw ClassNotFound no metaclass is bound to U
*/
template <typename U>
ClassBuilder<T>& base();
/**
* \brief Declare a new property from a single accessor
*
* The accessor argument can be a getter of any valid type, or a direct
* pointer-to-member (which is considered both a getter and a setter)
*
* Example:
*
* \code
* struct Point
* {
* float x;
* float y;
*
* float length() const;
* };
*
* camp::Class::declare<Point>("Point")
* .property("x", &Point::x); // getter + setter
* .property("y", &Point::y); // getter + setter
* .property("length", &Point::length); // getter only
* \endcode
* \param name Name of the property (must be unique within the metaclass)
* \param accessor Accessor to the C++ implementation of the property
*
* \return Reference to this, in order to chain other calls
*/
template <typename F>
ClassBuilder<T>& property(const std::string& name, F accessor);
/**
* \brief Declare a new property from a pair of accessors
*
* The accessor1 and accessor2 arguments can be a pair of getter/setter, or
* two getters which must be composed to form a single getter.
* If F1 is a direct pointer-to-member, it is considered both a getter and a setter.
*
* Having two getters allows to expose a property which requires an extra level of indirection to be accessed
* (for example, a property of a member of the class instead of a property of the class itself).
*
* Example:
*
* \code
* struct Point {float x, y;};
*
* class Entity
* {
* public:
*
* Point p;
* };
*
* camp::Class::declare<Entity>("Entity")
* .property("x", &Point::x, &Entity::p); // will internally resolve to e.p.x
* .property("y", &Point::y, &Entity::p); // will internally resolve to e.p.y
* \endcode
*
* \param name Name of the property (must be unique within the metaclass)
* \param accessor1 First accessor to the C++ implementation of the property (getter)
* \param accessor2 Second accessor to the C++ implementation of the property (setter or getter to compose)
*
* \return Reference to this, in order to chain other calls
*/
template <typename F1, typename F2>
ClassBuilder<T>& property(const std::string& name, F1 accessor1, F2 accessor2);
/**
* \brief Declare a new property from three accessors
*
* The accessor1 and accessor2 arguments are a pair of getter/setter, accessor3 is
* an accessor to compose to accessor1 and accessor2 to get the final accessors.
*
* This allows to expose a property which requires an extra level of indirection to be accessed
* (for example, a property of a member of the class instead of a property of the class itself).
*
* Example:
*
* \code
* struct Point
* {
* float getX() const;
* void setX(float);
*
* float getY() const;
* void setY(float);
* };
*
* class Entity
* {
* public:
*
* Point p;
* };
*
* camp::Class::declare<Entity>("Entity")
* .property("x", &Point::getX, &Point::setX, &Entity::p); // will internally resolve to e.p.get/setX()
* .property("y", &Point::getY, &Point::setY, &Entity::p); // will internally resolve to e.p.get/setY()
* \endcode
*
* \param name Name of the property (must be unique within the metaclass)
* \param accessor1 First accessor (getter)
* \param accessor2 Second accessor (setter)
* \param accessor3 Third accessor (getter)
*
* \return Reference to this, in order to chain other calls
*/
template <typename F1, typename F2, typename F3>
ClassBuilder<T>& property(const std::string& name, F1 accessor1, F2 accessor2, F3 accessor3);
/**
* \brief Declare a new function from any bindable type
*
* The function argument can be any valid type: a non-member function,
* a member function, const, non-const, etc.
*
* \param name Name of the function (must be unique within the metaclass)
* \param function C++ callable entity to bind to the function
*
* \return Reference to this, in order to chain other calls
*/
template <typename F>
ClassBuilder<T>& function(const std::string& name, F function);
/**
* \brief Declare a new function from a boost::function
*
* Overload handling functions of type boost::function.
*
* \param name Name of the function (must be unique within the metaclass)
* \param function Instance of boost::function to bind to the function
*
* \return Reference to this, in order to chain other calls
*/
template <typename F>
ClassBuilder<T>& function(const std::string& name, boost::function<F> function);
/**
* \brief Declare a new function from two functions to compose
*
* This allows to expose a function which requires an extra level of indirection to be accessed
* (for example, a function of a member of the class instead of a function of the class itself).
*
* Example:
*
* \code
* struct Point
* {
* void move(float x, float y);
* };
*
* class Entity
* {
* public:
*
* Point p;
* };
*
* camp::Class::declare<Entity>("Entity")
* .function("move", &Point::move, &Entity::p); // will internally resolve to e.p.move()
* \endcode
*
* \param name Name of the function (must be unique within the metaclass)
* \param function1 C++ callable entity to bind to the function
* \param function2 Accessor returning the member to apply to function1
*
* \return Reference to this, in order to chain other calls
*/
template <typename F1, typename F2>
ClassBuilder<T>& function(const std::string& name, F1 function1, F2 function2);
/**
* \brief Declare a new static tag
*
* \param id Identifier of the new tag (must be unique within the metaclass)
*
* \return Reference to this, in order to chain other calls
*/
ClassBuilder<T>& tag(const Value& id);
/**
* \brief Declare a new tag with value
*
* \param id Identifier of the new tag (must be unique within the metaclass)
* \param value Value associated to the tag. It can be a static value, or a function
* which will be evaluated each time the tag will be requested
*
* \return Reference to this, in order to chain other calls
*/
template <typename U>
ClassBuilder<T>& tag(const Value& id, const U& value);
/**
* \brief Set the readable state of the current property with a static value
*
* \param value True to set the current property as readable, false otherwise
*
* \return Reference to this, in order to chain other calls
*/
ClassBuilder<T>& readable(bool value);
/**
* \brief Set the readable state of the current property with a dynamic value
*
* function can be any C++ callable type, and will be called to return the
* readable state of the property each time it is requested. This way, the readable
* state of a property can depend on metaclass instances.
*
* \param function Function to call to get the readable state of the property
*
* \return Reference to this, in order to chain other calls
*/
template <typename F>
ClassBuilder<T>& readable(F function);
/**
* \brief Set the writable state of the current property with a static value
*
* \param value True to set the current property as writable, false otherwise
*
* \return Reference to this, in order to chain other calls
*/
ClassBuilder<T>& writable(bool value);
/**
* \brief Set the writable state of the current property with a dynamic value
*
* function can be any C++ callable type, and will be called to return the
* writable state of the property each time it is requested. This way, the writable
* state of a property can depend on metaclass instances.
*
* \param function Function to call to get the writable state of the property
*
* \return Reference to this, in order to chain other calls
*/
template <typename F>
ClassBuilder<T>& writable(F function);
/**
* \brief Set the callable state of the current function with a static value
*
* \param value True to set the current function as callable, false otherwise
*
* \return Reference to this, in order to chain other calls
*/
ClassBuilder<T>& callable(bool value);
/**
* \brief Set the callable state of the current function with a dynamic value
*
* function can be any C++ callable type, and will be called to return the
* callable state of the function each time it is requested. This way, the callable
* state of a function can depend on metaclass instances.
*
* \param function Function to call to get the callable state of the function
*
* \return Reference to this, in order to chain other calls
*/
template <typename F>
ClassBuilder<T>& callable(F function);
/**
* \brief Declare a default constructor for the metaclass
*
* \return Reference to this, in order to chain other calls
*/
ClassBuilder<T>& constructor0();
/**
* \brief Declare a constructor with 1 parameter for the metaclass
*
* A0 is the type of the parameter
*
* \return Reference to this, in order to chain other calls
*/
template <typename A0>
ClassBuilder<T>& constructor1();
/**
* \brief Declare a constructor with 2 parameters for the metaclass
*
* A0 is the type of the first parameter.
* A1 is the type of the second parameter.
*
* \return Reference to this, in order to chain other calls
*/
template <typename A0, typename A1>
ClassBuilder<T>& constructor2();
/**
* \brief Declare a constructor with 3 parameters for the metaclass
*
* A0 is the type of the first parameter.
* A1 is the type of the second parameter.
* A2 is the type of the third parameter.
*
* \return Reference to this, in order to chain other calls
*/
template <typename A0, typename A1, typename A2>
ClassBuilder<T>& constructor3();
/**
* \brief Declare a constructor with 4 parameters for the metaclass
*
* A0 is the type of the first parameter.
* A1 is the type of the second parameter.
* A2 is the type of the third parameter.
* A3 is the type of the fourth parameter.
*
* \return Reference to this, in order to chain other calls
*/
template <typename A0, typename A1, typename A2, typename A3>
ClassBuilder<T>& constructor4();
/**
* \brief Declare a constructor with 5 parameters for the metaclass
*
* A0 is the type of the first parameter.
* A1 is the type of the second parameter.
* A2 is the type of the third parameter.
* A3 is the type of the fourth parameter.
* A4 is the type of the fifth parameter.
*
* \return Reference to this, in order to chain other calls
*/
template <typename A0, typename A1, typename A2, typename A3, typename A4>
ClassBuilder<T>& constructor5();
/**
* \brief Add properties and/or functions from an external source
*
* The purpose of this function is to allow the binding of classes
* that already use a similar system of metaproperties and metafunctions,
* with a direct mapping from external attributes to CAMP ones.
*
* The mapping process must be done in a specific mapper class (see below), thus avoiding
* to manually write the mapping for every class.
*
* The mapper class must accept a template parameter (which is the target C++ class)
* and be compatible with the following interface:
*
* \code
* template <typename T>
* class MyClassMapper
* {
* public:
*
* MyClassMapper();
*
* size_t propertyCount();
* camp::Property* property(size_t index);
*
* size_t functionCount();
* camp::Function* function(size_t index);
* };
* \endcode
*
* Example of usage:
*
* \code
* camp::Class::declare<MyClass>("MyClass")
* .external<MyClassMapper>()
* ...
* \endcode
*
* \return Reference to this, in order to chain other calls
*/
template <template <typename> class U>
ClassBuilder<T>& external();
private:
/**
* \brief Add a new property to the target class
*
* \param property Property to add
*
* \return Reference to this, in order to chain other calls
*/
ClassBuilder<T>& addProperty(Property* property);
/**
* \brief Add a new function to the target class
*
* \param function Function to add
*
* \return Reference to this, in order to chain other calls
*/
ClassBuilder<T>& addFunction(Function* function);
Class* m_target; ///< Target metaclass to fill
TagHolder* m_currentTagHolder; ///< Last tag holder which has been declared
Property* m_currentProperty; ///< Last metaproperty which has been declared
Function* m_currentFunction; ///< Last function which has been declared
};
} // namespace camp
#include <camp/classbuilder.inl>
#endif // CAMP_CLASSBUILDER_HPP
|