[use exceptions for load errors instead of asserts. Now the user gets an error message when loading fails
Andreas Röver <roever@users.sourceforge.net>**20050712152929] {
hunk ./src/lib/assembly.cpp 110
-  assert(node.get_type() == xml::node::type_element);
-  assert(strcmp(node.get_name(), "assembly") == 0);
+  if ((node.get_type() != xml::node::type_element) ||
+      (strcmp(node.get_name(), "assembly") != 0))
+    throw load_error("not the right node for assembly", node);
hunk ./src/lib/disassembly.cpp 43
-      assert(!negative && !gotNum);
+      if (negative || gotNum)
+        throw load_error("too many '-' signs in disassembly number");
+
hunk ./src/lib/disassembly.cpp 56
-        assert(start != end);
+
+        if (start == end)
+          throw load_error("too many numbers in disassembly");
+
hunk ./src/lib/disassembly.cpp 67
-      assert(!negative);
+      if (negative)
+        throw load_error("only '-' encountered in disassembly");
hunk ./src/lib/disassembly.cpp 72
-      assert(0);
+      throw load_error("not alowed character in disassembly");
hunk ./src/lib/disassembly.cpp 83
-    assert(start != end);
+
+    if (start == end)
+      throw load_error("too many numbers in disassembly");
+
hunk ./src/lib/disassembly.cpp 93
-  assert(start == end);
+  if (start != end)
+    throw load_error("too few number in disassembly");
hunk ./src/lib/disassembly.cpp 144
-  assert(node.get_type() == xml::node::type_element);
-  assert(strcmp(node.get_name(), "state") == 0);
-  assert(node.find("dx") != node.end());
-  assert(node.find("dy") != node.end());
-  assert(node.find("dz") != node.end());
+  if ((node.get_type() != xml::node::type_element) ||
+      (strcmp(node.get_name(), "state") != 0))
+    throw load_error("not the right node for disassembly state", node);
+
+  if ((node.find("dx") == node.end()) ||
+      (node.find("dy") == node.end()) ||
+      (node.find("dz") == node.end()))
+    throw load_error("disassembly state needs dx, dy and dz subnode", node);
hunk ./src/lib/disassembly.cpp 157
-  assert(dx && dy && dz);
+  if (!dx || !dy || !dz)
+    throw load_error("could not allocate memory for disassembly state", node);
hunk ./src/lib/disassembly.cpp 164
-  getNumbers(node.find("dx")->get_content(), dx, dx+pn, true);
-  getNumbers(node.find("dy")->get_content(), dy, dy+pn, true);
-  getNumbers(node.find("dz")->get_content(), dz, dz+pn, true);
+  try {
+    getNumbers(node.find("dx")->get_content(), dx, dx+pn, true);
+    getNumbers(node.find("dy")->get_content(), dy, dy+pn, true);
+    getNumbers(node.find("dz")->get_content(), dz, dz+pn, true);
+  }
+  catch (load_error e) {
+    throw load_error(e.getText(), node);
+  }
hunk ./src/lib/puzzle.cpp 167
-  assert(node.get_type() == xml::node::type_element);
-  assert(strcmp(node.get_name(), "bitmap") == 0);
+  if ((node.get_type() != xml::node::type_element) ||
+      (strcmp(node.get_name(), "bitmap") != 0))
+    throw load_error("not the right node for color constrains", node);
hunk ./src/lib/puzzle.cpp 176
-      assert(i->get_attributes().find("piece") != i->get_attributes().end());
-      assert(i->get_attributes().find("result") != i->get_attributes().end());
+
+      if (i->get_attributes().find("piece") == i->get_attributes().end())
+        throw load_error("no attribute 'piece' found in color constraint node", node);
+      if (i->get_attributes().find("result") == i->get_attributes().end())
+        throw load_error("no attribute 'result' found in color constraint node", node);
hunk ./src/lib/puzzle.cpp 185
-      assert(piece < colors);
-      assert(result < colors);
+      if (piece >= colors)
+        throw load_error("piece color too big", node);
+      if (result >= colors)
+        throw load_error("result color too big", node);
hunk ./src/lib/puzzle.cpp 222
-  assert(node.get_type() == xml::node::type_element);
-  assert(strcmp(node.get_name(), "solution") == 0);
-  assert(node.find("assembly") != node.end());
+
+  if ((node.get_type() != xml::node::type_element) ||
+      (strcmp(node.get_name(), "solution") != 0))
+    throw load_error("wrong node type for solution", node);
+
+  if (node.find("assembly") == node.end())
+    throw load_error("slution does not contain an assembly", node);
hunk ./src/lib/puzzle.cpp 269
-  problem_c(const xml::node & node, unsigned int colors);
+  problem_c(const xml::node & node, unsigned int colors, unsigned int shapes);
hunk ./src/lib/puzzle.cpp 441
+
+problem_c::problem_c(const xml::node & node, unsigned int color, unsigned int shape) : result(0xFFFFFFFF), colorConstraints(color), assm(0) {
hunk ./src/lib/puzzle.cpp 444
-problem_c::problem_c(const xml::node & node, unsigned int color) : result(0xFFFFFFFF), colorConstraints(color), assm(0) {
+  if ((node.get_type() != xml::node::type_element) ||
+      (strcmp(node.get_name(), "problem") != 0))
+    throw load_error("not the right node for the puzzle problem", node);
hunk ./src/lib/puzzle.cpp 448
-  assert(node.get_type() == xml::node::type_element);
-  assert(strcmp(node.get_name(), "problem") == 0);
-  assert(node.find("result") != node.end());
+  if (node.get_attributes().find("name") == node.get_attributes().end())
+    throw load_error("problems need to have a 'name' attribute", node);
hunk ./src/lib/puzzle.cpp 451
-  assert(node.get_attributes().find("name") != node.get_attributes().end());
hunk ./src/lib/puzzle.cpp 461
-        assert(i->get_attributes().find("id") != i->get_attributes().end());
-        assert(i->get_attributes().find("count") != i->get_attributes().end());
+
+        if (i->get_attributes().find("id") == i->get_attributes().end())
+          throw load_error("a shape node must have an 'idt' attribute", *i);
+
+        if (i->get_attributes().find("count") == i->get_attributes().end())
+          throw load_error("a shape node must have a 'count' attribute", *i);
hunk ./src/lib/puzzle.cpp 470
+
+        if (id >= shape)
+          throw load_error("the shape ids must be for valid shapes", *i);
hunk ./src/lib/puzzle.cpp 479
-    assert(it->get_attributes().find("id") != it->get_attributes().end());
+    if (it->get_attributes().find("id") == it->get_attributes().end())
+      throw load_error("the result node must have an 'id' attribute", *it);
+
hunk ./src/lib/puzzle.cpp 483
+
+    if (result >= shape)
+      throw load_error("the result id must be for a valid shape", *it);
hunk ./src/lib/puzzle.cpp 727
+
+  if ((node.get_type() != xml::node::type_element) ||
+      (strcmp(node.get_name(), "puzzle") != 0))
+    throw load_error("not the right node type for the puzzle", node);
+
+  if (node.get_attributes().find("version") == node.get_attributes().end())
+    throw load_error("puzzle node must have a 'version' attribute", node);
hunk ./src/lib/puzzle.cpp 735
-  assert(node.get_type() == xml::node::type_element);
-  assert(strcmp(node.get_name(), "puzzle") == 0);
-  assert(node.get_attributes().find("version") != node.get_attributes().end());
-  assert(atoi(node.get_attributes().find("version")->get_value()) == 1);
+  if (atoi(node.get_attributes().find("version")->get_value()) != 1)
+    throw load_error("puzzle nodes must have version 1", node);
hunk ./src/lib/puzzle.cpp 745
+
+        if (i->get_attributes().find("red") == i->get_attributes().end())
+          throw load_error("color nodes must have a 'red' attribute", *i);
+
+        if (i->get_attributes().find("green") == i->get_attributes().end())
+          throw load_error("color nodes must have a 'gree' attribute", *i);
hunk ./src/lib/puzzle.cpp 752
-        assert(i->get_attributes().find("red") != i->get_attributes().end());
-        assert(i->get_attributes().find("green") != i->get_attributes().end());
-        assert(i->get_attributes().find("blue") != i->get_attributes().end());
+        if (i->get_attributes().find("blue") == i->get_attributes().end())
+          throw load_error("color nodes must have a 'blue' attribute", *i);
hunk ./src/lib/puzzle.cpp 778
-        problems.push_back(new problem_c(*i, colors.size()));
+        problems.push_back(new problem_c(*i, colors.size(), shapes.size()));
hunk ./src/lib/voxel.cpp 863
-  assert(node.get_type() == xml::node::type_element);
-  assert(strcmp(node.get_name(), "voxel") == 0);
+  if ((node.get_type() != xml::node::type_element) ||
+      (strcmp(node.get_name(), "voxel") != 0))
+    throw load_error("not the right type of node for a voxel space", node);
hunk ./src/lib/voxel.cpp 1019
-  assert(node.get_type() == xml::node::type_element);
-  assert(strcmp(node.get_name(), "voxel") == 0);
+  if ((node.get_type() != xml::node::type_element) ||
+      (strcmp(node.get_name(), "voxel") != 0))
+    throw load_error("not the right type of node for an assemblyVoxel", node);
hunk ./src/lib/voxel.h 61
+  load_error(const std::string & arg) : text(arg) {};
+
}
