summaryrefslogtreecommitdiff
path: root/TAO/CIAO/tools/Config_Handlers/Utils/Functors.h
blob: 34702cd60d0ae904edc2736208988705cf8c632f (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
#ifndef CONFIG_HANDLERS_FUNCTORS_H
#define CONFIG_HANDLERS_FUNCTORS_H

/**
 * @file Functors.h
 * @author William Otte <wotte@dre.vanderbilt.edu>
 * $Id$
 * Functors useful in the config handlers
 */
#include <iterator>

#include "tao/Basic_Types.h" // For CORBA::ULong
#include "tao/StringSeqC.h"

#include "XMLSchema/Types.hpp"
namespace CIAO
{
  namespace Config_Handlers
  {
    template <typename Seq_Type, typename T>
    class Sequence_Iterator :
      public std::iterator <std::forward_iterator_tag, //iterator type
                            T, // Type pointed to by the iterator
                            CORBA::ULong> // Distance type
    {
    public:
      Sequence_Iterator (void)
        : pos_ (0),
          seq_ (0)
      {
      }

      Sequence_Iterator (const Seq_Type &seq, CORBA::ULong pos = 0)
        : pos_ (pos),
          seq_ (&seq)
      {
      }

      Sequence_Iterator (const Sequence_Iterator &s)
      {
        *this = s;
      }

      Sequence_Iterator& operator= (const Sequence_Iterator &s)
      {
        this->seq_ = s.seq_;
        this->pos_ = s.pos_;
        return *this;
      }

      bool operator== (Sequence_Iterator &s)
      {
        return (this->seq_ == s.seq_) && (this->pos_ == s.pos_);
      }

      bool operator!= (Sequence_Iterator &s)
      {
        return !(*this == s);
      }

      T& operator* (void)
      {
        return (*seq_)[pos_];
      }

      T& operator-> (void)
      {
        return *(*this);
      }

      //  Prefix operator
      Sequence_Iterator& operator++ ()
      {
        ++pos_;
        return *this;
      }

      Sequence_Iterator& operator++ (int)
      {
        Sequence_Iterator ans (*this);
        ++(*this);
        return ans;
      }

    private:
      CORBA::ULong pos_;
      Seq_Type *seq_;
    };

    template <typename Source,
              typename Dest,
              typename Dest_Type,
              void (*Func)(const Source &, Dest_Type &)>
    struct Sequence_Handler
    {
      Sequence_Handler (Dest &dest, CORBA::ULong pos = 0)
         : dest_ (dest),
          pos_ (pos)
      {
      }

      void operator() (const Source &src)
      {
        Func (src, dest_[pos_++]);
      }

    private:
      Dest &dest_;
      CORBA::ULong pos_;
    };

    template <typename Dest, typename Dest_Type>
    struct String_Seq_Handler
    {
      String_Seq_Handler (Dest &dest, CORBA::ULong pos = 0)
         : dest_ (dest),
          pos_ (pos)
      {
      }

      void operator() (const ::XMLSchema::string<ACE_TCHAR>  &src)
      {
        dest_[pos_++] = src.c_str ();
      }

    private:
      Dest &dest_;
      CORBA::ULong pos_;
    };

    typedef String_Seq_Handler < ::CORBA::StringSeq,
                                 ::CORBA::String_var > String_Seq_Functor;

  }
}

#endif /* CONFIG_HANDLERS_FUNCTORS_H */