Browse Source

Move roll ostream<< functions into io.cxx

Sam Jaffe 4 years ago
parent
commit
e5143fc864
2 changed files with 31 additions and 33 deletions
  1. 31 1
      src/io.cxx
  2. 0 32
      src/roll.cxx

+ 31 - 1
src/io.cxx

@@ -10,8 +10,8 @@
 #include <sstream>
 
 #include "dice-roll/die.h"
-#include "dice-roll/exception.h"
 #include "dice-roll/parser.h"
+#include "dice-roll/roll.h"
 
 namespace dice {
 
@@ -48,6 +48,36 @@ std::ostream & operator<<(std::ostream & out, dice const & d) {
   return out;
 }
 
+std::ostream & operator<<(std::ostream & out, die_roll const & r) {
+  out << r.sign;
+  switch (r.rolled.size()) {
+  case 0:
+      // Prevent crashes if we somehow get a 0dM expression
+    return out << "0";
+  case 1:
+      // Don't bother with braces if there's only a single roll,
+      // the braces are for grouping purposes.
+    return out << r.rolled[0];
+  default:
+    out << "[ ";
+    out << r.rolled[0];
+    for (int i = 1; i < r.rolled.size(); ++i) {
+      out << ", " << r.rolled[i];
+    }
+    return out << " ]";
+  }
+}
+
+std::ostream & operator<<(std::ostream & out, dice_roll const & r) {
+  for (die_roll const & dr : r.sub_rolls) {
+    out << dr;
+  }
+  for (mod const & m : r.modifiers) {
+    out << m.sign << m.value;
+  }
+  return out;
+}
+
 std::istream & operator>>(std::istream & in, dice & d) {
   d = parser(in).parse();
   return in;

+ 0 - 32
src/roll.cxx

@@ -8,8 +8,6 @@
 
 #include "dice-roll/roll.h"
 
-#include <iostream>
-#include <memory>
 #include <numeric>
 
 #include "dice-roll/random.h"
@@ -24,36 +22,6 @@ dice_roll::operator int() const {
          std::accumulate(modifiers.begin(), modifiers.end(), 0);
 }
 
-std::ostream & operator<<(std::ostream & out, die_roll const & r) {
-  out << r.sign;
-  switch (r.rolled.size()) {
-  case 0:
-      // Prevent crashes if we somehow get a 0dM expression
-    return out << "0";
-  case 1:
-      // Don't bother with braces if there's only a single roll,
-      // the braces are for grouping purposes.
-    return out << r.rolled[0];
-  default:
-    out << "[ ";
-    out << r.rolled[0];
-    for (int i = 1; i < r.rolled.size(); ++i) {
-      out << ", " << r.rolled[i];
-    }
-    return out << " ]";
-  }
-}
-
-std::ostream & operator<<(std::ostream & out, dice_roll const & r) {
-  for (die_roll const & dr : r.sub_rolls) {
-    out << dr;
-  }
-  for (mod const & m : r.modifiers) {
-    out << m.sign << m.value;
-  }
-  return out;
-}
-
 die_roll roll_impl(die const & d, engine::random & gen) {
   std::vector<int> hits;
   for (int i = 0; i < d.num; ++i) {