You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2012/04/05 17:54:01 UTC
svn commit: r1309913 - /qpid/trunk/qpid/cpp/src/qpid/ha/ReplicateLevel.cpp
Author: aconway
Date: Thu Apr 5 15:54:00 2012
New Revision: 1309913
URL: http://svn.apache.org/viewvc?rev=1309913&view=rev
Log:
NO-JIRA: Fix a static-initialization bug in the HaPlugin.
Modified:
qpid/trunk/qpid/cpp/src/qpid/ha/ReplicateLevel.cpp
Modified: qpid/trunk/qpid/cpp/src/qpid/ha/ReplicateLevel.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/ha/ReplicateLevel.cpp?rev=1309913&r1=1309912&r2=1309913&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/ha/ReplicateLevel.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/ha/ReplicateLevel.cpp Thu Apr 5 15:54:00 2012
@@ -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 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;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org