You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by fi...@apache.org on 2012/06/01 13:09:23 UTC
svn commit: r1345050 - in /incubator/etch/trunk/binding-cpp/runtime:
include/serialization/ src/main/ src/main/serialization/
Author: fitzner
Date: Fri Jun 1 11:09:22 2012
New Revision: 1345050
URL: http://svn.apache.org/viewvc?rev=1345050&view=rev
Log:
ETCH-185 Implementation Validators
Abstract Base Classes for validators are implemented
Change-Id: Iaf8ac1217de1a9f5ffb15fcc33012b54cb148ebe
Added:
incubator/etch/trunk/binding-cpp/runtime/include/serialization/
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeCodes.h
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeValidator.h
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidator.h
incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/
incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchTypeValidator.cpp
Modified:
incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeCodes.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeCodes.h?rev=1345050&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeCodes.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeCodes.h Fri Jun 1 11:09:22 2012
@@ -0,0 +1,202 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ETCHTYPECODES_H__
+#define __ETCHTYPECODES_H__
+#include "common/EtchConfig.h"
+
+/**
+ * Values denoting types of encoded values. There are two value ranges:
+ *
+ * -128 to -65: codes for defined types.
+ * -64 to 127: tiny integer values.
+ *
+ * Tiny integers are completely encoded within the type byte.
+ */
+class EtchTypeCode {
+
+public:
+ /**
+ * A code denoting a null value.
+ */
+ static const capu::int8_t Null = -128;
+
+ /**
+ * A code denoting no value, which is different than NULL. For
+ * example, an array is a sequence of values (some of which may
+ * be NULL), terminated by a NONE.
+ */
+ static const capu::int8_t NONE = -127;
+
+ //////////////////////////////////////////////////
+ // scalar values (but, also see tiny int below) //
+ //////////////////////////////////////////////////
+
+ /**
+ * A code denoting a false boolean value.
+ */
+ static const capu::int8_t BOOLEAN_FALSE = -126;
+
+ /**
+ * A code denoting a true boolean value.
+ */
+ static const capu::int8_t BOOLEAN_TRUE = -125;
+
+ /**
+ * A code denoting a signed byte.
+ */
+ static const capu::int8_t BYTE = -124;
+
+ /**
+ * A code denoting a two byte signed short, msb first.
+ */
+ static const capu::int8_t SHORT = -123;
+
+ /**
+ * A code denoting a four byte signed integer, msb first.
+ */
+ static const capu::int8_t INT = -122;
+
+ /**
+ * A code denoting an eight byte signed long, msb first.
+ */
+ static const capu::int8_t LONG = -121;
+
+ /**
+ * A code denoting a four byte ieee floating format number (single,
+ * written as an INT).
+ */
+ static const capu::int8_t FLOAT = -120;
+
+ /**
+ * A code denoting an eight byte ieee floating format number (double,
+ * written as a LONG).
+ */
+ static const capu::int8_t DOUBLE = -119;
+
+ ////////////
+ // arrays //
+ ////////////
+
+ // BOOLS, SHORTS, INTS, LONGS, FLOATS, and DOUBLES are
+ // reserved for future use.
+
+ // /**
+ // * A code denoting an array of booleans.
+ // */
+ // static capu::int8_t BOOLS = -118;
+
+ /**
+ * A code denoting an array of bytes.
+ */
+ static const capu::int8_t BYTES = -117;
+
+ // /**
+ // * A code denoting an array of shorts.
+ // */
+ // static capu::int8_t SHORTS = -116;
+
+ // /**
+ // * A code denoting an array of ints.
+ // */
+ // static capu::int8_t INTS = -115;
+
+ // /**
+ // * A code denoting an array of longs.
+ // */
+ // static capu::int8_t LONGS = -114;
+
+ // /**
+ // * A code denoting an array of ieee format singles.
+ // */
+ // static capu::int8_t FLOATS = -113;
+
+ // /**
+ // * A code denoting an array of ieee format doubles.
+ // */
+ // static capu::int8_t DOUBLES = -112;
+
+ /**
+ * A code denoting a sequence of values.
+ */
+ static const capu::int8_t ARRAY = -111;
+
+ /////////////
+ // strings //
+ /////////////
+
+ /**
+ * A code denoting an empty string.
+ */
+ static const capu::int8_t EMPTY_STRING = -110;
+
+ /**
+ * A code denoting a utf-8 encoded string.
+ */
+ static const capu::int8_t STRING = -109;
+
+ /////////////////////
+ // structured data //
+ /////////////////////
+
+ /**
+ * A code denoting a custom value (struct, exception, enum, extern)
+ * from a value factory. An associated value identifies the specific
+ * type. The format on the wire of STRUCT and CUSTOM are the same.
+ * Emit CUSTOM instead of STRUCT, and accept STRUCT as if it were
+ * CUSTOM.
+ */
+ static const capu::int8_t STRUCT = -108;
+
+ /**
+ * A code denoting a custom value (struct, exception, enum, extern)
+ * from a value factory. An associated value identifies the specific
+ * type. The format on the wire of STRUCT and CUSTOM are the same.
+ * Emit CUSTOM instead of STRUCT, and accept STRUCT as if it were
+ * CUSTOM.
+ */
+ static const capu::int8_t CUSTOM = -107;
+
+ //////////
+ // misc //
+ //////////
+
+ /**
+ * A code denoting that any value is ok (as long as we know how
+ * to serialize it). Dynamic methods should be applied to determine
+ * the type. This type never appears on the wire.
+ */
+ static const capu::int8_t ANY = -106;
+
+ ///////////////////
+ // tiny integers //
+ ///////////////////
+
+ /**
+ * Minimum "tiny" integer.
+ */
+ static const capu::int8_t MIN_TINY_INT = -64;
+
+ /**
+ * Maximum "tiny" integer.
+ */
+ static const capu::int8_t MAX_TINY_INT = 127;
+};
+
+#endif /* ETCHTYPECODES_H */
+
Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeValidator.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeValidator.h?rev=1345050&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeValidator.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeValidator.h Fri Jun 1 11:09:22 2012
@@ -0,0 +1,73 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ETCHTYPEVALIDATOR_H__
+#define __ETCHTYPEVALIDATOR_H__
+#include "serialization/EtchValidator.h"
+#include "common/EtchError.h"
+
+class EtchTypeValidator : public EtchValidator {
+public:
+
+ /**
+ * Constructs the TypeValidator.
+ *
+ * @param type the type of the derived class
+ * @param scalarClass class to use if nDims == 0
+ * @param arrayClass class to use if nDims > 0
+ * @param nDims the number of dimensions. 0 for a scalar
+ * @param subClass default is false
+ */
+ EtchTypeValidator(const EtchObjectType * type, const EtchObjectType* scalarClass, const EtchObjectType* arrayClass, capu::uint32_t nDims, capu::bool_t subclass = false);
+
+ /**
+ * Default Destructor
+ */
+ virtual ~EtchTypeValidator();
+
+ /**
+ * Checks the number of dimensions for standard validators.
+ * @param nDims
+ * @returns ETCH_ERROR if nDims < 0 || mNDims > MAX_NDIMS
+ * ETCH_OK otherwise
+ */
+ status_t checkDimension(capu::uint32_t ndim);
+
+ /**
+ * @return the expected number of dimensions.
+ */
+ virtual capu::uint32_t getNDims();
+
+ /**
+ * Returns expected Type
+ * @return expected type
+ */
+ virtual const EtchObjectType* getExpectedType();
+
+protected:
+
+ capu::uint32_t mNDims;
+ const EtchObjectType* mExpectedType;
+ const EtchObjectType* mArrayComponentType;
+ capu::bool_t mSubclass;
+
+};
+
+
+#endif /* ETCHTYPEVALIDATOR_H */
+
Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidator.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidator.h?rev=1345050&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidator.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidator.h Fri Jun 1 11:09:22 2012
@@ -0,0 +1,80 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ETCHVALIDATOR_H__
+#define __ETCHVALIDATOR_H__
+#include "capu/util/SmartPointer.h"
+#include "common/EtchObject.h"
+#include "common/EtchError.h"
+
+class EtchValidator : public EtchObject {
+public:
+
+ EtchValidator(const EtchObjectType *type)
+ : EtchObject(type) {
+
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~EtchValidator() {
+
+ }
+
+ /**
+ * The maximum number of dimensions for arrays (9).
+ */
+ const static capu::uint32_t MAX_NDIMS = 9;
+
+ /**
+ * The maximum number of validators to cache per type.
+ */
+ const static capu::uint32_t MAX_CACHED = 4;
+
+ /**
+ * @param val for an array type, return a validator for an element of
+ * the array (which might be a scalar or another array element).
+ * @return ETCH_OK if elementValidator is succesfully get
+ * ETCH_EINVAL otherwise
+ */
+ virtual status_t elementValidator(capu::SmartPointer<EtchValidator> &val) = 0;
+
+ /**
+ * Checks the value for being valid. If the value is valid
+ * by this validator, return true.
+ * @param value the value to be validated.
+ * @return true if the value is valid by any validator in the
+ * chain, or false if all reject it.
+ */
+ virtual capu::bool_t validate(EtchObject* value) = 0;
+
+ /**
+ * @param value
+ * @param result the appropriate value given the input value and this
+ * validator's sensibility about what it should be really (e.g.,
+ * input Byte but output Long.
+ * @return TRUE if the value is validated
+ * FALSE otherwise
+ */
+ virtual status_t validateValue(EtchObject* value, EtchObject*& result) = 0;
+
+};
+
+#endif /* ETCHVALIDATOR_H */
+
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1345050&r1=1345049&r2=1345050&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Fri Jun 1 11:09:22 2012
@@ -61,6 +61,9 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/transport/EtchTcpListener.h
${PROJECT_SOURCE_DIR}/include/transport/EtchTcpOption.h
${PROJECT_SOURCE_DIR}/include/transport/EtchPacketizer.h
+ ${PROJECT_SOURCE_DIR}/include/serialization/EtchValidator.h
+ ${PROJECT_SOURCE_DIR}/include/serialization/EtchTypeValidator.h
+ ${PROJECT_SOURCE_DIR}/include/serialization/EtchTypeCodes.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
)
@@ -86,6 +89,7 @@ SET(MAIN_SOURCES
transport/EtchTcpListener.cpp
transport/EtchTcpOption.cpp
transport/EtchPacketizer.cpp
+ serialization/EtchTypeValidator.cpp
util/EtchUtil.cpp
)
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchTypeValidator.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchTypeValidator.cpp?rev=1345050&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchTypeValidator.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchTypeValidator.cpp Fri Jun 1 11:09:22 2012
@@ -0,0 +1,65 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "serialization/EtchTypeValidator.h"
+
+EtchTypeValidator::EtchTypeValidator(const EtchObjectType * type, const EtchObjectType* scalarClass, const EtchObjectType* arrayClass, capu::uint32_t nDims, capu::bool_t subclass)
+: EtchValidator(type), mNDims(-1), mExpectedType(NULL), mArrayComponentType(NULL), mSubclass(subclass){
+ if (checkDimension(nDims) == ETCH_OK)
+ mNDims = nDims;
+
+ if (mNDims == 0)
+ mExpectedType = new EtchObjectType(scalarClass->getTypeId(),scalarClass->getObjectComponentType());
+ else if (mNDims > 0){
+ EtchObjectType *type = new EtchObjectType(scalarClass->getTypeId(), NULL);
+ for(capu::uint32_t i = 0 ; i < mNDims ;i++)
+ {
+ type = new EtchObjectType(EOTID_NATIVE_ARRAY, type);
+ }
+ mExpectedType = type;
+ mArrayComponentType = scalarClass;
+ }
+
+}
+
+EtchTypeValidator::~EtchTypeValidator(){
+ const EtchObjectType *type;
+ type = mExpectedType->getObjectComponentType();
+ while(type != NULL)
+ {
+ const EtchObjectType *tmp = type;
+ type = type->getObjectComponentType();
+ delete tmp;
+ }
+ delete mExpectedType;
+}
+
+capu::uint32_t EtchTypeValidator::getNDims(){
+ return mNDims;
+}
+
+const EtchObjectType* EtchTypeValidator::getExpectedType(){
+ return mExpectedType;
+}
+
+status_t EtchTypeValidator::checkDimension(capu::uint32_t ndim){
+ if (ndim < EtchValidator::MAX_NDIMS)
+ return ETCH_OK;
+ else
+ return ETCH_ERROR;
+}
\ No newline at end of file