~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/tao/Valuetype/ValueFactory_Map.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "ValueFactory_Map.h"
2
 
#include "ValueFactory.h"
3
 
#include "tao/CORBA_String.h"
4
 
 
5
 
#if !defined (__ACE_INLINE__)
6
 
# include "ValueFactory_Map.inl"
7
 
#endif /* ! __ACE_INLINE__ */
8
 
 
9
 
ACE_RCSID (tao,
10
 
           ValueFactory_Map,
11
 
           "ValueFactory_Map.cpp,v 1.3 2003/10/28 18:29:34 bala Exp")
12
 
 
13
 
TAO_ValueFactory_Map::TAO_ValueFactory_Map (void)
14
 
  : map_ (TAO_DEFAULT_VALUE_FACTORY_TABLE_SIZE)
15
 
{
16
 
}
17
 
 
18
 
TAO_ValueFactory_Map::~TAO_ValueFactory_Map (void)
19
 
{
20
 
  // Initialize an iterator.  We need to go thru each entry and free
21
 
  // up storage allocated to hold the external ids and invoke
22
 
  // _remove_ref () on the internal ids.
23
 
  FACTORY_MAP_MANAGER::ITERATOR iterator (this->map_);
24
 
 
25
 
  for (FACTORY_MAP_MANAGER::ENTRY *entry = 0;
26
 
       iterator.next (entry) != 0;
27
 
       iterator.advance ())
28
 
    {
29
 
      // We had allocated memory and stored the string. So we free the
30
 
      // memory.
31
 
      CORBA::string_free ((char *) entry->ext_id_);
32
 
      entry->ext_id_ = 0;
33
 
      entry->int_id_->_remove_ref ();
34
 
      entry->int_id_ = 0;
35
 
    }
36
 
}
37
 
 
38
 
// %! Thread issues
39
 
 
40
 
int
41
 
TAO_ValueFactory_Map::rebind (const char *repo_id,
42
 
                              CORBA::ValueFactory &factory)
43
 
{
44
 
//  ACE_READ_GUARD_RETURN (TAO_SYNCH_RW_MUTEX, guard, map_->mutex(),-1);
45
 
//   --- but must be recursive
46
 
  const char *prev_repo_id;
47
 
  CORBA::ValueFactory prev_factory;
48
 
  int ret = 0;
49
 
  ret = this->map_.rebind (CORBA::string_dup (repo_id),
50
 
                           factory,
51
 
                           prev_repo_id,
52
 
                           prev_factory);
53
 
 
54
 
  if (ret > -1)   // ok, no error
55
 
    {
56
 
      factory->_add_ref ();    // The map owns one reference.
57
 
 
58
 
      if (ret == 1)    // there was a previous factory
59
 
        {
60
 
          factory = prev_factory;
61
 
          CORBA::string_free (ACE_const_cast(char*,prev_repo_id));
62
 
        }
63
 
    }
64
 
 
65
 
  return ret;
66
 
}
67
 
 
68
 
int
69
 
TAO_ValueFactory_Map::unbind (const char *repo_id,
70
 
                              CORBA::ValueFactory &factory)
71
 
{
72
 
  FACTORY_MAP_MANAGER::ENTRY *prev_entry;
73
 
  int ret = 0;
74
 
  ret = this->map_.find (repo_id,
75
 
                         prev_entry);
76
 
  if (ret == 0)    // there was a matching factory
77
 
    {
78
 
      // set factory to the previous factory,
79
 
      factory = prev_entry->int_id_;
80
 
      char *temp = ACE_const_cast (char *, prev_entry->ext_id_);
81
 
      ret = this->map_.unbind (prev_entry);
82
 
 
83
 
      if (ret == 0)
84
 
        {
85
 
          CORBA::string_free (temp);
86
 
        }
87
 
    }
88
 
 
89
 
  return ret;
90
 
}
91
 
 
92
 
// %! perhaps inline
93
 
int
94
 
TAO_ValueFactory_Map::find (const char *repo_id,
95
 
                            CORBA::ValueFactory &factory)
96
 
{
97
 
  int ret = 0;
98
 
  ret = this->map_.find (repo_id,
99
 
                         factory);
100
 
  // %! this must be guarded to be atomic  !!!!!!!!!!!!!!!!!!
101
 
  if (ret > -1)
102
 
    {
103
 
      factory->_add_ref ();    // The caller gets one reference as gift.
104
 
    }
105
 
 
106
 
  return ret;
107
 
}
108
 
 
109
 
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
110
 
template class ACE_Hash_Map_Iterator_Base_Ex<const char *, CORBA::ValueFactoryBase *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_RW_MUTEX>;
111
 
template class ACE_Hash_Map_Iterator_Ex<const char *, CORBA::ValueFactoryBase *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_RW_MUTEX>;
112
 
template class ACE_Hash_Map_Reverse_Iterator_Ex<const char *, CORBA::ValueFactoryBase *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_RW_MUTEX>;
113
 
template class ACE_Hash_Map_Manager_Ex<const char *, CORBA::ValueFactoryBase *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_RW_MUTEX>;
114
 
template class ACE_Hash_Map_Entry<const char *, CORBA::ValueFactoryBase *>;
115
 
template class TAO_Singleton<TAO_ValueFactory_Map, TAO_SYNCH_MUTEX>;
116
 
 
117
 
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
118
 
#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<const char *, CORBA::ValueFactoryBase *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_RW_MUTEX>
119
 
#pragma instantiate ACE_Hash_Map_Iterator_Ex<const char *, CORBA::ValueFactoryBase *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_RW_MUTEX>
120
 
#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<const char *, CORBA::ValueFactoryBase *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_RW_MUTEX>
121
 
#pragma instantiate ACE_Hash_Map_Manager_Ex<const char *, CORBA::ValueFactoryBase *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_RW_MUTEX>
122
 
#pragma instantiate ACE_Hash_Map_Entry<const char *, CORBA::ValueFactoryBase *>
123
 
#pragma instantiate TAO_Singleton<TAO_ValueFactory_Map, TAO_SYNCH_MUTEX>
124
 
 
125
 
#elif defined (__GNUC__) && (defined (_AIX) || defined (__hpux) || defined (VXWORKS))
126
 
template TAO_Singleton<TAO_ValueFactory_Map, TAO_SYNCH_MUTEX> * TAO_Singleton<TAO_ValueFactory_Map, TAO_SYNCH_MUTEX>::singleton_;
127
 
 
128
 
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */