浏览代码

Adding json and expect submodules
Removing unneeded util files.
Updating vector and matrix to use expects()

Samuel Jaffe 9 年之前
父节点
当前提交
1204b2893f
共有 12 个文件被更改,包括 47 次插入68 次删除
  1. 1 0
      .gitignore
  2. 10 0
      .gitmodules
  3. 1 0
      include/expect
  4. 1 0
      include/json
  5. 2 2
      math/math.xcodeproj/project.pbxproj
  6. 6 6
      math/matrix.hpp
  7. 5 5
      math/vector.hpp
  8. 0 32
      util/expect.hpp
  9. 0 8
      util/gameutils.xcodeproj/project.pbxproj
  10. 20 0
      util/identity.hpp
  11. 0 14
      util/macro.h
  12. 1 1
      util/scope_exit.hpp

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.*_tc.cpp

+ 10 - 0
.gitmodules

@@ -0,0 +1,10 @@
+[submodule "include/stb"]
+	path = include/stb
+	url = https://github.com/nothings/stb.git
+[submodule "include/json"]
+	path = include/json
+	url = freenas:utility/json
+[submodule "include/expect"]
+	path = include/expect
+	url = freenas:utility/expect
+	branch = master

+ 1 - 0
include/expect

@@ -0,0 +1 @@
+Subproject commit 08408ea5c1358ff5a951c1ca755947974a8736fe

+ 1 - 0
include/json

@@ -0,0 +1 @@
+Subproject commit 357524597efe513068eec2e31a82dc976c31d085

+ 2 - 2
math/math.xcodeproj/project.pbxproj

@@ -398,7 +398,7 @@
 				GCC_ENABLE_CPP_RTTI = YES;
 				GCC_SYMBOLS_PRIVATE_EXTERN = YES;
 				PRODUCT_NAME = "$(TARGET_NAME)";
-				USER_HEADER_SEARCH_PATHS = ..;
+				USER_HEADER_SEARCH_PATHS = ".. ../include";
 			};
 			name = Debug;
 		};
@@ -412,7 +412,7 @@
 				GCC_ENABLE_CPP_RTTI = YES;
 				GCC_SYMBOLS_PRIVATE_EXTERN = YES;
 				PRODUCT_NAME = "$(TARGET_NAME)";
-				USER_HEADER_SEARCH_PATHS = ..;
+				USER_HEADER_SEARCH_PATHS = ".. ../include";
 			};
 			name = Release;
 		};

+ 6 - 6
math/matrix.hpp

@@ -65,11 +65,11 @@ typename std::enable_if<!is_matrix<_type>::value, matrix<t, r, c> >::type
       S const & operator[](std::size_t col) const { return _handle[col]; }
       S & operator[](std::size_t col) { return _handle[col]; }
       S const & at(std::size_t col) const {
-        expects_e(col < C, std::out_of_range, "column index out of range");
+        expects(col < C, std::out_of_range, "column index out of range");
         return operator[](col);
       }
       S & at(std::size_t col) {
-        expects_e(col < C, std::out_of_range, "column index out of range");
+        expects(col < C, std::out_of_range, "column index out of range");
         return operator[](col);
       }
       
@@ -164,19 +164,19 @@ typename std::enable_if<!is_matrix<_type>::value, matrix<t, r, c> >::type
       return { _data[row] };
     }
     row_reference<const T> at(std::size_t row) const {
-      expects_e(row >= R, std::out_of_range, "row index out of range");
+      expects(row >= R, std::out_of_range, "row index out of range");
       return operator[](row);
     }
     row_reference<T> at(std::size_t row) {
-      expects_e(row >= R, std::out_of_range, "row index out of range");
+      expects(row >= R, std::out_of_range, "row index out of range");
       return operator[](row);
     }
     value_type const & at(std::size_t row, std::size_t col) const {
-      expects_e(row < R && col < C, std::out_of_range, "coordinates out of range");
+      expects(row < R && col < C, std::out_of_range, "coordinates out of range");
       return _data[row][col];
     }
     value_type & at(std::size_t row, std::size_t col) {
-      expects_e(row < R && col < C, std::out_of_range, "coordinates out of range");
+      expects(row < R && col < C, std::out_of_range, "coordinates out of range");
       return _data[row][col];
     }
     

+ 5 - 5
math/vector.hpp

@@ -16,7 +16,7 @@
 #include <stdexcept>
 #include <type_traits>
 
-#include "util/expect.hpp"
+#include "expect/expect.hpp"
 
 namespace math { namespace vector {
 #define VECTOR_ENABLE_IF_LT_N(index, expr) \
@@ -132,12 +132,12 @@ VECTOR_ENABLE_IF_LT_N(i, value_type &) name() { return _data[i]; }
     }
     
     value_type const & at(std::size_t idx) const {
-      expects_e(idx < N, std::out_of_range, "index out of range");
+      expects(idx < N, std::out_of_range, "index out of range");
       return _data[idx];
     }
     
     value_type & at(std::size_t idx) {
-      expects_e(idx < N, std::out_of_range, "index out of range");
+      expects(idx < N, std::out_of_range, "index out of range");
       return _data[idx];
     }
     
@@ -192,7 +192,7 @@ VECTOR_ENABLE_IF_LT_N(i, value_type &) name() { return _data[i]; }
     
     template <typename M>
     VECTOR_ENABLE_IF_EQ_T(div_t<M>, T, N)& operator/=(M c) {
-      expects_e(c != 0, std::domain_error, "divide by zero");
+      expects(c != 0, std::domain_error, "divide by zero");
       VECTOR_FOR_EACH(i) { _data[i] /= c; }
       return *this;
     }
@@ -204,7 +204,7 @@ VECTOR_ENABLE_IF_LT_N(i, value_type &) name() { return _data[i]; }
     
     template <typename M>
     VECTOR_ENABLE_IF_EQ_T(div_t<M>, T, N)& operator/=(vector<M, N> c) {
-      VECTOR_FOR_EACH(i) { expects_e(c[i] != 0, std::domain_error, "divide by zero"); }
+      VECTOR_FOR_EACH(i) { expects(c[i] != 0, std::domain_error, "divide by zero"); }
       VECTOR_FOR_EACH(i) { _data[i] /= c[i]; }
       return *this;
     }

+ 0 - 32
util/expect.hpp

@@ -1,32 +0,0 @@
-//
-//  require.hpp
-//  gameutils
-//
-//  Created by Sam Jaffe on 8/19/16.
-//
-
-#pragma once
-
-#include <stdexcept>
-
-#include "macro.h"
-
-inline namespace precondition {
-  template <typename except>
-  void _expect(bool expr, char const * message) {
-    if (!expr) throw except{message};
-  }
-}
-
-#if defined( __clang__ ) || defined( __GNUC__ )
-# define LOCATION_INFO ". in " STRING(__PRETTY_FUNCTION__) "(" __FILE__ ":" STRING(__LINE__) ")"
-#elif defined( _MSC_VER )
-# define LOCATION_INFO ". in " __FUNCTION__ "(" __FILE__ ":" STRING(__LINE__) ")"
-#else
-# define LOCATION_INFO ". in " __FILE__ ":" STRING(__LINE__)
-#endif
-
-#define error_msg(expr, msg) msg ": " #expr LOCATION_INFO
-
-#define expects(expr, msg) expects_e(expr, std::logic_error, msg)
-#define expects_e(expr, except, msg) precondition::_expect<except>( expr, error_msg(expr, msg) )

+ 0 - 8
util/gameutils.xcodeproj/project.pbxproj

@@ -9,16 +9,12 @@
 /* Begin PBXBuildFile section */
 		CD3C808B1D6646AC00ACC795 /* scope_exit.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD3AC7281D2C2922002B4BB0 /* scope_exit.hpp */; };
 		CD3C808C1D6646AF00ACC795 /* identity.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD3AC7161D2C0794002B4BB0 /* identity.hpp */; };
-		CD3C80B51D67B9CC00ACC795 /* expect.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD3C80B41D67B9CC00ACC795 /* expect.hpp */; };
-		CD3C80B71D67BD4C00ACC795 /* macro.h in Headers */ = {isa = PBXBuildFile; fileRef = CD3C80B61D67BD4C00ACC795 /* macro.h */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
 		CD3AC7081D2C0726002B4BB0 /* libgameutils.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libgameutils.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		CD3AC7161D2C0794002B4BB0 /* identity.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = identity.hpp; sourceTree = "<group>"; };
 		CD3AC7281D2C2922002B4BB0 /* scope_exit.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = scope_exit.hpp; sourceTree = "<group>"; };
-		CD3C80B41D67B9CC00ACC795 /* expect.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = expect.hpp; sourceTree = "<group>"; };
-		CD3C80B61D67BD4C00ACC795 /* macro.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = macro.h; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -53,8 +49,6 @@
 			children = (
 				CD3AC7161D2C0794002B4BB0 /* identity.hpp */,
 				CD3AC7281D2C2922002B4BB0 /* scope_exit.hpp */,
-				CD3C80B61D67BD4C00ACC795 /* macro.h */,
-				CD3C80B41D67B9CC00ACC795 /* expect.hpp */,
 			);
 			name = src;
 			sourceTree = "<group>";
@@ -66,10 +60,8 @@
 			isa = PBXHeadersBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				CD3C80B51D67B9CC00ACC795 /* expect.hpp in Headers */,
 				CD3C808C1D6646AF00ACC795 /* identity.hpp in Headers */,
 				CD3C808B1D6646AC00ACC795 /* scope_exit.hpp in Headers */,
-				CD3C80B71D67BD4C00ACC795 /* macro.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 20 - 0
util/identity.hpp

@@ -0,0 +1,20 @@
+//
+//  identity.hpp
+//  gameutils
+//
+//  Created by Sam Jaffe on 7/5/16.
+//
+
+#pragma once
+
+#include <type_traits>
+
+template <typename T, typename ID = unsigned int>
+class identity {
+public:
+  ID const id;
+private:
+  friend T;
+  identity( ID _id ) : id( std::move( _id ) ) {}
+  identity( ) = delete;
+};

+ 0 - 14
util/macro.h

@@ -1,14 +0,0 @@
-//
-//  macro.h
-//  gameutils
-//
-//  Created by Sam Jaffe on 8/19/16.
-//
-
-#pragma once
-
-#define CONCAT2(A, B) A##B
-#define CONCAT(A, B) CONCAT2(A, B)
-
-#define STRING2(A) #A
-#define STRING(A) STRING2(A)

+ 1 - 1
util/scope_exit.hpp

@@ -11,7 +11,7 @@
 
 #include "macro.h"
 
-#define scope(type) scope_##type##_t CONCAT(scope_,CONCAT(type,__LINE__) = [&]()
+#define scope(type) scope_##type##_t CONCAT( scope_,CONCAT( type, __LINE__ ) ) = [&]()
 
 class scope_exit_t {
 public: