allow parsing locations

This commit is contained in:
2024-07-03 16:17:24 -06:00
committed by Celtic Minstrel
parent 945a4f14a0
commit 54ac26b4da
3 changed files with 35 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
#include "location.hpp"
#include "mathutil.hpp"
#include <iostream>
#include <sstream>
eDirection& operator++ (eDirection& me, int) {
if(me == DIR_HERE) return me = DIR_N;
@@ -237,6 +238,19 @@ std::ostream& operator<< (std::ostream& out, location l) {
return out;
}
std::istream& operator>> (std::istream& in, location& l) {
in.get(); // (
std::stringbuf sstr;
in.get(sstr, ',');
l.x = atoi(sstr.str().c_str());
in.get(); // ,
sstr.str("");
in.get(sstr, ')');
l.y = atoi(sstr.str().c_str());
in.get(); // )
return in;
}
std::ostream& operator<< (std::ostream& out, spec_loc_t l) {
out << static_cast<location&>(l);
out << ':' << l.spec;

View File

@@ -165,6 +165,7 @@ rectangle rect(int top, int left, int bottom, int right);
std::ostream& operator << (std::ostream& out, eDirection e);
std::istream& operator >> (std::istream& in, eDirection& e);
std::ostream& operator<< (std::ostream& out, location l);
std::istream& operator>> (std::istream& in, location& l);
std::ostream& operator<< (std::ostream& out, spec_loc_t l);
std::ostream& operator<< (std::ostream& out, sign_loc_t l);
std::ostream& operator<< (std::ostream& out, rectangle r);