LazyTable.h
1 /*
2  * MoMEMta: a modular implementation of the Matrix Element Method
3  * Copyright (C) 2016 Universite catholique de Louvain (UCL), Belgium
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include <memory>
22 #include <string>
23 
24 #include <momemta/ParameterSet.h>
25 
26 #include <lua/utils.h>
27 
28 namespace lua {
29 
35 struct LazyTableField : public Lazy {
36  std::string table_name;
37  std::string key;
38 
39  virtual momemta::any operator()() const override;
40 
44  void ensure_created();
45 
49  void set(const momemta::any& value);
50 
51  LazyTableField(lua_State *L, const std::string& table_name, const std::string& key);
52 };
53 
62 class LazyTable: public ParameterSet {
63  friend class ConfigurationReader;
64 
65 public:
66  LazyTable(std::shared_ptr<lua_State> L, const std::string& name);
67  virtual LazyTable* clone() const override;
68 
69 protected:
70  virtual void create(const std::string& name, const momemta::any& value) override;
71  virtual void setInternal(const std::string& name, Element& element, const momemta::any& value) override;
72 
73  virtual bool lazy() const override;
74 
75  virtual void freeze() override;
76 
77 private:
78  std::shared_ptr<lua_State> m_lua_state;
79 };
80 
81 }
A specialization of ParameterSet for lazy loading of lua tables.
Definition: LazyTable.h:62
A lua configuration file parser.
std::string table_name
The name of the global table.
Definition: LazyTable.h:36
std::string key
The name of the field inside the table to retrieve when evaluated.
Definition: LazyTable.h:37
Configuration freeze() const
Freeze the configuration.
Lazy table field in lua (delayed table access)
Definition: LazyTable.h:35
A small wrapper around a momemta::any value.
Definition: ParameterSet.h:259
lua_State * L
The global lua state. This state must be valid for as long as this instance.
Definition: utils.h:55
Lazy value in lua (delayed evaluation)
Definition: utils.h:54
A class encapsulating a lua table.
Definition: ParameterSet.h:82
virtual momemta::any operator()() const override
Evaluate the lazy value.
Definition: LazyTable.cc:52
void ensure_created()
Ensure the global table referenced by this struct exist. If not, create it.
Definition: LazyTable.cc:36
Utility functions related to lua configuration file parsing.
Definition: Path.h:31