You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

63 lines
1006 B

#pragma once
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <iostream>
namespace csv {
struct cell_id {
size_t x,y;
bool operator<(const cell_id& oth) {
if (y < oth.y) return true;
if (x < oth.x) return true;
return false;
};
};
cell_id get_coords_from_id(const std::string_view id) {
size_t x = 0;
size_t y = 0;
auto c = id.begin();
while(*c < 'A' || *c > 'Z')
{
x += *c-'A';
x *= 26;
c++;
}
x /= 26;
while(*c < '0' || *c > '9')
{
y += *c-'0';
y *= 10;
c++;
}
y /= 10;
cell_id ret;
ret.x = x;
ret.y = y;
return ret;
}
class context;
class cell {
public:
std::string data = "";
mutable std::string computed_value = "";
mutable std::string display_value = "";
void eval(const context& ctx);
};
class context {
public:
std::map<cell_id, cell> data;
const cell& operator[] (const std::string_view id) const {
auto coords = get_coords_from_id(id);
return data[coords];
}
};
}