Commits

Jens Alfke  committed f0d86ec

A bit more cleanup before the public release.

  • Participants
  • Parent commits f284b0b

Comments (0)

Files changed (9)

+# Fudge-Cpp #
+
+by Jens Alfke -- (c)2011
+
+**Fudge-Cpp** is a C++ library for reading and writing [Fudge](http://fudgemsg.org/), "a binary messaging system designed to scale from ad-hoc messages to long-term persistance." Fudge is somewhat similar in semantics to JSON, but uses a binary encoding that's more compact and faster to parse.
+
+Fudge-Cpp's advantages over the existing Fudge-C library are:
+
+* Simpler, idiomatic C++ API using classes.
+* Integrates with STL and iostreams.
+* Uses less memory -- in fact, it allocates _no heap space at all_ unless you use STL string accessors. When you access the fields in a message, the objects returned to you are really pointers directly into the existing binary message data. When you write a message, the library writes directly to the output stream without needing any heap space for bookkeeping.
+
+**Fudge-Cpp** is intended to be cross-platform, but the current version still has some OS X dependencies, primarily for byte-swapping. Fixes for these are welcome :)

File fudge/message.h

 #pragma once
 #include <string>
 
-
 namespace fudge {
 
-    
 class Field;
 class Message;
 class IntArray;
     friend class Writer;
     Envelope(uint8_t schema, uint16_t taxonomy);
     
+    // Members must be laid out exactly as in the Encoding Specification.
     uint8_t  _processingDirectives;
     uint8_t  _schemaVersion;
     uint16_t _taxonomy;
     bool validate() const   {return validate(end());}
     
     class iterator {
-    public:
+      public:
         operator const Field*()            {return _current;}
         const Field& operator*() const     {return *_current;}
         const Field* operator->() const    {return _current;}
         iterator& operator++();
         bool operator==(iterator i) const   {return _current == i._current;}
         
-    private:
+      private:
         friend class Message;
         iterator(const Field* field) :_current(field) { }
         const Field* _current;

File src/array.cpp

 #include "fudge/array.h"
 #include "internal.h"
 #include <assert.h>
-#include <math.h>
-#include <CoreFoundation/CFByteOrder.h>
 
 
 namespace fudge {
 
     
 }
+
+
+/*
+ Copyright (c) 2011, Jens Alfke <jens@mooseyard.com>. All rights reserved.
+ 
+ Redistribution and use in source and binary forms, with or without modification, are permitted
+ provided that the following conditions are met:
+ 
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ and the following disclaimer in the documentation and/or other materials provided with the
+ distribution.
+ 
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
+ BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
+  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */

File src/dump.cpp

 
 #include "fudge/dump.h"
 #include "fudge/message.h"
-#include <algorithm>
 #include <sstream>
 
 namespace fudge {
 }
     
 }
+
+
+/*
+ Copyright (c) 2011, Jens Alfke <jens@mooseyard.com>. All rights reserved.
+ 
+ Redistribution and use in source and binary forms, with or without modification, are permitted
+ provided that the following conditions are met:
+ 
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ and the following disclaimer in the documentation and/or other materials provided with the
+ distribution.
+ 
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
+ BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
+  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */

File src/json.cpp

 #include "fudge/json.h"
 #include "fudge/message.h"
 #include "fudge/array.h"
-#include <algorithm>
 #include <sstream>
 
 namespace fudge {
 }
     
 }
+
+
+/*
+ Copyright (c) 2011, Jens Alfke <jens@mooseyard.com>. All rights reserved.
+ 
+ Redistribution and use in source and binary forms, with or without modification, are permitted
+ provided that the following conditions are met:
+ 
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ and the following disclaimer in the documentation and/or other materials provided with the
+ distribution.
+ 
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
+ BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
+  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */

File src/message.cpp

 #include "fudge/message.h"
 #include "fudge/array.h"
 #include "internal.h"
-#include <assert.h>
-#include <math.h>
-
-#include <CoreFoundation/CFByteOrder.h>
 
 
 namespace fudge {
     return Message(data);
 }
 
-}
+}
+
+/*
+ Copyright (c) 2011, Jens Alfke <jens@mooseyard.com>. All rights reserved.
+ 
+ Redistribution and use in source and binary forms, with or without modification, are permitted
+ provided that the following conditions are met:
+ 
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ and the following disclaimer in the documentation and/or other materials provided with the
+ distribution.
+ 
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
+ BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
+  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */

File src/writer.cpp

 #include "fudge/writer.h"
 #include "internal.h"
 #include <assert.h>
-#include <math.h>
 #include <ostream>
 
-#include <CoreFoundation/CFByteOrder.h>
-
 
 namespace fudge {
 
 }
 
 }
+
+
+/*
+ Copyright (c) 2011, Jens Alfke <jens@mooseyard.com>. All rights reserved.
+ 
+ Redistribution and use in source and binary forms, with or without modification, are permitted
+ provided that the following conditions are met:
+ 
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
+ and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ and the following disclaimer in the documentation and/or other materials provided with the
+ distribution.
+ 
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
+ BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
+  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */

File test/TestExamples.cpp

 
 // Helper class for reading (mapping) the contents of a file into a Data object.
 class FileData : public Data {
-public:
+  public:
     FileData(string path)
     : _fd(-1)
     {
             close(_fd);
     }
     
-private:
+  private:
     int _fd;
 };
 
 
-// Ick. This is platform specific (Xcode puts the binary in a build/Debug subfolder that
+// FIX: Ick. This is platform specific (Xcode puts the binary in a build/Debug subfolder that
 // we then have to crawl out of to find the test_data folder at the top level.)
 static const string kTestFileDir("../../test/test_data/");
 

File test/TestNested.cpp

 
 
 #include <gtest/gtest.h>
-#include <math.h>
 
 #include <iostream>
 #include <sstream>