summaryrefslogtreecommitdiff
path: root/TAO/tests/Sequence_Unit_Tests/string_traits.hpp
blob: 85bc08c0b75e60b4ee065a29f0207314d97a176c (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
#ifndef guard_string_traits_hpp
#define guard_string_traits_hpp
/**
 * @file
 *
 * @brief Implement the element manipulation traits for string types.
 *
 * $Id$
 *
 * @author Carlos O'Ryan
 */

#include "string_traits_base.hpp"

#include <algorithm>
#include <functional>

namespace TAO
{
namespace details
{

template<typename char_type, class derived>
struct string_traits_decorator
{
  typedef char_type * value_type;
  typedef char_type const * const_value_type;

  inline static void zero_range(
      char_type ** begin, char_type ** end)
  {
    std::fill(begin, end, static_cast<char_type*>(0));
  }

  inline static void initialize_range(
      char_type ** begin, char_type ** end)
  {
    std::generate(begin, end, &derived::default_initializer);
  }

  inline static void copy_range(
      char_type ** begin, char_type ** end, char ** dst)
  {
    std::transform(begin, end, dst, &derived::duplicate);
  }

  inline static char_type const * initialize_if_zero(char_type * & element)
  {
    if (element == 0)
    {
      element = derived::default_initializer();
    }
    return element;
  }

  inline static void not_released_from_const(
      char_type * & dst, char_type const * src)
  {
    dst = const_cast<char_type*>(src);
  }

  inline static void not_released_from_managed(
      char_type * & dst, char_type const * src)
  {
    dst = const_cast<char_type*>(src);
  }
};

template<class charT, bool dummy>
struct string_traits
  : public string_traits_base<charT>
  , public string_traits_decorator<charT,string_traits<charT,dummy> >
{
};

} // namespace details
} // namespace CORBA

#endif // guard_string_traits_hpp