Calculator
Extensible stack-based calculator primarily in library form
StackOperatorFactory.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 STACK_OPERATOR_FACTORY_H
15 #define STACK_OPERATOR_FACTORY_H
16 
17 namespace Calculator {
18 
19  class StackOperator;
20  class StackOperatorCreator;
21  class StackOperatorFactoryPimpl;
22 
23  /** Factory to create StackOperators and help from StackOperatorCreators.
24  *
25  * This class is simple for a reason: if you want to change available commands,
26  * create a factory for each situation and provide it when relevant.
27  *
28  * \note When creating StackOperators, the first added creator that can make a
29  * StackOperator wins and terminates. There is no ambiguity or resolution done.
30  */
32  public:
33 
34  /** Create */
36 
41 
42  /** Add creator as available after all previous creators.
43  *
44  * @param creator to add
45  */
46  void addCreator(std::shared_ptr<StackOperatorCreator> creator);
47 
48  /** @return help string for all available creators */
49  std::string getHelp() const;
50 
51  /** Try to create a StackOperator for the given str.
52  *
53  * @param str to use in attempting to create a StackOperator
54  *
55  * @return StackOperator created, or none if there is no match to str
56  */
57  std::shared_ptr<StackOperator> create(const std::string& str) const;
58 
59  private:
60  /** Private implementation */
61  std::shared_ptr<StackOperatorFactoryPimpl> pimpl;
62  };
63 
64 } // namespace Calculator
65 
66 #endif // STACK_OPERATOR_FACTORY_H
Factory to create StackOperators and help from StackOperatorCreators.
std::shared_ptr< StackOperator > create(const std::string &str) const
Try to create a StackOperator for the given str.
StackOperatorFactory & operator=(const StackOperatorFactory &rhs)
void addCreator(std::shared_ptr< StackOperatorCreator > creator)
Add creator as available after all previous creators.
Container of Calculator resources.