extern const char *ceph_entity_type_name(int type);
-struct str_to_entity_type_t {
- uint32_t type;
- const char *str;
-};
-
-static const str_to_entity_type_t STR_TO_ENTITY_TYPE[] = {
+const std::array<EntityName::str_to_entity_type_t, 6> EntityName::STR_TO_ENTITY_TYPE = {{
{ CEPH_ENTITY_TYPE_AUTH, "auth" },
{ CEPH_ENTITY_TYPE_MON, "mon" },
{ CEPH_ENTITY_TYPE_OSD, "osd" },
{ CEPH_ENTITY_TYPE_MDS, "mds" },
{ CEPH_ENTITY_TYPE_MGR, "mgr" },
{ CEPH_ENTITY_TYPE_CLIENT, "client" },
-};
-
-EntityName::
-EntityName()
- : type(0)
-{
-}
+}};
const std::string& EntityName::
to_str() const
std::string EntityName::
get_valid_types_as_str()
{
- std::string out;
+ std::ostringstream out;
+ size_t i;
+ for (i = 0; i < STR_TO_ENTITY_TYPE.size(); ++i) {
+ if (i > 0) {
+ out << ", ";
+ }
+ out << STR_TO_ENTITY_TYPE[i].str;
+ }
+ return out.str();
+}
+
+uint32_t EntityName::str_to_ceph_entity_type(std::string_view s)
+{
size_t i;
- std::string sep("");
- for (i = 0; i < sizeof(STR_TO_ENTITY_TYPE)/sizeof(STR_TO_ENTITY_TYPE[0]); ++i) {
- out += sep;
- out += STR_TO_ENTITY_TYPE[i].str;
- sep = ", ";
+ for (i = 0; i < STR_TO_ENTITY_TYPE.size(); ++i) {
+ if (s == STR_TO_ENTITY_TYPE[i].str)
+ return STR_TO_ENTITY_TYPE[i].type;
}
- return out;
+ return CEPH_ENTITY_TYPE_ANY;
}
bool operator<(const EntityName& a, const EntityName& b)
{
return out << n.to_str();
}
-
-uint32_t str_to_ceph_entity_type(const char * str)
-{
- size_t i;
- for (i = 0; i < ARRAY_SIZE(STR_TO_ENTITY_TYPE); ++i) {
- if (strcmp(str, STR_TO_ENTITY_TYPE[i].str) == 0)
- return STR_TO_ENTITY_TYPE[i].type;
- }
- return CEPH_ENTITY_TYPE_ANY;
-}
#include "msg/msg_types.h"
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
-
/* Represents a Ceph entity name.
*
* For example, mds.0 is the name of the first metadata server.
*/
struct EntityName
{
- EntityName();
-
void encode(bufferlist& bl) const {
using ceph::encode;
encode(type, bl);
bool has_default_id() const;
static std::string get_valid_types_as_str();
+ static uint32_t str_to_ceph_entity_type(std::string_view);
friend bool operator<(const EntityName& a, const EntityName& b);
friend std::ostream& operator<<(std::ostream& out, const EntityName& n);
friend bool operator!=(const EntityName& a, const EntityName& b);
private:
- uint32_t type;
+ struct str_to_entity_type_t {
+ uint32_t type;
+ const char *str;
+ };
+ static const std::array<str_to_entity_type_t, 6> STR_TO_ENTITY_TYPE;
+
+ uint32_t type = 0;
std::string id;
std::string type_id;
};
-uint32_t str_to_ceph_entity_type(const char * str);
-
WRITE_CLASS_ENCODER(EntityName)
WRITE_EQ_OPERATORS_2(EntityName, type, id)
*/
int encode_utf8(unsigned long u, unsigned char *buf)
{
- int i;
- unsigned long max_val[MAX_UTF8_SZ] = {
+ static const unsigned long max_val[MAX_UTF8_SZ] = {
0x0000007ful, 0x000007fful, 0x0000fffful,
0x001ffffful, 0x03fffffful, 0x7ffffffful
};
- static const int MAX_VAL_SZ = ARRAY_SIZE(max_val);
+ static const int MAX_VAL_SZ = sizeof(max_val)/sizeof(max_val[0]);
+ int i;
for (i = 0; i < MAX_VAL_SZ; ++i) {
if (u <= max_val[i])
break;