1 | /* |
---|
2 | * $Id: Instance_getLink.cpp 97 2008-12-19 15:34:00Z rosiere $ |
---|
3 | * |
---|
4 | * [ Description ] |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #include "Behavioural/Configuration/include/Instance.h" |
---|
9 | |
---|
10 | namespace morpheo { |
---|
11 | namespace behavioural { |
---|
12 | namespace configuration { |
---|
13 | |
---|
14 | #undef FUNCTION |
---|
15 | #define FUNCTION "Instance::getLink" |
---|
16 | std::vector<std::string> Instance::getLink (const char * name, ...) |
---|
17 | { |
---|
18 | log_begin(Configuration,FUNCTION); |
---|
19 | |
---|
20 | std::string src = ""; |
---|
21 | std::string dest; |
---|
22 | |
---|
23 | // Create src id |
---|
24 | { |
---|
25 | va_list args; |
---|
26 | va_start(args, name); |
---|
27 | |
---|
28 | std::string tmp; |
---|
29 | while ((tmp = va_arg(args,const char *)) != "") |
---|
30 | { |
---|
31 | if (src == "") |
---|
32 | src = tmp; |
---|
33 | else |
---|
34 | src += "." + tmp; |
---|
35 | } |
---|
36 | va_end(args); |
---|
37 | } |
---|
38 | |
---|
39 | // Find link |
---|
40 | bool find = true; |
---|
41 | |
---|
42 | { |
---|
43 | // find link |
---|
44 | list_links_t::iterator it1=_list_links->find(name); |
---|
45 | |
---|
46 | if (it1 == _list_links->end()) |
---|
47 | { |
---|
48 | // log_printf(INFO,Configuration,FUNCTION,_("Link \"%s\" is not define, don't link."),name); |
---|
49 | find = false; |
---|
50 | } |
---|
51 | else |
---|
52 | { |
---|
53 | // Find src |
---|
54 | list_link_t::iterator it2=it1->second.find(src); |
---|
55 | |
---|
56 | if (it2 == it1->second.end()) |
---|
57 | { |
---|
58 | // log_printf(INFO,Configuration,FUNCTION,_("Link \"%s[%s]\" is not define, don't link."),name,src.c_str()); |
---|
59 | find = false; |
---|
60 | } |
---|
61 | else |
---|
62 | { |
---|
63 | if (it2->second->_use) |
---|
64 | throw ERRORMORPHEO(FUNCTION,toString(_("Link \"%s[%s]\" is already used.\n"),name,src.c_str())); |
---|
65 | |
---|
66 | dest = it2->second->_dest; |
---|
67 | it2->second->_use = true; // now, this parameters is use |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | std::vector<std::string> _return; |
---|
73 | if (find) |
---|
74 | { |
---|
75 | _return = link2array(dest); |
---|
76 | //log_printf(INFO,Configuration,FUNCTION,_("Link \"%s[%s]\"= %s."),name,src.c_str(),dest.c_str()); |
---|
77 | } |
---|
78 | else |
---|
79 | { |
---|
80 | _return.clear(); |
---|
81 | //log_printf(INFO,Configuration,FUNCTION,_("Link \"%s[%s]\" not find."),name,src.c_str()); |
---|
82 | } |
---|
83 | |
---|
84 | log_end(Configuration,FUNCTION); |
---|
85 | |
---|
86 | return _return; |
---|
87 | }; |
---|
88 | |
---|
89 | }; // end namespace configuration |
---|
90 | }; // end namespace behavioural |
---|
91 | }; // end namespace morpheo |
---|