/usr/include/camp/classbuilder.inl 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 | /****************************************************************************
**
** 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/>.
**
****************************************************************************/
namespace camp
{
//-------------------------------------------------------------------------------------------------
template <typename T>
ClassBuilder<T>::ClassBuilder(Class& target)
: m_target(&target)
, m_currentTagHolder(m_target)
, m_currentProperty(0)
, m_currentFunction(0)
{
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename U>
ClassBuilder<T>& ClassBuilder<T>::base()
{
// Retrieve the base metaclass and its name
const Class& baseClass = classByType<U>();
std::string baseName = baseClass.name();
// First make sure that the base class is not already a base of the current class
Class::BaseList::const_iterator endBase = m_target->m_bases.end();
for (Class::BaseList::const_iterator it = m_target->m_bases.begin(); it != endBase; ++it)
{
assert(it->base->name() != baseName);
}
// Compute the offset to apply for pointer conversions
T* asDerived = reinterpret_cast<T*>(1);
U* asBase = static_cast<U*>(asDerived);
int offset = static_cast<int>(reinterpret_cast<char*>(asBase) - reinterpret_cast<char*>(asDerived));
// Add the base metaclass to the bases of the current class
Class::BaseInfo baseInfos;
baseInfos.base = &baseClass;
baseInfos.offset = offset;
m_target->m_bases.push_back(baseInfos);
// Copy all properties of the base class into the current class
for (Class::PropertyTable::const_iterator it = baseClass.m_properties.begin();
it != baseClass.m_properties.end();
++it)
{
m_target->m_properties.push_back(*it);
}
// Copy all functions of the base class into the current class
for (Class::FunctionTable::const_iterator it = baseClass.m_functions.begin();
it != baseClass.m_functions.end();
++it)
{
m_target->m_functions.push_back(*it);
}
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename F>
ClassBuilder<T>& ClassBuilder<T>::property(const std::string& name, F accessor)
{
// Find the factory which will be able to construct a camp::Property from an accessor of type F
typedef detail::PropertyFactory1<T, F> Factory;
// Construct and add the metaproperty
return addProperty(Factory::get(name, accessor));
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename F1, typename F2>
ClassBuilder<T>& ClassBuilder<T>::property(const std::string& name, F1 accessor1, F2 accessor2)
{
// Find the factory which will be able to construct a camp::Property from accessors of type F1 and F2
typedef detail::PropertyFactory2<T, F1, F2> Factory;
// Construct and add the metaproperty
return addProperty(Factory::get(name, accessor1, accessor2));
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename F1, typename F2, typename F3>
ClassBuilder<T>& ClassBuilder<T>::property(const std::string& name, F1 accessor1, F2 accessor2, F3 accessor3)
{
// Find the factory which will be able to construct a camp::Property from accessors of type F1, F2 and F3
typedef detail::PropertyFactory3<T, F1, F2, F3> Factory;
// Construct and add the metaproperty
return addProperty(Factory::get(name, accessor1, accessor2, accessor3));
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename F>
ClassBuilder<T>& ClassBuilder<T>::function(const std::string& name, F function)
{
// Get a uniform function type from F, whatever it really is
typedef typename boost::function_types::function_type<F>::type Signature;
// Construct and add the metafunction
return addFunction(new detail::FunctionImpl<Signature>(name, function));
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename F>
ClassBuilder<T>& ClassBuilder<T>::function(const std::string& name, boost::function<F> function)
{
return addFunction(new detail::FunctionImpl<F>(name, function));
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename F1, typename F2>
ClassBuilder<T>& ClassBuilder<T>::function(const std::string& name, F1 function1, F2 function2)
{
// Get uniform function types from F1 and F2, whatever they really are
typedef typename boost::function_types::function_type<F1>::type Signature1;
typedef typename boost::function_types::function_type<F2>::type Signature2;
// Construct and add the metafunction
return addFunction(new detail::FunctionImpl<Signature1, Signature2>(name, function1, function2));
}
//-------------------------------------------------------------------------------------------------
template <typename T>
ClassBuilder<T>& ClassBuilder<T>::tag(const Value& id)
{
return tag(id, Value::nothing);
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename U>
ClassBuilder<T>& ClassBuilder<T>::tag(const Value& id, const U& value)
{
// Make sure we have a valid tag holder, and the tag doesn't already exists
assert(m_currentTagHolder && !m_currentTagHolder->hasTag(id));
// For the special case of Getter<Value>, the ambiguity between both constructors
// cannot be automatically solved, so let's do it manually
typedef typename boost::mpl::if_c<detail::FunctionTraits<U>::isFunction, boost::function<Value (T&)>, Value>::type Type;
// Add the new tag (override if already exists)
m_currentTagHolder->m_tags[id] = detail::Getter<Value>(Type(value));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
ClassBuilder<T>& ClassBuilder<T>::readable(bool value)
{
// Make sure we have a valid property
assert(m_currentProperty != 0);
m_currentProperty->m_readable = detail::Getter<bool>(value);
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename F>
ClassBuilder<T>& ClassBuilder<T>::readable(F function)
{
// Make sure we have a valid property
assert(m_currentProperty != 0);
m_currentProperty->m_readable = detail::Getter<bool>(boost::function<bool (T&)>(function));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
ClassBuilder<T>& ClassBuilder<T>::writable(bool value)
{
// Make sure we have a valid property
assert(m_currentProperty != 0);
m_currentProperty->m_writable = detail::Getter<bool>(value);
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename F>
ClassBuilder<T>& ClassBuilder<T>::writable(F function)
{
// Make sure we have a valid property
assert(m_currentProperty != 0);
m_currentProperty->m_writable = detail::Getter<bool>(boost::function<bool (T&)>(function));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
ClassBuilder<T>& ClassBuilder<T>::callable(bool value)
{
// Make sure we have a valid function
assert(m_currentFunction != 0);
m_currentFunction->m_callable = detail::Getter<bool>(value);
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename F>
ClassBuilder<T>& ClassBuilder<T>::callable(F function)
{
// Make sure we have a valid function
assert(m_currentFunction != 0);
m_currentFunction->m_callable = detail::Getter<bool>(boost::function<bool (T&)>(function));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
ClassBuilder<T>& ClassBuilder<T>::constructor0()
{
Constructor* constructor = new detail::ConstructorImpl0<T>;
m_target->m_constructors.push_back(Class::ConstructorPtr(constructor));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename A0>
ClassBuilder<T>& ClassBuilder<T>::constructor1()
{
Constructor* constructor = new detail::ConstructorImpl1<T, A0>;
m_target->m_constructors.push_back(Class::ConstructorPtr(constructor));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename A0, typename A1>
ClassBuilder<T>& ClassBuilder<T>::constructor2()
{
Constructor* constructor = new detail::ConstructorImpl2<T, A0, A1>;
m_target->m_constructors.push_back(Class::ConstructorPtr(constructor));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename A0, typename A1, typename A2>
ClassBuilder<T>& ClassBuilder<T>::constructor3()
{
Constructor* constructor = new detail::ConstructorImpl3<T, A0, A1, A2>;
m_target->m_constructors.push_back(Class::ConstructorPtr(constructor));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename A0, typename A1, typename A2, typename A3>
ClassBuilder<T>& ClassBuilder<T>::constructor4()
{
Constructor* constructor = new detail::ConstructorImpl4<T, A0, A1, A2, A3>;
m_target->m_constructors.push_back(Class::ConstructorPtr(constructor));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <typename A0, typename A1, typename A2, typename A3, typename A4>
ClassBuilder<T>& ClassBuilder<T>::constructor5()
{
Constructor* constructor = new detail::ConstructorImpl5<T, A0, A1, A2, A3, A4>;
m_target->m_constructors.push_back(Class::ConstructorPtr(constructor));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
template <template <typename> class U>
ClassBuilder<T>& ClassBuilder<T>::external()
{
// Create an instance of the mapper
U<T> mapper;
// Retrieve the properties
std::size_t propertyCount = mapper.propertyCount();
for (std::size_t i = 0; i < propertyCount; ++i)
addProperty(mapper.property(i));
// Retrieve the functions
std::size_t functionCount = mapper.functionCount();
for (std::size_t i = 0; i < functionCount; ++i)
addFunction(mapper.function(i));
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
ClassBuilder<T>& ClassBuilder<T>::addProperty(Property* property)
{
// Retrieve the class' properties indexed by name
Class::PropertyNameIndex& properties = m_target->m_properties.get<Class::Name>();
// First remove any property that already exists with the same name
properties.erase(property->name());
// Insert the new property
properties.insert(Class::PropertyPtr(property));
m_currentTagHolder = m_currentProperty = property;
m_currentFunction = 0;
return *this;
}
//-------------------------------------------------------------------------------------------------
template <typename T>
ClassBuilder<T>& ClassBuilder<T>::addFunction(Function* function)
{
// Retrieve the class' functions indexed by name
Class::FunctionNameIndex& functions = m_target->m_functions.get<Class::Name>();
// First remove any function that already exists with the same name
functions.erase(function->name());
// Insert the new function
functions.insert(Class::FunctionPtr(function));
m_currentTagHolder = m_currentFunction = function;
m_currentProperty = 0;
return *this;
}
} // namespace camp
|