summaryrefslogtreecommitdiff
path: root/orbsvcs/orbsvcs/FtRtEvent/EventChannel/replace_key.cpp
blob: 4b684ac136b37b3ab053e97fd72ef6c5545e124f (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
// $Id$

#include "ace/OS_NS_string.h"
#include "ace/Log_Msg.h"
#include "tao/Object_KeyC.h"
#include <algorithm>

/// This function was defined in IOGR_Maker.cpp. It is moved
/// here because the use of <algorithm> header
/// file conflicts with the use of auto_ptr in the
/// VxWorks5.5.1_PPC85XX_DIAB platform.

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

void replace_key(char* ior, char* end_ior,
                 const TAO::ObjectKey& oldkey,
                 const TAO::ObjectKey& newkey)
{
  size_t keylen = oldkey.length();
  ACE_ASSERT(keylen == newkey.length());

  char* pos = ior;
  const char* oldkey_begin = (const char*)oldkey.get_buffer();
  const char* oldkey_end = oldkey_begin + keylen;

  while ((pos = std::search(pos, end_ior,oldkey_begin, oldkey_end)) != end_ior) {
    ACE_OS::memcpy(pos, newkey.get_buffer(), keylen);
    pos+= keylen;
  }
}

TAO_END_VERSIONED_NAMESPACE_DECL