Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / tao / Codeset / UTF16_BOM_Factory.cpp
blob207fc0ab4673b9bca51ee44aba2b24b50fecaf55
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file UTF16_BOM_Factory.cpp
7 * Loader for an instance of the UTF16_BOM_Translator.
9 * @author Phil Mesnier <mesnier_p@ociweb.com>
11 //=============================================================================
13 #include "tao/debug.h"
14 #include "tao/Codeset/UTF16_BOM_Factory.h"
15 #include "ace/OS_NS_strings.h"
16 #include "ace/Dynamic_Service.h"
17 #include "ace/Log_Msg.h"
19 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
21 ACE_STATIC_SVC_DEFINE (TAO_UTF16_BOM_Factory,
22 ACE_TEXT ("UTF16_BOM_Factory"),
23 ACE_SVC_OBJ_T,
24 &ACE_SVC_NAME (TAO_UTF16_BOM_Factory),
25 ACE_Service_Type::DELETE_THIS
26 | ACE_Service_Type::DELETE_OBJ,
28 ACE_FACTORY_DEFINE (TAO_Codeset, TAO_UTF16_BOM_Factory)
30 TAO_UTF16_BOM_Factory::~TAO_UTF16_BOM_Factory ()
32 delete this->translator_;
35 int
36 TAO_UTF16_BOM_Factory::init (int argc, ACE_TCHAR *argv[])
38 TAO_Codeset_Translator_Factory::init (argc, argv);
40 for (int narg = 0; narg < argc;)
42 int consumed = parse_one_arg (argc - narg, &argv[narg]);
43 if (consumed > 0)
45 narg += consumed;
47 else
49 TAOLIB_ERROR ((LM_ERROR,
50 ACE_TEXT ("(%P|%t)TAO_UTF16_BOM_Factory parameter error: %s\n")
51 ACE_TEXT ("Usage: TAO_UTF16_BOM_Factory \"-forceBE\"\n")
52 , argv[narg]
53 ));
54 return -1;
57 return 0;
60 int
61 TAO_UTF16_BOM_Factory::parse_one_arg (int argc, ACE_TCHAR *argv[])
63 int consumed = 0;
64 if ((argc > 0) && (ACE_OS::strcasecmp (argv[0], ACE_TEXT("-forcebe")) == 0))
66 this->forceBE_ = true;
67 consumed = 1;
69 return consumed;
72 CONV_FRAME::CodeSetId
73 TAO_UTF16_BOM_Factory::ncs () const
75 create_translator();
76 return this->translator_->ncs();
79 CONV_FRAME::CodeSetId
80 TAO_UTF16_BOM_Factory::tcs () const
82 create_translator();
83 return this->translator_->tcs();
86 // Assign either a reference to the existing translator or a new translator
87 // for input CDR streams
88 void
89 TAO_UTF16_BOM_Factory::assign (TAO_InputCDR *cdr) const
91 if (cdr)
93 create_translator ();
94 this->assign_i (cdr, this->translator_);
98 // Assign either a reference to the existing translator or a new translator
99 // for output CDR streams
100 void
101 TAO_UTF16_BOM_Factory::assign (TAO_OutputCDR *cdr) const
103 if (cdr)
105 create_translator ();
106 this->assign_i (cdr, this->translator_);
110 void
111 TAO_UTF16_BOM_Factory::create_translator () const
113 if (this->translator_ == 0)
115 TAO_UTF16_BOM_Factory * pthis = const_cast<TAO_UTF16_BOM_Factory *> (this);
116 ACE_NEW (pthis->translator_, TAO_UTF16_BOM_Translator (this->forceBE_));
117 if (this->translator_ == 0)
119 if (TAO_debug_level)
120 TAOLIB_ERROR ((LM_ERROR,
121 ACE_TEXT ("TAO (%P|%t) - UTF16_BOM_Factory: ")
122 ACE_TEXT ("Cannot create translator\n")
128 TAO_END_VERSIONED_NAMESPACE_DECL