Sort-of-working statcache implementation.
[cumulus.git] / ref.cc
diff --git a/ref.cc b/ref.cc
index e996c7d..84b631c 100644 (file)
--- a/ref.cc
+++ b/ref.cc
@@ -28,6 +28,10 @@ string generate_uuid()
     return string(buf);
 }
 
+ObjectReference::ObjectReference()
+    : segment(""), object("")
+{
+}
 
 ObjectReference::ObjectReference(const std::string& segment, int sequence)
     : segment(segment)
@@ -40,6 +44,14 @@ ObjectReference::ObjectReference(const std::string& segment, int sequence)
     clear_range();
 }
 
+ObjectReference::ObjectReference(const std::string& segment,
+                                 const std::string& sequence)
+    : segment(segment), object(sequence)
+{
+    clear_checksum();
+    clear_range();
+}
+
 string ObjectReference::to_string() const
 {
     string result = segment + "/" + object;
@@ -55,3 +67,26 @@ string ObjectReference::to_string() const
 
     return result;
 }
+
+/* Parse a string object reference and return a pointer to a new
+ * ObjectReference.  The caller is responsible for freeing the object.  NULL is
+ * returned if there is an error in the syntax. */
+ObjectReference *ObjectReference::parse(const std::string& str)
+{
+    const char *s = str.c_str();
+    const char *t;
+
+    // Segment
+    t = strchr(s, '/');
+    if (t == NULL)
+        return NULL;
+    string segment(s, t - s);
+
+    // Object sequence number
+    s = t + 1;
+    string object(s);
+
+    // TODO: Checksums, ranges.
+
+    return new ObjectReference(segment, object);
+}