1 //=============================================================================
3 * @file Codeset_Registry.cpp
5 * emulated codset regstry functions
7 * @author Phil Mesnier <mesnier_p@ociweb.com>
9 //=============================================================================
11 #include "ace/Codeset_Registry.h"
12 #include "ace/OS_Memory.h"
13 #include "ace/OS_NS_string.h"
15 #if !defined (__ACE_INLINE__)
16 #include "ace/Codeset_Registry.inl"
17 #endif /* __ACE_INLINE__ */
19 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
22 ACE_Codeset_Registry::locale_to_registry_i (const ACE_CString
&locale
,
23 ACE_CDR::ULong
&codeset_id
,
24 ACE_CDR::UShort
*num_sets
,
25 ACE_CDR::UShort
**char_sets
)
27 registry_entry
const *element
= 0;
28 for (size_t i
= 0; element
== 0 && i
< num_registry_entries_
; i
++)
29 if (ACE_OS::strcmp (registry_db_
[i
].loc_name_
, locale
.c_str ()) == 0)
30 element
= ®istry_db_
[i
];
33 codeset_id
= element
->codeset_id_
;
35 *num_sets
= element
->num_sets_
;
38 #if defined (ACE_HAS_ALLOC_HOOKS)
39 ACE_ALLOCATOR_RETURN (*char_sets
,static_cast<ACE_CDR::UShort
*> (ACE_Allocator::instance()->malloc(sizeof (ACE_CDR::UShort
) * (element
->num_sets_
))),0);
41 ACE_NEW_RETURN (*char_sets
,ACE_CDR::UShort
[element
->num_sets_
],0);
42 #endif /* ACE_HAS_ALLOC_HOOKS */
43 ACE_OS::memcpy (*char_sets
, element
->char_sets_
,
44 element
->num_sets_
* sizeof (ACE_CDR::UShort
));
50 ACE_Codeset_Registry::registry_to_locale_i (ACE_CDR::ULong codeset_id
,
52 ACE_CDR::UShort
*num_sets
,
53 ACE_CDR::UShort
**char_sets
)
55 registry_entry
const *element
= 0;
56 for (size_t i
= 0; element
== 0 && i
< num_registry_entries_
; i
++)
57 if (codeset_id
== registry_db_
[i
].codeset_id_
)
58 element
= ®istry_db_
[i
];
61 locale
.set (element
->loc_name_
);
63 *num_sets
= element
->num_sets_
;
66 #if defined (ACE_HAS_ALLOC_HOOKS)
67 ACE_ALLOCATOR_RETURN (*char_sets
,static_cast<ACE_CDR::UShort
*> (ACE_Allocator::instance()->malloc(sizeof (ACE_CDR::UShort
) * (element
->num_sets_
))),0);
69 ACE_NEW_RETURN (*char_sets
,ACE_CDR::UShort
[element
->num_sets_
],0);
70 #endif /* ACE_HAS_ALLOC_HOOKS */
71 ACE_OS::memcpy (*char_sets
, element
->char_sets_
,
72 element
->num_sets_
* sizeof (ACE_CDR::UShort
));
78 ACE_Codeset_Registry::is_compatible_i (ACE_CDR::ULong codeset_id
,
81 registry_entry
const *lhs
= 0;
82 registry_entry
const *rhs
= 0;
83 for (size_t i
= 0; (lhs
== 0 || rhs
== 0) && i
< num_registry_entries_
; i
++)
85 if (codeset_id
== registry_db_
[i
].codeset_id_
)
86 lhs
= ®istry_db_
[i
];
87 if (other
== registry_db_
[i
].codeset_id_
)
88 rhs
= ®istry_db_
[i
];
91 if (lhs
== 0 || rhs
== 0)
94 for (ACE_CDR::UShort l
= 0; l
< lhs
->num_sets_
; l
++)
95 for (ACE_CDR::UShort r
= 0; r
< rhs
->num_sets_
; r
++)
96 if (rhs
->char_sets_
[r
] == lhs
->char_sets_
[l
])
102 ACE_Codeset_Registry::get_max_bytes_i (ACE_CDR::ULong codeset_id
)
104 for (size_t i
= 0; i
< num_registry_entries_
; i
++)
105 if (codeset_id
== registry_db_
[i
].codeset_id_
)
106 return registry_db_
[i
].max_bytes_
;
110 ACE_END_VERSIONED_NAMESPACE_DECL