Calculator
Extensible stack-based calculator primarily in library form
VariableSet.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2013, Komodo Does Inc
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 
7 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 - Neither the name of the Komodo Does Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 */
13 
14 #ifndef VARIABLE_SET_H
15 #define VARIABLE_SET_H
16 
17 namespace Calculator {
18 
19  class StackItem;
20  class VariableSetPimpl;
21 
22  /** \class VariableSet
23  * \brief All variables belonging to a Stack.
24  *
25  * A variable without a value is acceptable until its value is requested; such a
26  * request is not allowed.
27  */
28  class VariableSet {
29  public:
30  /** Construct with an empty variable set */
31  VariableSet();
32 
33  VariableSet(const VariableSet&) = delete;
34  VariableSet(VariableSet&&) = delete;
35  VariableSet& operator=(const VariableSet&) = delete;
37 
38  /** Clear all set variables */
39  void clear();
40 
41  /** Get the value of name, if any.
42  *
43  * @param name of the variable go get
44  *
45  * @return StackItem holding the value of the variable
46  */
47  std::shared_ptr<StackItem> get(const std::string& name) const;
48 
49  /** Set the value of name, overriding existing values
50  *
51  * @param name of the variable go set
52  * @param value holding the value of the variable
53  */
54  void set(const std::string& name, std::shared_ptr<StackItem> value);
55 
56  private:
57  /** Private implementation */
58  std::shared_ptr<VariableSetPimpl> pimpl;
59  };
60 
61 } // namespace Calculator
62 
63 #endif // VARIABLE_SET_H
All variables belonging to a Stack.
Definition: VariableSet.h:28
VariableSet & operator=(VariableSet &&)=delete
VariableSet(VariableSet &&)=delete
void clear()
Clear all set variables.
Definition: VariableSet.cpp:36
VariableSet()
Construct with an empty variable set.
Definition: VariableSet.cpp:31
void set(const std::string &name, std::shared_ptr< StackItem > value)
Set the value of name, overriding existing values.
Definition: VariableSet.cpp:49
VariableSet(const VariableSet &)=delete
std::shared_ptr< StackItem > get(const std::string &name) const
Get the value of name, if any.
Definition: VariableSet.cpp:40
VariableSet & operator=(const VariableSet &)=delete
Container of Calculator resources.