Author: veithm
Date: Fri May 15 15:01:36 2015
New Revision: 1679581
URL: http://svn.apache.org/r1679581
Log:
Add macro for validator cache implementation
Most of the validators use a cache. This cache looks the same in
all of the validator classes. In preparation of reduce these code
duplications a macro gets added to the validator base class which
can be used by the derived validator classes.
Change-Id: I5fe8a897f9b36e2a620e657bdd37ae0ea8b62c4c
Modified:
etch/trunk/binding-cpp/runtime/include/serialization/EtchValidator.h
Modified: etch/trunk/binding-cpp/runtime/include/serialization/EtchValidator.h
URL:
http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidator.h?rev=1679581&r1=1679580&r2=1679581&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/include/serialization/EtchValidator.h
(original)
+++ etch/trunk/binding-cpp/runtime/include/serialization/EtchValidator.h Fri
May 15 15:01:36 2015
@@ -19,6 +19,31 @@
#ifndef __ETCHVALIDATOR_H__
#define __ETCHVALIDATOR_H__
+ #define VALIDATOR_CACHE_DEF()
\
+ static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+
+#define VALIDATOR_CACHE_IMPL(validatorClassName)
\
+ static EtchValidatorCaches SValidatorCache##validatorClassName;
\
+
\
+class EtchValidatorStringRuntimeListener : public EtchRuntimeListener {
\
+ status_t onRuntimeChanged(EtchRuntime* runtime) {
\
+ if (runtime == NULL) {
\
+ return ETCH_ERROR;
\
+ }
\
+ if (runtime->isClosed()) {
\
+ SValidatorCache##validatorClassName.clearCache();
\
+ runtime->unregisterListener(this);
\
+ }
\
+ return ETCH_OK;
\
+ }
\
+};
\
+
\
+ static EtchValidatorStringRuntimeListener SRuntimeChangedListener;
\
+
\
+ capu::SmartPointer<EtchValidator>*
validatorClassName::Validators(EtchRuntime* runtime) { \
+ return SValidatorCache##validatorClassName.get(runtime);
\
+}
+
#include "common/EtchObject.h"
#include "support/EtchRuntime.h"
@@ -102,19 +127,23 @@ public:
* Destructor
*/
virtual ~EtchValidatorCaches() {
- capu::List<ValidatorCache*>::Iterator iter = mValidatorsCache.begin();
- while(iter != mValidatorsCache.end()) {
- ValidatorCache* entry = *iter;
- iter++;
- delete entry;
- }
- mValidatorsCache.clear();
+ clearCache();
}
status_t onRuntimeChanged(EtchRuntime* runtime) {
return ETCH_OK;
}
+ void clearCache() {
+ capu::List<ValidatorCache*>::Iterator iter = mValidatorsCache.begin();
+ while(iter != mValidatorsCache.end()) {
+ ValidatorCache* entry = *iter;
+ iter++;
+ delete entry;
+ }
+ mValidatorsCache.clear();
+ }
+
capu::SmartPointer<EtchValidator>* get(EtchRuntime* runtime) {
capu::List<ValidatorCache*>::Iterator iter = mValidatorsCache.begin();
while(iter != mValidatorsCache.end()) {