1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 Adam Crume <adamcrume@gmail.com>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "rbd_loc.hpp"
16 #include "include/assert.h"
20 using namespace rbd_replay;
26 rbd_loc::rbd_loc(string pool, string image, string snap)
32 bool rbd_loc::parse(string name_string) {
35 bool read_slash = false;
37 for (size_t i = 0, n = name_string.length(); i < n; i++) {
38 char c = name_string[i];
41 if (read_slash || read_at) {
60 fields[field].push_back(name_string[++i]);
63 fields[field].push_back(c);
70 // note that if read_at is false, then fields[2] is the empty string,
71 // so this is still correct
76 // note that if read_at is false, then fields[1] is the empty string,
77 // so this is still correct
84 static void write(const string &in, string *out) {
85 for (size_t i = 0, n = in.length(); i < n; i++) {
87 if (c == '@' || c == '/' || c == '\\') {
94 string rbd_loc::str() const {
108 int rbd_loc::compare(const rbd_loc& rhs) const {
109 int c = pool.compare(rhs.pool);
113 c = image.compare(rhs.image);
117 c = snap.compare(rhs.snap);
124 bool rbd_loc::operator==(const rbd_loc& rhs) const {
125 return compare(rhs) == 0;
128 bool rbd_loc::operator<(const rbd_loc& rhs) const {
129 return compare(rhs) < 0;