diff -r 000000000000 -r 6cbad782d16a include/Ottoman.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/Ottoman.h	Sun Sep 20 20:39:24 2009 -0700
@@ -0,0 +1,99 @@
+/*
+ *  Ottoman.h
+ *  Ottoman
+ *
+ *  Created by Jens Alfke on 8/31/09.
+ *  Copyright 2009 Jens Alfke. All rights reserved.
+ *  BSD-Licensed: See the file "LICENSE.txt" for details.
+ */
+
+#ifndef _MOOSEYARD_OTTOMAN_
+#define _MOOSEYARD_OTTOMAN_
+
+namespace Mooseyard {
+    
+    class ChunkIterator;
+    class Dictionary;
+    class File;
+    class VersionDictionary;
+    class OverlayDictionary;
+    
+    
+    /** A version-controlled persistent dictionary. 
+        Each version is stored as a VersionDictionary, unsaved changes as an OverlayDictionary. */
+    class Ottoman {
+    public:
+        /** Creates an "untitled" Ottoman with no file and no lastVersion.
+            After adding values to the currentVersion, use saveAs to save it. */
+        Ottoman ();
+        
+        /** Opens an existing Ottoman file. */
+        explicit Ottoman (const char *filename, bool writeable =true);
+        
+        /** Closes an Ottoman. */
+        virtual ~Ottoman();
+        
+        /** The current filename, or NULL if the receiver is still in the "untitled" state. */
+        virtual const char* filename() const                {return _filename;}
+        
+        /** The latest saved version of the dictionary. 
+            Earlier versions can be accessed through its previousVersion() accessor.
+            This will be NULL if the receiver is still in the "untitled" state. */
+        virtual VersionDictionary* lastVersion() const         {return _lastVersion;}
+        
+        /** A mutable overlay representing the current state of the dictionary.
+            Changes are made in memory until save() is called.
+            This will be NULL if the receiver was opened read-only (writeable=false). */
+        virtual OverlayDictionary* currentVersion() const   {return _current;}
+        
+        /** Has the on-disk file been updated with newer revisions than what I know about? */
+        virtual bool needsSync() const;
+        
+        /** Reads any newer versions from disk.
+            Returns true if new versions were read, false if there were none.
+            Afterwards, lastVersion() will return the latest version in the file. 
+            (The old lastVersion dictionary is still around, so you can save a pointer to it 
+            before the call and use it later to see what changed.)
+            Changes made to the currentVersion dictionary are not lost, but are now relative
+            to the new lastVersion. You may want to scan them and resolve conflicts. */
+        virtual bool sync();
+        
+        /** Saves the current version to the file, by appending.
+            Returns false if there is a version conflict; in that case you need to call sync(),
+            possibly resolve conflicts, and then call save() again. */
+        virtual bool save();
+        
+        /** Saves the current version to the file, by writing to a new temporary file and
+            then atomically replacing the original. 
+            Older versions, and older copies of the data, are not preserved, so this
+            will typically shrink the file quite a bit.
+            Returns false if there is a version conflict. */
+        virtual bool saveAndCompact();
+         
+        /** Saves the current version to a new file, leaving the new file open, 
+            so subsequent saves will be written to it. */
+        virtual void saveAs (const char *newFilename, bool overwriteAllowed =true);
+        
+        /** Scans the file for damage. Returns true if the file is OK, false if problems are found.
+            If the 'repair' flag is set, will truncate the file to the last valid version. */
+        bool scavenge (bool repair =false);
+        
+        ChunkIterator* chunkIterator() const;       // for testing purposes
+
+    private:
+        Ottoman(const Ottoman&);            // forbid copying/assignment
+        Ottoman& operator=(const Ottoman&);
+        
+        void _open();
+        void _append (File *dstFile);
+        File* _writeTo (const char *dstFileName, bool overwriteAllowed);
+        
+        bool _writeable;
+        File *_file;
+        char *_filename;
+        VersionDictionary *_lastVersion;
+        OverlayDictionary *_current;
+    };
+    
+}
+#endif // _MOOSEYARD_OTTOMAN_