1 //
2 //      aegis - project change supervisor
3 //      Copyright (C) 2007, 2008, 2012 Peter Miller
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
17 //      <http://www.gnu.org/licenses/>.
18 //
19 
20 #ifndef LIBAEGIS_SUB_FUNCTOR_GLUE_H
21 #define LIBAEGIS_SUB_FUNCTOR_GLUE_H
22 
23 #include <libaegis/sub/functor.h>
24 
25 /**
26   * The sub_functor_glue class is used to represent calling a function
27   * to do the work of the functor.
28   *
29   * DO NOT write new substitutions using this class.  New substitutions
30   * should always be implemented by derving from the sub_functor
31   * abstract base class.
32   */
33 class sub_functor_glue:
34     public sub_functor
35 {
36 public:
37     /**
38       * The destructor.
39       */
40     virtual ~sub_functor_glue();
41 
42     typedef wstring (*func_p)(sub_context_ty *scp, const wstring_list &arg);
43 
44 private:
45     /**
46       * The constructor.  May not be called directly, you must always go
47       * via the create class method.
48       *
49       * @param name
50       *     The name of this substitution
51       * @param what
52       *     The function to perform the substitution
53       * @param resub
54       *     the output of the substitution is to be re-interpreted again
55       *     for substitutions
56       */
57     sub_functor_glue(const nstring &name, func_p what, bool resub);
58 
59 public:
60     /**
61       * The create class method is used to create a new instance of this
62       * class.  This ensures that smart pointers are always used.
63       *
64       * @param name
65       *     The name of this substitution
66       * @param what
67       *     The function to perform the substitution
68       */
69     static pointer create(const nstring &name, func_p what);
70 
71     /**
72       * The create class method is used to create a new instance of this
73       * class.  This ensures that smart pointers are always used.
74       *
75       * @param name
76       *     The name of this substitution
77       * @param what
78       *     The function to perform the substitution
79       * @param resub
80       *     the output of the substitution is to be re-interpreted again
81       *     for substitutions
82       */
83     static pointer create(const nstring &name, func_p what, bool resub);
84 
85 protected:
86     // See base class for documentation.
87     wstring evaluate(sub_context_ty *cp, const wstring_list &arg);
88 
89     // See base class for documentation.
90     bool resubstitute() const;
91 
92     // See base class for documentation.
93     bool append_if_unused() const;
94 
95     // See base class for documentation.
96     bool override() const;
97 
98     // See base class for documentation.
99     bool must_be_used() const;
100 
101     // See base class for documentation.
102     void resubstitute_set();
103 
104     // See base class for documentation.
105     void optional_set();
106 
107     // See base class for documentation.
108     void append_if_unused_set();
109 
110     // See base class for documentation.
111     void override_set();
112 
113 private:
114     /**
115       * The what instance variable is used to remember the function to
116       * call to perform the substitution.
117       */
118     func_p what;
119 
120     /**
121       * The resub instance variable is used to remeber whether or
122       * not the output of this substritution is to be reexamined fro
123       * substitutions.
124       */
125     bool resub;
126 
127     /**
128       * The default constructor.  Do not use.
129       */
130     sub_functor_glue();
131 
132     /**
133       * The copy constructor.  Do not use.
134       */
135     sub_functor_glue(const sub_functor_glue &);
136 
137     /**
138       * The assignment operator.  Do not use.
139       */
140     sub_functor_glue &operator=(const sub_functor_glue &);
141 };
142 
143 #endif // LIBAEGIS_SUB_FUNCTOR_GLUE_H
144 // vim: set ts=8 sw=4 et :
145