summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2012-04-05 15:54:00 +0000
committerAlan Conway <aconway@apache.org>2012-04-05 15:54:00 +0000
commit37ca4d90a45d04caeadee3154efe7764447fe47d (patch)
tree7da9ff05bf09ce85c2b29f6bad7a4f3e1b4a6dbc /cpp/src
parent2f331f7e5b25a359db95a62298477925ec0830c7 (diff)
downloadqpid-python-37ca4d90a45d04caeadee3154efe7764447fe47d.tar.gz
NO-JIRA: Fix a static-initialization bug in the HaPlugin.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1309913 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/ha/ReplicateLevel.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/cpp/src/qpid/ha/ReplicateLevel.cpp b/cpp/src/qpid/ha/ReplicateLevel.cpp
index 48f21a1f66..2c3614bb63 100644
--- a/cpp/src/qpid/ha/ReplicateLevel.cpp
+++ b/cpp/src/qpid/ha/ReplicateLevel.cpp
@@ -21,18 +21,21 @@
#include "ReplicateLevel.h"
#include "qpid/Exception.h"
#include <iostream>
+#include <assert.h>
namespace qpid {
namespace ha {
using namespace std;
+// Note replicateLevel is called during plugin-initialization which
+// happens in the static construction phase so these constants need
+// to be POD, they can't be class objects
+//
namespace {
-const string S_NONE="none";
-const string S_CONFIGURATION="configuration";
-const string S_ALL="all";
-
-string names[] = { S_NONE, S_CONFIGURATION, S_ALL };
+const char* S_NONE="none";
+const char* S_CONFIGURATION="configuration";
+const char* S_ALL="all";
}
bool replicateLevel(const string& level, ReplicateLevel& out) {
@@ -44,14 +47,22 @@ bool replicateLevel(const string& level, ReplicateLevel& out) {
ReplicateLevel replicateLevel(const string& level) {
ReplicateLevel rl;
- if (!replicateLevel(level, rl))
+ if (!replicateLevel(level, rl)) {
+ assert(0);
throw Exception("Invalid value for replication level: "+level);
+ }
return rl;
}
-string str(ReplicateLevel l) { return names[l]; }
+string str(ReplicateLevel l) {
+ const char* names[] = { S_NONE, S_CONFIGURATION, S_ALL };
+ assert(l >= RL_NONE);
+ assert(l <= RL_ALL);
+ return names[l];
+}
ostream& operator<<(ostream& o, ReplicateLevel rl) { return o << str(rl); }
+
istream& operator>>(istream& i, ReplicateLevel& rl) {
string str;
i >> str;