1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 #ifndef CMAJOR_SYMBOLS_OPERATION_INCLUDED
 7 #define CMAJOR_SYMBOLS_OPERATION_INCLUDED
 8 #include <cmajor/symbols/FunctionSymbol.hpp>
 9 
10 namespace cmajor { namespace symbols {
11 
12 class Operation 
13 {
14 public:
15     virtual ~Operation();
16     FunctionSymbol* Get(std::std::vector<Operation*>&operations)
17     {
18         if (!fun)
19         {
20             fun.reset(Create());
21             operations.push_back(this);
22         }
23         return fun.get();
24     }
25     void Release()
26     {
27         fun.reset();
28     }
29 protected:
30     virtual FunctionSymbol* Create() const = 0;
31 private:
32     std::unique_ptr<FunctionSymbol> fun;
33 };
34 
35 } } // namespace cmajor::symbols
36 
37 #endif // CMAJOR_SYMBOLS_OPERATION_INCLUDED