Line data Source code
1 : // Author(s): Wieger Wesselink 2 : // Copyright: see the accompanying file COPYING or copy at 3 : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING 4 : // 5 : // Distributed under the Boost Software License, Version 1.0. 6 : // (See accompanying file LICENSE_1_0.txt or copy at 7 : // http://www.boost.org/LICENSE_1_0.txt) 8 : // 9 : /// \file mcrl2/data/default_expression_generator.h 10 : /// \brief add your file description here. 11 : 12 : #ifndef MCRL2_DATA_DEFAULT_EXPRESSION_GENERATOR_H 13 : #define MCRL2_DATA_DEFAULT_EXPRESSION_GENERATOR_H 14 : 15 : #include "mcrl2/data/representative_generator.h" 16 : 17 : namespace mcrl2 { 18 : 19 : namespace data { 20 : 21 : /// \brief Expression generator that caches values. 22 : class default_expression_generator 23 : { 24 : protected: 25 : data::representative_generator generator; 26 : std::map<sort_expression, data_expression> default_values; 27 : 28 : public: 29 0 : explicit default_expression_generator(const data_specification& dataspec) 30 0 : : generator(dataspec) 31 0 : {} 32 : 33 0 : const data_expression& operator()(const sort_expression& x) 34 : { 35 0 : auto i = default_values.find(x); 36 0 : if (i == default_values.end()) 37 : { 38 0 : data_expression d = generator(x); 39 0 : if (!d.defined()) 40 : { 41 0 : throw mcrl2::runtime_error("could not find a default value for sort " + data::pp(x)); 42 : } 43 0 : i = default_values.insert(std::make_pair(x, d)).first; 44 0 : } 45 0 : return i->second; 46 : } 47 : }; 48 : 49 : } // namespace data 50 : 51 : } // namespace mcrl2 52 : 53 : #endif // MCRL2_DATA_DEFAULT_EXPRESSION_GENERATOR_H