summaryrefslogtreecommitdiff
path: root/modules/CIAO/tools/Config_Handlers/Utils/Functors.h
blob: 6856a0defec4874b15d1f34975ac2215fa009417 (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
#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 Source,
              typename Dest,
              typename Dest_Type,
#if defined (__BORLANDC__) && (__BORLANDC__ == 0x564)
              void (Func)(const Source &, Dest_Type &)>
#else
              void (&Func)(const Source &, Dest_Type &)>
#endif
    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_;
    };

    /*
     * This is a workaround for a GCC bug that for some reason causes
     * functions that appear ONLY in a Sequence_Handler typedef to not
     * be present in the compiled object file.
     * This bug was first observed in GCC 4.02.
     *
     * W: The function we want to be defined
     * X: First argument to the function
     * Y: Second argument to the function
     */
#define SEQ_HAND_GCC_BUG_WORKAROUND(W, X, Y)	\
    while(0) { \
      W (*X, Y[0]);  \
    }


    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 */