#include "base/workqueue.hpp"
#include "base/context.hpp"
#include "base/application.hpp"
+#include "config/configitem.hpp"
#include <fstream>
#include <boost/foreach.hpp>
#include <boost/exception/errinfo_api_function.hpp>
extensions->Remove(key);
}
+class ModAttrValidationUtils : public ValidationUtils
+{
+public:
+ virtual bool ValidateName(const String& type, const String& name) const override
+ {
+ DynamicType::Ptr dtype = DynamicType::GetByName(type);
+
+ if (!dtype)
+ return false;
+
+ if (!dtype->GetObject(name))
+ return false;
+
+ return true;
+ }
+};
+
void DynamicObject::ModifyAttribute(const String& attr, const Value& value)
{
Dictionary::Ptr original_attributes = GetOriginalAttributes();
}
}
- //TODO: validation, vars.os
+ ModAttrValidationUtils utils;
+ ValidateField(fid, value, utils);
+
+ //TODO: vars.os
SetField(fid, value);
if (updated_original_attributes)
Dictionary::Ptr currentHint = vex->GetDebugHint();
Array::Ptr messages;
- BOOST_FOREACH(const String& attr, vex->GetAttributePath()) {
- Dictionary::Ptr props = currentHint->Get("properties");
+ if (currentHint) {
+ BOOST_FOREACH(const String& attr, vex->GetAttributePath()) {
+ Dictionary::Ptr props = currentHint->Get("properties");
- if (!props)
- break;
+ if (!props)
+ break;
- currentHint = props->Get(attr);
+ currentHint = props->Get(attr);
- if (!currentHint)
- break;
+ if (!currentHint)
+ break;
- messages = currentHint->Get("messages");
+ messages = currentHint->Get("messages");
+ }
}
if (messages && messages->GetLength() > 0) {
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
}
+void Object::ValidateField(int id, const Value& value, const ValidationUtils& utils)
+{
+ /* Nothing to do here. */
+}
+
void Object::NotifyField(int id, const Value& cookie)
{
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
-}
\ No newline at end of file
+}
class Object;
class Type;
class String;
+class ValidationUtils;
extern I2_BASE_API Value Empty;
virtual void SetField(int id, const Value& value, bool suppress_events = false, const Value& cookie = Empty);
virtual Value GetField(int id) const;
+ virtual void ValidateField(int id, const Value& value, const ValidationUtils& utils);
virtual void NotifyField(int id, const Value& cookie = Empty);
#ifdef I2_DEBUG
m_Impl << "}" << std::endl << std::endl;
+ /* ValidateField */
+ m_Header << "protected:" << std::endl
+ << "\t" << "virtual void ValidateField(int id, const Value& value, const ValidationUtils& utils);" << std::endl;
+
+ m_Impl << "void ObjectImpl<" << klass.Name << ">::ValidateField(int id, const Value& value, const ValidationUtils& utils)" << std::endl
+ << "{" << std::endl;
+
+ if (!klass.Parent.empty())
+ m_Impl << "\t" << "int real_id = id - " << klass.Parent << "::TypeInstance->GetFieldCount(); " << std::endl
+ << "\t" << "if (real_id < 0) { " << klass.Parent << "::ValidateField(id, value, utils); return; }" << std::endl;
+
+ m_Impl << "\t" << "switch (";
+
+ if (!klass.Parent.empty())
+ m_Impl << "real_id";
+ else
+ m_Impl << "id";
+
+ m_Impl << ") {" << std::endl;
+
+ num = 0;
+ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ m_Impl << "\t\t" << "case " << num << ":" << std::endl
+ << "\t\t\t" << "Validate" << it->GetFriendlyName() << "(";
+
+ if (it->Attributes & FAEnum)
+ m_Impl << "static_cast<" << it->Type.GetRealType() << ">(static_cast<int>(";
+
+ m_Impl << "value";
+
+ if (it->Attributes & FAEnum)
+ m_Impl << "))";
+
+ m_Impl << ", utils);" << std::endl
+ << "\t\t\t" << "break;" << std::endl;
+ num++;
+ }
+
+ m_Impl << "\t\t" << "default:" << std::endl
+ << "\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl
+ << "\t" << "}" << std::endl;
+
+ m_Impl << "}" << std::endl << std::endl;
+
/* NotifyField */
m_Header << "protected:" << std::endl
<< "\t" << "virtual void NotifyField(int id, const Value& cookie = Empty);" << std::endl;