1
0
Fork 0
arangodb/Variant/VariantObject.h

249 lines
9.2 KiB
C++

////////////////////////////////////////////////////////////////////////////////
/// @brief abstract base class for variant objects
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
///
/// Licensed 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.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Achim Brandt
/// @author Copyright 2008-2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_VARIANT_VARIANT_OBJECT_H
#define TRIAGENS_VARIANT_VARIANT_OBJECT_H 1
#include "Basics/Common.h"
#include "Basics/Exceptions.h"
namespace triagens {
namespace basics {
class StringBuffer;
// -----------------------------------------------------------------------------
// --SECTION-- class VariantObject
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Variants
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief abstract base class for variant objects
////////////////////////////////////////////////////////////////////////////////
class VariantObject {
VariantObject (VariantObject const&);
VariantObject& operator= (VariantObject const&);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- static public constants
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Variants
/// @{
////////////////////////////////////////////////////////////////////////////////
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief enumeration of all non-abstract object types
////////////////////////////////////////////////////////////////////////////////
enum ObjectType {
VARIANT_ARRAY,
VARIANT_BLOB,
VARIANT_BOOLEAN,
VARIANT_DATE,
VARIANT_DATETIME,
VARIANT_DOUBLE,
VARIANT_FLOAT,
VARIANT_INT8,
VARIANT_INT16,
VARIANT_INT32,
VARIANT_INT64,
VARIANT_MATRIX2,
VARIANT_NULL,
VARIANT_ROW,
VARIANT_STRING,
VARIANT_UINT8,
VARIANT_UINT16,
VARIANT_UINT32,
VARIANT_UINT64,
VARIANT_VECTOR
};
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- static public methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Variants
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief name of an object types
////////////////////////////////////////////////////////////////////////////////
static string NameObjectType (ObjectType);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Variants
/// @{
////////////////////////////////////////////////////////////////////////////////
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief constructs a result object
////////////////////////////////////////////////////////////////////////////////
VariantObject ();
////////////////////////////////////////////////////////////////////////////////
/// @brief destructs a result object
////////////////////////////////////////////////////////////////////////////////
virtual ~VariantObject ();
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Variants
/// @{
////////////////////////////////////////////////////////////////////////////////
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief converts into specific subtype or raises an error
////////////////////////////////////////////////////////////////////////////////
template<typename T> T* as () {
T* c = dynamic_cast<T*>(this);
if (c == 0) {
THROW_INTERNAL_ERROR("illegal cast");
}
return c;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief checks for specific subtype
////////////////////////////////////////////////////////////////////////////////
template<typename T> bool is () const {
return this->type() == T::TYPE;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public abstract virtual methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Variants
/// @{
////////////////////////////////////////////////////////////////////////////////
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the object type
////////////////////////////////////////////////////////////////////////////////
virtual ObjectType type () const = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief clones an object
////////////////////////////////////////////////////////////////////////////////
virtual VariantObject* clone () const = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief prints an object to a string buffer für debugging
////////////////////////////////////////////////////////////////////////////////
virtual void print (StringBuffer&, size_t indent) const = 0;
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- protected methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Variants
/// @{
////////////////////////////////////////////////////////////////////////////////
protected:
////////////////////////////////////////////////////////////////////////////////
/// @brief print indentation
////////////////////////////////////////////////////////////////////////////////
void printIndent (StringBuffer&, size_t indent) const;
};
}
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End: