//////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2018 Leo Tenenbaum // This file is part of GraphColoring. // // GraphColoring is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // GraphColoring is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with GraphColoring. If not, see . //////////////////////////////////////////////////////////////////////////////// #ifndef GRAPHCOLORING_LEVELS_VALUE_H_ #define GRAPHCOLORING_LEVELS_VALUE_H_ #include "pugi/pugixml.hpp" #include "../graphs/graph.hpp" namespace graphcoloring { class Value { public: typedef std::function operation_t; Value(); Value(std::vector list); Value(int val); Value(const std::string& string); Value(pugi::xml_node node); virtual ~Value() {} int Eval(const Graph& graph, std::function lookup_variable) const; static void AddNodeToVariables(pugi::xml_node node); private: void FromString(const std::string& string); void ReadOperation(std::string op); static operation_t SimpleOperation(std::function op); // For operations which don't look at the graph. // Bool operations return bools. static operation_t SimpleBoolOperation(std::function op); // Logical operations take bools and return bools. static operation_t SimpleLogicOperation(std::function op); static void InitializeOperationTable(); std::vector EvalListOperation(const Graph& graph, // Handles anything that returns a list. std::function lookup_variable) const; operation_t operation; static std::map operation_table; std::shared_ptr fold_start; std::shared_ptr val1; std::shared_ptr val2; std::string variable_name; int val = 0; std::vector list; enum class Type { NULL_TYPE, VALUE, // This value represents a constant number LIST, VARIABLE, NUMBER_OF_VERTICES, NUMBER_OF_EDGES, VERTICES, EDGES, OPERATION, LIST_OPERATION, MAP, ZIP, FOLD }; Type type; }; } // namespace graphcoloring #endif // GRAPHCOLORING_LEVELS_VALUE_H_