summaryrefslogtreecommitdiff
path: root/trunk/CIAO/CCF/CCF/IDL2/Parsing/Action.hpp
blob: 2737abafb5875b6f375d00343e49d9450e7c1e1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// file      : CCF/IDL2/Parsing/Action.hpp
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : $Id$

#ifndef CCF_IDL2_PARSING_ACTION_HPP
#define CCF_IDL2_PARSING_ACTION_HPP

#include "CCF/IDL2/Parsing/Elements.hpp"

namespace CCF
{
  namespace IDL2
  {
    namespace Parsing
    {
      //
      //
      //
      template <typename Obj>
      class ActionExecutor
      {
      public:

        typedef
        void (Obj::*SemanticAction)(Iterator, Iterator) const;

        ActionExecutor (Obj const* obj, SemanticAction action)
            : obj_ (obj), action_ (action)
        {
        }

        void operator () (Iterator begin, Iterator end) const
        {
          (obj_->*action_) (begin, end);
        }

      private:
        Obj const* obj_;
        SemanticAction action_;
      };


      //
      //
      //
      template <typename Obj>
      class NoArgAction
      {
      public:

        typedef
        void (Obj::*Action)();

        NoArgAction (Obj& obj, Action action)
            : obj_ (obj), action_ (action)
        {
        }

        void operator () (Iterator, Iterator) const
        {
          (obj_.*action_) ();
        }

      private:
        Obj& obj_;
        Action action_;
      };


      //@@ Should prbably use Type instead of TypePtr
      //
      //
      //
      template <typename TypePtr, typename Obj>
      class OneArgAction
      {
      public:

        typedef
        void (Obj::*Action)(TypePtr const&);

        OneArgAction (Obj& obj, Action action)
            : obj_ (obj), action_ (action)
        {
        }

        void operator () (Iterator begin, Iterator end) const
        {
          if (end - begin != 1 )
          {
            //@@ throw
          }

          //@@ error handling if the strict_cast fails
          (obj_.*action_) (
            ReferenceCounting::strict_cast<typename TypePtr::Type> (*begin));
        }

      private:
        Obj& obj_;
        Action action_;
      };


      //
      //
      //
      template <typename Arg1, typename Arg2, typename Obj>
      class TwoArgAction
      {
      public:

        typedef
        void (Obj::*Action)(Arg1 const&, Arg2 const&);

        TwoArgAction (Obj& obj, Action action)
            : obj_ (obj), action_ (action)
        {
        }

        void operator () (Iterator begin, Iterator end) const
        {
          if (end - begin != 2 )
          {
            //@@ throw
          }

          //@@ error handling if strict_cast fails
          (obj_.*action_) (
            ReferenceCounting::strict_cast<typename Arg1::Type> (*begin),
            ReferenceCounting::strict_cast<typename Arg2::Type> (*(begin + 1)));
        }

      private:
        Obj& obj_;
        Action action_;
      };
    }
  }
}

#endif  // CCF_IDL2_PARSING_ACTION_HPP