Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / orbsvcs / ImplRepo_Service / ImR_Utils.cpp
blob1fb777c52878d5c7011386d0f292aa993b4e7038
1 #include "utils.h"
2 #include "ImplRepoC.h"
4 #include "ace/SString.h"
6 const char *
7 ImR_Utils::activationModeToString (ImplementationRepository::ActivationMode mode)
9 switch (mode)
11 case ImplementationRepository::NORMAL:
12 return "NORMAL";
13 case ImplementationRepository::MANUAL:
14 return "MANUAL";
15 case ImplementationRepository::PER_CLIENT:
16 return "PER_CLIENT";
17 case ImplementationRepository::AUTO_START:
18 return "AUTO_START";
19 default:
20 ACE_ASSERT(mode == ImplementationRepository::NORMAL);
21 return "";
25 ImplementationRepository::ActivationMode
26 ImR_Utils::stringToActivationMode (const ACE_CString& s)
28 if (s == "NORMAL")
29 return ImplementationRepository::NORMAL;
30 if (s == "MANUAL")
31 return ImplementationRepository::MANUAL;
32 if (s == "PER_CLIENT")
33 return ImplementationRepository::PER_CLIENT;
34 if (s == "AUTO_START")
35 return ImplementationRepository::AUTO_START;
37 return ImplementationRepository::NORMAL;
40 const char *
41 ImR_Utils::envListToString(const ImplementationRepository::EnvironmentList& lst)
43 static ACE_CString ret;
44 ret = "";
45 for (CORBA::ULong n = 0; n < lst.length(); ++n)
47 ret += "name=\"";
48 ret += lst[n].name.in();
49 ret += "\" value=\"";
50 ret += lst[n].value.in();
51 ret += "\"\n";
53 return ret.c_str();
56 void
57 ImR_Utils::stringToEnvList(const ACE_CString& s,
58 ImplementationRepository::EnvironmentList& ret)
60 const ACE_CString NAMETAG = "name=\"";
61 const ACE_CString VALTAG = "value=\"";
62 const ACE_CString ENDTAG = "\"";
64 size_t pos = 0;
65 size_t start = 0;
67 CORBA::ULong idx = 0;
68 for (pos = s.find ('\n'); pos != ACE_CString::npos; pos = s.find ('\n',pos + 1))
70 idx++;
72 ret.length (idx);
73 if (idx == 0)
75 return;
78 ACE_CString source = s;
79 for (idx = 0; idx < ret.length () ;idx++)
81 pos = source.find ("\n");
82 ACE_CString entry = source.substr (0,pos);
83 source = source.substr (pos + 1);
84 ret[idx].name = "";
85 ret[idx].value = "";
87 if ((start = entry.find (NAMETAG)) == ACE_CString::npos)
88 continue;
89 start += NAMETAG.length();
90 if ((pos = entry.find (ENDTAG, start + 1)) == ACE_CString::npos)
91 continue;
92 ret[idx].name = entry.substr (start, pos - start).c_str();
95 if ((start = entry.find (VALTAG, pos)) == ACE_CString::npos)
96 continue;
97 start += VALTAG.length ();
98 if ((pos = entry.find (ENDTAG, start + 1)) == ACE_CString::npos)
99 continue;
100 ret[idx].value = entry.substr (start, pos - start).c_str();
104 const char *
105 ImR_Utils::peerListToString (const CORBA::StringSeq& lst)
107 static ACE_CString ret;
108 ret = "";
109 for (CORBA::ULong n = 0; n < lst.length(); ++n)
111 ret += "name=\"";
112 ret += lst[n].in();
113 ret += "\"\n";
115 return ret.c_str();
118 void
119 ImR_Utils::stringToPeerList (const ACE_CString& s, CORBA::StringSeq& ret)
121 const ACE_CString NAMETAG = "name=\"";
122 const ACE_CString ENDTAG = "\"";
124 size_t pos = 0;
125 size_t start = 0;
127 CORBA::ULong idx = 0;
128 for (pos = s.find ('\n'); pos != ACE_CString::npos; pos = s.find ('\n',pos + 1))
130 idx++;
132 ret.length (idx);
133 if (idx == 0)
135 return;
138 ACE_CString source = s;
139 for (idx = 0; idx < ret.length () ;idx++)
141 pos = source.find ("\n");
142 ACE_CString entry = source.substr (0,pos);
143 source = source.substr (pos + 1);
144 ret[idx] = "";
146 if ((start = entry.find (NAMETAG)) == ACE_CString::npos)
147 continue;
148 start += NAMETAG.length();
149 if ((pos = entry.find (ENDTAG, start + 1)) == ACE_CString::npos)
150 continue;
151 ret[idx] = entry.substr (start, pos - start).c_str();