X-Git-Url: http://git.vrable.net/?p=cumulus.git;a=blobdiff_plain;f=ref.h;h=a27b4d6a1fedb0a373452a7128cff7e9fbf85332;hp=13eba9401c9e8beaa51910c4f6016e4616ee0f06;hb=f38dd9bcb0caffd3fc9126b05788c936690e8288;hpb=c26f44fe8cd3eeec0d9d849cb2e639d484de5887 diff --git a/ref.h b/ref.h index 13eba94..a27b4d6 100644 --- a/ref.h +++ b/ref.h @@ -1,7 +1,24 @@ -/* LBS: An LFS-inspired filesystem backup system - * Copyright (C) 2007 Michael Vrable +/* Cumulus: Smart Filesystem Backup to Dumb Servers * - * Backups are structured as a collection of objects, which may refer to other + * Copyright (C) 2007-2008 The Regents of the University of California + * Written by Michael Vrable + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* Backups are structured as a collection of objects, which may refer to other * objects. Object references are used to name other objects or parts of them. * This file defines the class for representing object references and the * textual representation of these references. */ @@ -38,8 +55,12 @@ * a substring rather than the entire string using a range specifier. If no * range specifier is given, then by default the entire object is used. * ::= "+" + * | + * | "=" * Both and are decimal values. If included, the range is - * enclosed in brackets. + * enclosed in brackets. As an abbreviation, if is 0 then the range + * can be given as just (no "+" needed). The "=" form asserts + * that the underlying object is exactly bytes in size. * * When both a checksum and a range are included, note that the checksum is * taken over the entire original object, before the range is taken into @@ -64,15 +85,22 @@ std::string generate_uuid(); * and converted to and from the text representation. */ class ObjectReference { public: + enum RefType { REF_NULL, REF_ZERO, REF_NORMAL }; + + ObjectReference(); + ObjectReference(RefType t); ObjectReference(const std::string& segment, int sequence); ObjectReference(const std::string& segment, const std::string& sequence); + bool is_null() const { return type == REF_NULL; } + bool is_normal() const { return type == REF_NORMAL; } std::string to_string() const; - static ObjectReference *parse(const std::string& s); + static ObjectReference parse(const std::string& s); std::string get_segment() const { return segment; } std::string get_sequence() const { return object; } std::string get_basename() const { return segment + "/" + object; } + ObjectReference base() const { return ObjectReference(segment, object); } bool has_checksum() const { return checksum_valid; } std::string get_checksum() const { return checksum; } @@ -83,14 +111,27 @@ public: bool has_range() const { return range_valid; } size_t get_range_start() const { return range_start; } size_t get_range_length() const { return range_length; } - void clear_range() { range_start = range_length = 0; range_valid = false; } - void set_range(size_t start, size_t length) - { range_start = start; range_length = length; range_valid = true; } + size_t get_range_exact() const { return range_exact; } + void clear_range() + { range_start = range_length = 0; + range_valid = false; range_exact = false; } + void set_range(size_t start, size_t length, bool exact = false) + { range_start = start; range_length = length; + range_valid = true; range_exact = exact; } + + bool merge(ObjectReference ref); + + // Maybe provide non-string implementations? + bool operator==(const ObjectReference &x) const + { return to_string() == x.to_string(); } + bool operator<(const ObjectReference &x) const + { return to_string() < x.to_string(); } private: + RefType type; std::string segment, object, checksum; size_t range_start, range_length; - bool checksum_valid, range_valid; + bool checksum_valid, range_valid, range_exact; }; #endif // _LBS_REF_H