Use check{_hard,_soft} in preference to assert

This commit is contained in:
Danny Robson 2012-04-12 16:06:28 +10:00
parent 040e565a18
commit e6ad6c2db3
2 changed files with 24 additions and 23 deletions

View File

@ -14,15 +14,16 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>. * along with libgim. If not, see <http://www.gnu.org/licenses/>.
* *
* Copyright 2010 Danny Robson <danny@blubinc.net> * Copyright 2010-2012 Danny Robson <danny@blubinc.net>
*/ */
#include "json.hpp" #include "json.hpp"
#include "maths.hpp"
#include "io.hpp"
#include <cassert> #include "debug.hpp"
#include "io.hpp"
#include "maths.hpp"
#include <deque> #include <deque>
#include <stdexcept> #include <stdexcept>
#include <cstdlib> #include <cstdlib>
@ -79,9 +80,9 @@ struct parse_context {
action new_array { nodestack.push_back (parse_context(new json::array)); } action new_array { nodestack.push_back (parse_context(new json::array)); }
action new_object_value { action new_object_value {
assert (nodestack.back ().root->is_object ()); check_hard (nodestack.back ().root->is_object ());
assert (nodestack.back ().key); check (nodestack.back ().key);
assert (nodestack.back ().value); check (nodestack.back ().value);
if (!nodestack.back ().key->is_string ()) if (!nodestack.back ().key->is_string ())
throw parse_error ("object keys must be strings"); throw parse_error ("object keys must be strings");
@ -94,8 +95,8 @@ struct parse_context {
} }
action new_array_value { action new_array_value {
assert (nodestack.back ().root->is_array ()); check_hard (nodestack.back ().root->is_array ());
assert (nodestack.back ().value); check (nodestack.back ().value);
json::array *array = (json::array *)nodestack.back ().root; json::array *array = (json::array *)nodestack.back ().root;
array->insert (nodestack.back ().value); array->insert (nodestack.back ().value);
@ -103,8 +104,8 @@ struct parse_context {
} }
action new_string { action new_string {
assert (!nodestack.empty ()); check_hard (!nodestack.empty ());
assert (!nodestack.back ().value); check (!nodestack.back ().value);
std::string value (std::string (nodestack.back ().start, std::string value (std::string (nodestack.back ().start,
nodestack.back ().stop)); nodestack.back ().stop));
@ -112,15 +113,15 @@ struct parse_context {
} }
action new_boolean { action new_boolean {
assert (!nodestack.empty ()); check_hard (!nodestack.empty ());
assert (!nodestack.back ().value); check (!nodestack.back ().value);
throw parse_error ("unable to parse boolean"); throw parse_error ("unable to parse boolean");
} }
action new_number { action new_number {
assert (!nodestack.empty ()); check_hard (!nodestack.empty ());
assert (!nodestack.back ().value); check (!nodestack.back ().value);
errno = 0; errno = 0;
double value = strtod (nodestack.back ().start, NULL); double value = strtod (nodestack.back ().start, NULL);
@ -130,17 +131,17 @@ struct parse_context {
} }
action new_null { action new_null {
assert (!nodestack.empty ()); check_hard (!nodestack.empty ());
assert (!nodestack.back ().value); check (!nodestack.back ().value);
nodestack.back().value = new json::null (); nodestack.back().value = new json::null ();
} }
action new_object_key { action new_object_key {
assert (!nodestack.empty ()); check_hard (!nodestack.empty ());
assert (nodestack.back ().root->is_object ()); check_hard (nodestack.back ().root->is_object ());
assert (nodestack.back ().value); check (nodestack.back ().value);
assert (!nodestack.back ().key); check (!nodestack.back ().key);
nodestack.back ().key = nodestack.back ().value; nodestack.back ().key = nodestack.back ().value;
nodestack.back ().value = NULL; nodestack.back ().value = NULL;
@ -264,7 +265,7 @@ json::parse (const char *start,
throw parse_error ("unable to parse json"); throw parse_error ("unable to parse json");
//__root->print (cout) << endl; //__root->print (cout) << endl;
assert (*__root == *__root); check (*__root == *__root);
return std::unique_ptr<json::node> (__root); return std::unique_ptr<json::node> (__root);
} }

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>. * along with libgim. If not, see <http://www.gnu.org/licenses/>.
* *
* Copyright 2010 Danny Robson <danny@blubinc.net> * Copyright 2010-2012 Danny Robson <danny@blubinc.net>
*/ */
#ifndef __UTIL_JSON_HPP #ifndef __UTIL_JSON_HPP