]> Dogcows Code - chaz/vimcoder/blobdiff - src/com/dogcows/resources/C++Driver
specify the std abort function in C++ driver
[chaz/vimcoder] / src / com / dogcows / resources / C++Driver
index 89e00f0678349fa54f17d27c59bd8fef604cebf6..8161f636c8e8665e0d95dfbb684358da235d5c85 100644 (file)
@@ -22,7 +22,7 @@ static void __timer_start()
        struct timeval tv;
        if (gettimeofday(&tv, NULL) == 0)
        {
-               __time = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
+               __time = double(tv.tv_sec) + double(tv.tv_usec) * 0.000001;
        }
 }
 
@@ -34,6 +34,12 @@ static double __timer_stop()
 }
 
 
+static void __eat_whitespace(std::istream& in)
+{
+       while (in.good() && std::isspace(in.peek())) in.get();
+}
+
+
 std::ostream& operator << (std::ostream& out, const std::string& str)
 {
        out << '"' << str.c_str() << '"';
@@ -55,7 +61,7 @@ std::ostream& operator << (std::ostream& out, const std::vector<T>& vec)
 
 std::istream& operator >> (std::istream& in, std::string& str)
 {
-       while (in.good() && std::isspace(in.peek())) in.get();
+       __eat_whitespace(in);
 
        int c;
        if (in.good() && (c = in.get()) == '"')
@@ -74,26 +80,29 @@ std::istream& operator >> (std::istream& in, std::string& str)
 template <class T>
 std::istream& operator >> (std::istream& in, std::vector<T>& vec)
 {
-       while (in.good() && std::isspace(in.peek())) in.get();
+       __eat_whitespace(in);
 
        int c;
        if (in.good() && (c = in.get()) == '{')
        {
-               while (in.good() && std::isspace(in.peek())) in.get();
-               T t;
+               __eat_whitespace(in);
                vec.clear();
                while (in.good() && (c = in.get()) != '}')
                {
                        if (c != ',') in.putback(c);
+
+                       T t;
                        in >> t;
+                       __eat_whitespace(in);
+
                        vec.push_back(t);
-                       while (in.good() && std::isspace(in.peek())) in.get();
                }
        }
 
        return in;
 }
 
+
 template <class T>
 bool __equals(const T& actual, const T& expected)
 {
@@ -129,11 +138,11 @@ bool __equals(const std::vector<double>& actual, const std::vector<double>& expe
 
 int main(int argc, char* argv[])
 {
-       bool    __exit_on_fail = false;
+       bool    __abort_on_fail = false;
        int     __pass = 0;
        int     __fail = 0;
 
-       if (1 < argc) __exit_on_fail = true;
+       if (1 < argc) __abort_on_fail = true;
 
        std::ifstream __in("testcases.txt");
        for(;;)
@@ -166,7 +175,7 @@ int main(int argc, char* argv[])
                                  << "   Actual: " << __actual << std::endl
                                  << " Expected: " << __expected << std::endl;
                        ++__fail;
-                       if (__exit_on_fail) exit(1);
+                       if (__abort_on_fail) std::abort();
                }
        }
 
This page took 0.024685 seconds and 4 git commands to generate.