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.

62 line
1010 B

  1. #pragma once
  2. #include <vector>
  3. #include <map>
  4. #include <string>
  5. #include <utility>
  6. #include <iostream>
  7. namespace csv {
  8. struct cell_id {
  9. size_t x,y;
  10. bool operator<(const cell_id& oth) {
  11. if (y < oth.y) return true;
  12. if (x < oth.x) return true;
  13. return false;
  14. };
  15. };
  16. cell_id get_coords_from_id(const std::string_view id) {
  17. size_t x = 0;
  18. size_t y = 0;
  19. auto c = id.begin();
  20. while(*c < 'A' || *c > 'Z')
  21. {
  22. x += *c-'A';
  23. x *= 26;
  24. c++;
  25. }
  26. x /= 26;
  27. while(*c < '0' || *c > '9')
  28. {
  29. y += *c-'0';
  30. y *= 10;
  31. c++;
  32. }
  33. y /= 10;
  34. cell_id ret;
  35. ret.x = x;
  36. ret.y = y;
  37. return ret;
  38. }
  39. class context;
  40. class cell {
  41. public:
  42. std::string data = "";
  43. mutable std::string computed_value = "";
  44. mutable std::string display_value = "";
  45. void eval(const context& ctx);
  46. };
  47. class context {
  48. public:
  49. std::map<cell_id, cell> data;
  50. /*const cell& operator[] (const std::string_view id) const {
  51. auto coords = get_coords_from_id(id);
  52. return data[coords];
  53. }*/
  54. };
  55. }