Make restoring from snapshots more efficient.
[cumulus.git] / ref.h
diff --git a/ref.h b/ref.h
index 496fdec..9a565ee 100644 (file)
--- a/ref.h
+++ b/ref.h
@@ -39,7 +39,8 @@
  * range specifier is given, then by default the entire object is used.
  *    <range> ::= <start> "+" <length>
  * Both <start> and <length> are decimal values.  If included, the range is
- * enclosed in brackets.
+ * enclosed in brackets.  As an abbreviation, if <start> is 0 then the range
+ * can be given as just <length> (no "+" needed).
  *
  * 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,12 +65,21 @@ 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);
 
     std::string get_segment() const { return segment; }
-    void set_segment(const std::string& segment) { this->segment = segment; }
+    std::string get_sequence() const { return object; }
+    std::string get_basename() const { return segment + "/" + object; }
 
     bool has_checksum() const { return checksum_valid; }
     std::string get_checksum() const { return checksum; }
@@ -84,7 +94,10 @@ public:
     void set_range(size_t start, size_t length)
         { range_start = start; range_length = length; range_valid = true; }
 
+    bool merge(ObjectReference ref);
+
 private:
+    RefType type;
     std::string segment, object, checksum;
     size_t range_start, range_length;
     bool checksum_valid, range_valid;