summaryrefslogtreecommitdiff
path: root/TAO/tao/Codeset/UTF16_BOM_Factory.cpp
blob: 207fc0ab4673b9bca51ee44aba2b24b50fecaf55 (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
// -*- C++ -*-

//=============================================================================
/**
 *  @file    UTF16_BOM_Factory.cpp
 *
 *  Loader for an instance of the UTF16_BOM_Translator.
 *
 *  @author Phil Mesnier <mesnier_p@ociweb.com>
 */
//=============================================================================

#include "tao/debug.h"
#include "tao/Codeset/UTF16_BOM_Factory.h"
#include "ace/OS_NS_strings.h"
#include "ace/Dynamic_Service.h"
#include "ace/Log_Msg.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

ACE_STATIC_SVC_DEFINE (TAO_UTF16_BOM_Factory,
                       ACE_TEXT ("UTF16_BOM_Factory"),
                       ACE_SVC_OBJ_T,
                       &ACE_SVC_NAME (TAO_UTF16_BOM_Factory),
                       ACE_Service_Type::DELETE_THIS
                       | ACE_Service_Type::DELETE_OBJ,
                       0)
ACE_FACTORY_DEFINE (TAO_Codeset, TAO_UTF16_BOM_Factory)

TAO_UTF16_BOM_Factory::~TAO_UTF16_BOM_Factory ()
{
  delete this->translator_;
}

int
TAO_UTF16_BOM_Factory::init (int argc, ACE_TCHAR *argv[])
{
  TAO_Codeset_Translator_Factory::init (argc, argv);

  for (int narg = 0; narg < argc;)
  {
    int consumed = parse_one_arg (argc - narg, &argv[narg]);
    if (consumed > 0)
    {
      narg += consumed;
    }
    else
    {
      TAOLIB_ERROR ((LM_ERROR,
        ACE_TEXT ("(%P|%t)TAO_UTF16_BOM_Factory parameter error: %s\n")
        ACE_TEXT ("Usage: TAO_UTF16_BOM_Factory \"-forceBE\"\n")
        , argv[narg]
        ));
      return -1;
    }
  }
  return 0;
}

int
TAO_UTF16_BOM_Factory::parse_one_arg (int argc, ACE_TCHAR *argv[])
{
  int consumed = 0;
  if ((argc > 0) && (ACE_OS::strcasecmp (argv[0], ACE_TEXT("-forcebe")) == 0))
  {
    this->forceBE_ = true;
    consumed = 1;
  }
  return consumed;
}

CONV_FRAME::CodeSetId
TAO_UTF16_BOM_Factory::ncs () const
{
  create_translator();
  return this->translator_->ncs();
}

CONV_FRAME::CodeSetId
TAO_UTF16_BOM_Factory::tcs () const
{
  create_translator();
  return this->translator_->tcs();
}

// Assign either a reference to the existing translator or a new translator
// for input CDR streams
void
TAO_UTF16_BOM_Factory::assign (TAO_InputCDR *cdr) const
{
  if (cdr)
    {
      create_translator ();
      this->assign_i (cdr, this->translator_);
    }
}

// Assign either a reference to the existing translator or a new translator
// for output CDR streams
void
TAO_UTF16_BOM_Factory::assign (TAO_OutputCDR *cdr) const
{
  if (cdr)
    {
      create_translator ();
      this->assign_i (cdr, this->translator_);
    }
}

void
TAO_UTF16_BOM_Factory::create_translator () const
{
  if (this->translator_ == 0)
  {
    TAO_UTF16_BOM_Factory * pthis = const_cast<TAO_UTF16_BOM_Factory *> (this);
    ACE_NEW (pthis->translator_, TAO_UTF16_BOM_Translator (this->forceBE_));
    if (this->translator_ == 0)
    {
      if (TAO_debug_level)
        TAOLIB_ERROR ((LM_ERROR,
                    ACE_TEXT ("TAO (%P|%t) - UTF16_BOM_Factory: ")
                    ACE_TEXT ("Cannot create translator\n")
        ));
    }
  }
}

TAO_END_VERSIONED_NAMESPACE_DECL