//////////////////////////////////////////////////////////////////////////////// /// @brief class for result vectors /// /// @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 //////////////////////////////////////////////////////////////////////////////// #include "VariantVector.h" #include "Basics/StringBuffer.h" #include "Variant/VariantString.h" using namespace std; using namespace triagens::basics; // ----------------------------------------------------------------------------- // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Variants /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief constructs a new vector //////////////////////////////////////////////////////////////////////////////// VariantVector::VariantVector () : _values() { } //////////////////////////////////////////////////////////////////////////////// /// @brief constructs a new vector //////////////////////////////////////////////////////////////////////////////// VariantVector::VariantVector (vector const& elements) : _values() { for (vector::const_iterator i = elements.begin(); i != elements.end(); ++i) { string const& value = *i; _values.push_back(new VariantString(value)); } } //////////////////////////////////////////////////////////////////////////////// /// @brief destructs a vector //////////////////////////////////////////////////////////////////////////////// VariantVector::~VariantVector () { for (vector::const_iterator i = _values.begin(); i != _values.end(); ++i) { delete (*i); } } //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- VariantObject methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Variants /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// VariantObject::ObjectType VariantVector::type () const { return TYPE; } //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// VariantObject* VariantVector::clone () const { VariantVector* copy = new VariantVector(); for (vector::const_iterator i = _values.begin(); i != _values.end(); ++i) { VariantObject* o = *i; copy->add(o->clone()); } return copy; } //////////////////////////////////////////////////////////////////////////////// /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// void VariantVector::print (StringBuffer& buffer, size_t indent) const { buffer.appendText("{\n"); vector::const_iterator j = _values.begin(); for (size_t i = 0; j != _values.end(); ++i, ++j) { printIndent(buffer, indent+1); buffer.appendInteger(i); buffer.appendText(" => "); (*j)->print(buffer, indent + 2); } printIndent(buffer, indent); buffer.appendText("}\n"); } //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Variants /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief returns the values //////////////////////////////////////////////////////////////////////////////// vector const& VariantVector::getValues () const { return _values; } //////////////////////////////////////////////////////////////////////////////// /// @brief adds a value //////////////////////////////////////////////////////////////////////////////// void VariantVector::add (VariantObject* value) { _values.push_back(value); } //////////////////////////////////////////////////////////////////////////////// /// @brief adds many values //////////////////////////////////////////////////////////////////////////////// void VariantVector::add (vector const& v) { for (vector::const_iterator i = v.begin(); i != v.end(); ++i) { VariantObject* value = *i; _values.push_back(value); } } //////////////////////////////////////////////////////////////////////////////// /// @brief adds a string value //////////////////////////////////////////////////////////////////////////////// void VariantVector::add (string const& value) { _values.push_back(new VariantString(value)); } //////////////////////////////////////////////////////////////////////////////// /// @brief adds many string values //////////////////////////////////////////////////////////////////////////////// void VariantVector::add (vector const& v) { for (vector::const_iterator i = v.begin(); i != v.end(); ++i) { string const& value = *i; _values.push_back(new VariantString(value)); } } //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // Local Variables: // mode: outline-minor // outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" // End: