//------------------------------------------------------------------------------------------------- Value Function::call(const UserObject& object, const Args& args) const { // Check if the function is callable if (!callable(object)) CAMP_ERROR(ForbiddenCall(name())); // Check the number of arguments if (args.count() < m_argTypes.size()) CAMP_ERROR(NotEnoughArguments(name(), args.count(), m_argTypes.size())); // Execute the function return execute(object, args); }
//------------------------------------------------------------------------------------------------- std::size_t DictionaryProperty::size(const UserObject& object) const { // Check if the property is readable if (!readable(object)) CAMP_ERROR(ForbiddenRead(name())); return getSize(object); }
//------------------------------------------------------------------------------------------------- TypeInfo Function::argTypeInfo(std::size_t index) const { // Make sure that the index is not out of range if (index >= m_argTypeInfo.size()) CAMP_ERROR(OutOfRange(index, m_argTypeInfo.size())); return m_argTypeInfo[index]; }
//------------------------------------------------------------------------------------------------- bool DictionaryProperty::exists(const UserObject& object, const camp::Value& key) const { // Check if the property is readable if (!readable(object)) CAMP_ERROR(ForbiddenRead(name())); return queryExists(object,key); }
//------------------------------------------------------------------------------------------------- Type Constructor::argType(std::size_t index) const { // Make sure that the index is not out of range if (index >= m_argTypes.size()) CAMP_ERROR(OutOfRange(index, m_argTypes.size())); return m_argTypes[index]; }
//------------------------------------------------------------------------------------------------- const Class& ClassManager::getByIndex(std::size_t index) const { // Make sure that the index is not out of range if (index >= m_classes.size()) CAMP_ERROR(OutOfRange(index, m_classes.size())); return *m_classes[index].classPtr; }
//------------------------------------------------------------------------------------------------- Value DictionaryProperty::get(const UserObject& object, const camp::Value& key) const { // Check if element exists if(!exists(object, key)) CAMP_ERROR(ElementNotFound()); return getElement(object, key); }
//------------------------------------------------------------------------------------------------- DictionaryIteratorPtr DictionaryProperty::iterator(const UserObject& object) const { // Check if the property is readable if (!readable(object)) CAMP_ERROR(ForbiddenRead(name())); return getIterator(object); }
//------------------------------------------------------------------------------------------------- const Constructor& Class::constructor(std::size_t index) const { // Make sure that the index is not out of range if (index >= m_constructors.size()) CAMP_ERROR(OutOfRange(index, m_constructors.size())); return *m_constructors[index]; }
//------------------------------------------------------------------------------------------------- const Class& Class::base(std::size_t index) const { // Make sure that the index is not out of range if (index >= m_bases.size()) CAMP_ERROR(OutOfRange(index, m_bases.size())); return *m_bases[index].base; }
//------------------------------------------------------------------------------------------------- const Function& Class::getOperator(std::size_t index) const { // Make sure that the index is not out of range if (index >= m_operators.size()) CAMP_ERROR(OutOfRange(index, m_operators.size())); return *m_operators[index]; }
//------------------------------------------------------------------------------------------------- const Enum& EnumManager::getByName(const std::string& name) const { const NameIndex& names = m_enums.get<Name>(); NameIndex::const_iterator it = names.find(name); if (it == names.end()) CAMP_ERROR(EnumNotFound(name)); return *it->enumPtr; }
//------------------------------------------------------------------------------------------------- const Enum& EnumManager::getById(const std::string& id) const { const IdIndex& ids = m_enums.get<Id>(); IdIndex::const_iterator it = ids.find(id); if (it == ids.end()) CAMP_ERROR(EnumNotFound(id)); return *it->enumPtr; }
//------------------------------------------------------------------------------------------------- const Function& Class::function(std::size_t index, bool ownOnly /*= false*/) const { const FunctionTable& table = ownOnly?m_own_functions:m_functions; // Make sure that the index is not out of range if (index >= table.size()) CAMP_ERROR(OutOfRange(index, table.size())); return *table[index]; }
//------------------------------------------------------------------------------------------------- const Class& ClassManager::getByName(const std::string& name) const { const NameIndex& names = m_classes.get<Name>(); NameIndex::const_iterator it = names.find(name); if (it == names.end()) CAMP_ERROR(ClassNotFound(name)); return *it->classPtr; }
//------------------------------------------------------------------------------------------------- const Property& Class::property(const std::string& name, bool ownOnly /*= false*/) const { const PropertyNameIndex& names = (ownOnly?m_own_properties:m_properties).get<Name>(); PropertyNameIndex::const_iterator it = names.find(name); if (it == names.end()) CAMP_ERROR(PropertyNotFound(name, m_name)); return **it; }
//------------------------------------------------------------------------------------------------- const Function& Class::getUnaryOperator(OperatorType operatorType) const { const LookupOperatorIndex& operators = m_operators.get<OperatorLookup>(); LookupOperatorIndex::const_iterator it = operators.find(operatorType); if (it == operators.end()) CAMP_ERROR(OperatorNotFound(operatorType, m_name)); return **it; }
//------------------------------------------------------------------------------------------------- const Property& Class::property(std::size_t index, bool ownOnly /*= false*/) const { const PropertyTable& table = ownOnly?m_own_properties:m_properties; // Make sure that the index is not out of range if (index >= table.size()) CAMP_ERROR(OutOfRange(index, table.size())); return *table[index]; }
//------------------------------------------------------------------------------------------------- const Function& Class::getOperator(OperatorType operatorType, TypeInfo argType) const { const UniqueOperatorIndex& operators = m_operators.get<OperatorUnique>(); UniqueOperatorIndex::const_iterator it = operators.find(boost::make_tuple(operatorType, argType)); if (it == operators.end()) CAMP_ERROR(OperatorNotFound(operatorType, argType, m_name)); return **it; }
//------------------------------------------------------------------------------------------------- const Class& ClassManager::getById(const std::string& id) const { const IdIndex& ids = m_classes.get<Id>(); IdIndex::const_iterator it = ids.find(id); if (it == ids.end()) CAMP_ERROR(ClassNotFound(id)); return *it->classPtr; }
//------------------------------------------------------------------------------------------------- const Function& Class::function(const std::string& name, bool ownOnly /*= false*/) const { const FunctionNameIndex& names = (ownOnly?m_own_functions:m_functions).get<Name>(); FunctionNameIndex::const_iterator it = names.find(name); if (it == names.end()) CAMP_ERROR(FunctionNotFound(name, m_name)); return **it; }
//------------------------------------------------------------------------------------------------- const Class& ClassManager::getByIndex(std::size_t index) const { // Make sure that the index is not out of range if (index >= m_classes.size()) CAMP_ERROR(OutOfRange(index, m_classes.size())); ClassTable::const_iterator it = m_classes.begin(); std::advance(it, index); return *it->classPtr; }
//------------------------------------------------------------------------------------------------- const Enum& EnumManager::getByIndex(std::size_t index) const { // Make sure that the index is not out of range if (index >= m_enums.size()) CAMP_ERROR(OutOfRange(index, m_enums.size())); EnumTable::const_iterator it = m_enums.begin(); std::advance(it, index); return *it->enumPtr; }
inline typename boost::remove_reference<T>::type convertArg(const Args& args, std::size_t index) { try { return args[index].to<typename boost::remove_reference<T>::type>(); } catch (BadType&) { CAMP_ERROR(BadArgument(args[index].type(), mapType<T>(), index, "constructor")); } }
//------------------------------------------------------------------------------------------------- const Class& UserObject::getClass() const { if (m_class) { return *m_class; } else { CAMP_ERROR(NullObject(m_class)); } }
//------------------------------------------------------------------------------------------------- void DictionaryProperty::set(const UserObject& object, const camp::Value& key, const Value& value) const { // Check if the property is writable if (!writable(object)) { m_setted_nonwritable_signal(object, *this, key, value); CAMP_ERROR(ForbiddenWrite(name())); } // Signal before setting the value so slots can throw an exception to prevent setting. m_setted_signal(object, *this, key, value); return setElement(object, key, value); }
//------------------------------------------------------------------------------------------------- void DictionaryProperty::remove(const UserObject& object, const camp::Value& key) const { // Check if element exists if(!exists(object, key)) { m_removed_nonwritable_signal(object, *this, key); CAMP_ERROR(ElementNotFound()); } // Signal before removing the value so slots can throw an exception to prevent removal. m_removed_signal(object, *this, key); return removeElement(object, key); }
//------------------------------------------------------------------------------------------------- const Class& ClassManager::getById(StringId id) const { SortedClassVector::const_iterator iterator = std::lower_bound(m_classes.cbegin(), m_classes.cend(), id, OrderByClassId()); if (iterator != m_classes.end() && iterator->id == id) { // Found return *iterator->classPtr; } else { // Not found CAMP_ERROR(ClassNotFound(id)); } }
//------------------------------------------------------------------------------------------------- void* Class::applyOffset(void* pointer, const Class& target) const { // Special case for null pointers: don't apply offset to leave them null if (!pointer) return pointer; // Check target as a base class of this int offset = baseOffset(target); if (offset != -1) return static_cast<void*>(static_cast<char*>(pointer) + offset); // Check target as a derived class of this offset = target.baseOffset(*this); if (offset != -1) return static_cast<void*>(static_cast<char*>(pointer) - offset); // No match found, target is not a base class nor a derived class of this CAMP_ERROR(ClassUnrelated(name(), target.name())); }
//------------------------------------------------------------------------------------------------- Class& ClassManager::addClass(StringId id, const char* name) { // First make sure that the class doesn't already exist SortedClassVector::const_iterator iterator = std::lower_bound(m_classes.cbegin(), m_classes.cend(), id, OrderByClassId()); if (iterator != m_classes.end() && iterator->id == id) { CAMP_ERROR(ClassAlreadyCreated(name)); } // Create the new class Class* newClass = new Class(id, name); // Insert it into the sorted vector m_classes.emplace(iterator, ClassEntry(id, newClass)); // Notify observers notifyClassAdded(*newClass); // Done return *newClass; }