1
0
Fork 0
arangodb/arangod/Aql/VariableGenerator.h

145 lines
5.5 KiB
C++

////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 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 ArangoDB GmbH, Cologne, Germany
///
/// @author Jan Steemann
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGOD_AQL_VARIABLE_GENERATOR_H
#define ARANGOD_AQL_VARIABLE_GENERATOR_H 1
#include "Basics/Common.h"
#include "Aql/Variable.h"
#include "Aql/types.h"
namespace arangodb {
namespace aql {
class VariableGenerator {
public:
//////////////////////////////////////////////////////////////////////////////
/// @brief create the generator
//////////////////////////////////////////////////////////////////////////////
VariableGenerator();
//////////////////////////////////////////////////////////////////////////////
/// @brief destroy the generator
//////////////////////////////////////////////////////////////////////////////
~VariableGenerator();
public:
//////////////////////////////////////////////////////////////////////////////
/// @brief return a map of all variable ids with their names
//////////////////////////////////////////////////////////////////////////////
std::unordered_map<VariableId, std::string const> variables(bool) const;
//////////////////////////////////////////////////////////////////////////////
/// @brief generate a variable
//////////////////////////////////////////////////////////////////////////////
Variable* createVariable(char const*, size_t, bool);
//////////////////////////////////////////////////////////////////////////////
/// @brief generate a variable
//////////////////////////////////////////////////////////////////////////////
Variable* createVariable(std::string const&, bool);
//////////////////////////////////////////////////////////////////////////////
/// @brief generate a variable from VelocyPack
//////////////////////////////////////////////////////////////////////////////
Variable* createVariable(arangodb::velocypack::Slice const);
//////////////////////////////////////////////////////////////////////////////
/// @brief clones a variable from an existing one
//////////////////////////////////////////////////////////////////////////////
Variable* createVariable(Variable const*);
//////////////////////////////////////////////////////////////////////////////
/// @brief generate a temporary variable
//////////////////////////////////////////////////////////////////////////////
Variable* createTemporaryVariable();
//////////////////////////////////////////////////////////////////////////////
/// @brief renames a variable (assigns a temporary name)
//////////////////////////////////////////////////////////////////////////////
Variable* renameVariable(VariableId);
//////////////////////////////////////////////////////////////////////////////
/// @brief renames a variable (assigns the specified name)
//////////////////////////////////////////////////////////////////////////////
Variable* renameVariable(VariableId, std::string const&);
//////////////////////////////////////////////////////////////////////////////
/// @brief return a variable by id - this does not respect the scopes!
//////////////////////////////////////////////////////////////////////////////
Variable* getVariable(VariableId) const;
//////////////////////////////////////////////////////////////////////////////
/// @brief return the next temporary variable name
//////////////////////////////////////////////////////////////////////////////
std::string nextName();
////////////////////////////////////////////////////////////////////////////////
/// @brief export to VelocyPack
////////////////////////////////////////////////////////////////////////////////
void toVelocyPack(arangodb::velocypack::Builder& builder) const;
//////////////////////////////////////////////////////////////////////////////
/// @brief import from VelocyPack
//////////////////////////////////////////////////////////////////////////////
void fromVelocyPack(arangodb::velocypack::Slice const& allVariablesList);
private:
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the next variable id
//////////////////////////////////////////////////////////////////////////////
inline VariableId nextId() { return _id++; }
private:
//////////////////////////////////////////////////////////////////////////////
/// @brief all variables created
//////////////////////////////////////////////////////////////////////////////
std::unordered_map<VariableId, Variable*> _variables;
//////////////////////////////////////////////////////////////////////////////
/// @brief the next assigned variable id
//////////////////////////////////////////////////////////////////////////////
VariableId _id;
};
}
}
#endif