Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / CSD_Framework / CSD_Strategy_Repository.cpp
blobd45afff0876ed7db5241a79df0a8e8fef2897a3a
1 // -*- C++ -*-
2 #include "tao/CSD_Framework/CSD_Strategy_Repository.h"
3 #include "tao/debug.h"
5 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
7 TAO_CSD_Strategy_Repository::TAO_CSD_Strategy_Repository() :
8 strategy_list_head_ (0)
13 TAO_CSD_Strategy_Repository::~TAO_CSD_Strategy_Repository()
15 delete this->strategy_list_head_;
18 int
19 TAO_CSD_Strategy_Repository::init(int, ACE_TCHAR **)
21 static int initialized = 0;
23 // Only allow initialization once.
24 if (initialized)
25 return 0;
27 initialized = 1;
28 this->strategy_list_head_ = 0;
29 return 0;
32 CSD_Framework::Strategy_ptr
33 TAO_CSD_Strategy_Repository::find (const ACE_CString& name)
35 if (this->strategy_list_head_ != 0)
37 Strategy_Node *node = this->strategy_list_head_->find(name);
38 if (node != 0)
39 return CSD_Framework::Strategy::_duplicate (node->strategy_.in());
42 return CSD_Framework::Strategy::_nil();
46 int
47 TAO_CSD_Strategy_Repository::add_strategy (const ACE_CString& name,
48 CSD_Framework::Strategy_ptr strat)
50 Strategy_Node *node = 0;
51 ACE_NEW_RETURN (node, Strategy_Node(name,strat),-1);
52 if (this->strategy_list_head_ == 0)
53 this->strategy_list_head_ = node;
54 else
55 this->strategy_list_head_->add_node(node);
57 if (TAO_debug_level > 3)
59 TAOLIB_DEBUG ((LM_DEBUG,
60 ACE_TEXT("Strategy_Repository::add_strategy for %C\n"),
61 name.c_str ()));
63 return 0;
66 TAO_CSD_Strategy_Repository::Strategy_Node::Strategy_Node (const ACE_CString& name,
67 CSD_Framework::Strategy_ptr strat)
68 : poa_name_(name),
69 strategy_(CSD_Framework::Strategy::_duplicate(strat)),
70 next_(0)
74 TAO_CSD_Strategy_Repository::Strategy_Node::~Strategy_Node ()
76 if (this->next_)
77 delete this->next_;
80 void
81 TAO_CSD_Strategy_Repository::Strategy_Node::add_node(Strategy_Node *node)
83 if (this->next_)
84 this->next_->add_node(node);
85 else
86 this->next_ = node;
89 TAO_CSD_Strategy_Repository::Strategy_Node *
90 TAO_CSD_Strategy_Repository::Strategy_Node::find(const ACE_CString &name)
92 if (this->poa_name_ == name)
93 return this;
94 if (this->next_)
95 return this->next_->find(name);
96 return 0;
100 /////////////////////////////////////////////////////////////////////
102 ACE_FACTORY_DEFINE (TAO_CSD_FW, TAO_CSD_Strategy_Repository)
103 ACE_STATIC_SVC_DEFINE (TAO_CSD_Strategy_Repository,
104 ACE_TEXT ("TAO_CSD_Strategy_Repository"),
105 ACE_SVC_OBJ_T,
106 &ACE_SVC_NAME (TAO_CSD_Strategy_Repository),
107 ACE_Service_Type::DELETE_THIS
108 | ACE_Service_Type::DELETE_OBJ,
110 TAO_END_VERSIONED_NAMESPACE_DECL