Add macro for validators static get function
The static Get function in the validator classes was a code
duplicate. It has been extracted into a macro which can then
by used by the different validator classes.
Change-Id: I13d5f33a930f58f5b7a73371d79a184603e2e03c
git-svn-id: https://svn.apache.org/repos/asf/etch/trunk@1679582 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/binding-cpp/runtime/include/serialization/EtchValidator.h b/binding-cpp/runtime/include/serialization/EtchValidator.h
index f9a6016..a1066d6 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidator.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidator.h
@@ -44,6 +44,30 @@
return SValidatorCache##validatorClassName.get(runtime); \
}
+#define VALIDATOR_GET_DEF() \
+ static status_t Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
+
+
+#define VALIDATOR_GET_IMPL(validatorClassName) \
+ status_t validatorClassName::Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) { \
+ \
+ \
+ if (ndim > MAX_NDIMS) { \
+ return ETCH_EINVAL; \
+ } \
+ if (ndim >= MAX_CACHED) { \
+ val = new validatorClassName(runtime, ndim); \
+ return ETCH_OK; \
+ } \
+ if (Validators(runtime)[ndim].get() == NULL) { \
+ Validators(runtime)[ndim] = new validatorClassName(runtime, ndim); \
+ runtime->registerListener(&SRuntimeChangedListener); \
+ ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "##validatorClassName has been created"); \
+ } \
+ val = Validators(runtime)[ndim]; \
+ return ETCH_OK; \
+}
+
#include "common/EtchObject.h"
#include "support/EtchRuntime.h"