Example #1
0
//-------------------------------------------------------------------------------------------------
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);
}
Example #2
0
//-------------------------------------------------------------------------------------------------
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);
}
Example #3
0
//-------------------------------------------------------------------------------------------------
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];
}
Example #4
0
//-------------------------------------------------------------------------------------------------
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);
}
Example #5
0
//-------------------------------------------------------------------------------------------------
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];
}
Example #6
0
//-------------------------------------------------------------------------------------------------
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;
}
Example #7
0
//-------------------------------------------------------------------------------------------------
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);
}
Example #8
0
//-------------------------------------------------------------------------------------------------
DictionaryIteratorPtr DictionaryProperty::iterator(const UserObject& object) const
{
    // Check if the property is readable
    if (!readable(object))
        CAMP_ERROR(ForbiddenRead(name()));

    return getIterator(object);
}
Example #9
0
//-------------------------------------------------------------------------------------------------
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];
}
Example #10
0
//-------------------------------------------------------------------------------------------------
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;
}
Example #11
0
File: class.cpp Project: Gohla/camp
//-------------------------------------------------------------------------------------------------
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];
}
Example #12
0
//-------------------------------------------------------------------------------------------------
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;
}
Example #13
0
//-------------------------------------------------------------------------------------------------
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;
}
Example #14
0
//-------------------------------------------------------------------------------------------------
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];
}
Example #15
0
//-------------------------------------------------------------------------------------------------
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;
}
Example #16
0
//-------------------------------------------------------------------------------------------------
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;
}
Example #17
0
File: class.cpp Project: Gohla/camp
//-------------------------------------------------------------------------------------------------
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;
}
Example #18
0
//-------------------------------------------------------------------------------------------------
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];
}
Example #19
0
File: class.cpp Project: Gohla/camp
//-------------------------------------------------------------------------------------------------
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;
}
Example #20
0
//-------------------------------------------------------------------------------------------------
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;
}
Example #21
0
//-------------------------------------------------------------------------------------------------
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;
}
Example #22
0
//-------------------------------------------------------------------------------------------------
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;
}
Example #23
0
//-------------------------------------------------------------------------------------------------
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;
}
Example #24
0
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"));
    }
}
Example #25
0
//-------------------------------------------------------------------------------------------------
const Class& UserObject::getClass() const
{
    if (m_class)
    {
        return *m_class;
    }
    else
    {
        CAMP_ERROR(NullObject(m_class));
    }
}
Example #26
0
//-------------------------------------------------------------------------------------------------
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);
}
Example #27
0
//-------------------------------------------------------------------------------------------------
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);
}
Example #28
0
//-------------------------------------------------------------------------------------------------
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));
    }
}
Example #29
0
//-------------------------------------------------------------------------------------------------
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()));
}
Example #30
0
//-------------------------------------------------------------------------------------------------
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;
}