summaryrefslogtreecommitdiff
path: root/examples/APG/Naming/Naming_Context.h
blob: abcf793b2b689defad8604e803f538d9d3c15293 (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
/* -*- C++ -*- */
// $Id$

#ifndef NAMING_CONTEXT_H
#define NAMING_CONTEXT_H

#include "ace/Naming_Context.h"
#include "ace/OS_NS_stdio.h"
#include "Name_Binding.h"

// Listing 1 code/ch21
class Naming_Context : public ACE_Naming_Context
{
public:
  typedef ACE_Naming_Context inherited;

  int rebind (const char *name_in,
              const char *value_in,
              const char *type_in = "")
  {
    return this->inherited::rebind (name_in, value_in, type_in);
  }

  int rebind (const char *name_in,
              float value_in,
              const char *type_in = "")
  {
    char buf[BUFSIZ];
    ACE_OS::sprintf (buf, "%2f", value_in);
    return this->inherited::rebind (name_in,
                                    (const char *)buf,
                                    type_in);
  }

  int rebind (const char *name_in,
              int value_in,
              const char *type_in = "")
  {
    char buf[BUFSIZ];
    ACE_OS::sprintf (buf, "%d", value_in );
    return this->inherited::rebind (name_in,
                                    (const char *)buf,
                                    type_in);
  }
  // Listing 1

  // Listing 2 code/ch21
  Name_Binding *fetch (const char *name)
  {
    ACE_NS_WString value;
    char *type;

    if (this->resolve (name, value, type) != 0 ||
        value.length () < 1)
      {
        return 0;
      }

    Name_Binding *rval =
      new Name_Binding (ACE_NS_WString (name),
                        value,
                        type);
    return rval;
  }
// Listing 2
};

#endif /* NAMING_CONTEXT_H */