summaryrefslogtreecommitdiff
path: root/DAnCE/tools/Config_Handlers/Dump_Obj.cpp
blob: f33ce9c49130e63e1eed27d7f83ab3d9d3bac1fe (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
#include "Dump_Obj.h"
#include "ace/Log_Msg.h"
#include "dance/Logger/Log_Macros.h"

namespace Deployment
{
  // static member initialization
  std::string Dump_Obj::indent_ = "-";
  std::map<std::string, CORBA::Any> Dump_Obj::desc_map_;

  Dump_Obj::Dump_Obj(const char* caption)
    : desc_()
  {
    DANCE_TRACE ("Dump_Obj::constructor");

    DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR,
      (LM_DEBUG, "%C%C:\n", indent_.c_str(), caption));
    indent_.append("  ");
  }


  Dump_Obj::Dump_Obj(const char* caption,
                      CORBA::Any &val)
    : desc_(caption)
  {
    DANCE_TRACE ("Dump_Obj::constructor");

    DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR, (LM_DEBUG, "%C%C:\n",
                indent_.c_str(),
                caption));

    indent_.append("   ");

    if (desc_map_.find (std::string (caption)) != desc_map_.end())
      {
        DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR, (LM_DEBUG, "DnC_Dump.cpp:Dump_Obj -"\
                          " The item with name %C is already in" \
                          " the node map.\n", caption));
        throw Node_Exist();
      }
    else
      {
        desc_map_[std::string(caption)] = val;
      }
  }

  Dump_Obj::~Dump_Obj()
  {
    DANCE_TRACE ("Dump_Obj::destructor");

    indent_.erase(indent_.size() - 2, 2);
    if (desc_.size() != 0)
      {
        if (desc_map_.find(desc_) != desc_map_.end())
          {
            desc_map_.erase(desc_map_.find(desc_));
          }
        else
          {
            DANCE_DEBUG (DANCE_LOG_TERMINAL_ERROR,
              (LM_DEBUG, "DnC_Dump.cpp:Dump_Obj -"\
                        " The item with name %C is not in the node map.\n",
                        desc_.c_str()));
            throw Node_Not_Exist();
          }
      }
  }
}