From a8af544372950e71c8dcccb7e5034e8f42e6f3af Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sun, 3 Mar 2019 17:40:16 -0500 Subject: wip --- c_layer/survival_curve.hpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 c_layer/survival_curve.hpp (limited to 'c_layer') diff --git a/c_layer/survival_curve.hpp b/c_layer/survival_curve.hpp new file mode 100644 index 0000000..7032687 --- /dev/null +++ b/c_layer/survival_curve.hpp @@ -0,0 +1,88 @@ +#include + +struct CurveName { + enum class __attribute__ ((__packed__)) Seniority { + Senior, + Subordinated + }; + + enum class __attribute__ ((__packed__)) DocClause { + XR14, + MR14, + MM14, + CR14 + }; + void serialize(unsigned char* buf) { + memcpy(buf, &seniority, sizeof(Seniority)); + buf += sizeof(Seniority); + memcpy(buf, &doc_clause, sizeof(DocClause)); + buf += sizeof(DocClause); + strcpy((char*)buf, ticker.c_str()); + }; + + std::string full_ticker() { + std::string r = ticker; + return r.append("_").append(str_seniority()). + append("_").append(str_doc_clause()); + } + + void serialize(unsigned char* buf, size_t num) { + memcpy(buf, &seniority, sizeof(Seniority)); + buf += sizeof(Seniority); + memcpy(buf, &doc_clause, sizeof(DocClause)); + buf += sizeof(DocClause); + strncpy((char*)buf, ticker.c_str(), num); + }; + + CurveName(std::string& ticker, Seniority seniority, DocClause doc_clause) : + ticker(ticker), + seniority(seniority), + doc_clause(doc_clause) {}; + + CurveName(const unsigned char* buf) { + memcpy(&seniority, buf, sizeof(Seniority)); + buf += sizeof(Seniority); + memcpy(&doc_clause, buf, sizeof(DocClause)); + buf += sizeof(DocClause); + ticker = std::string((char*)buf); + } + + CurveName() {}; + + size_t size() { + return sizeof(Seniority) + sizeof(DocClause) + ticker.length() + 1; + }; + + bool operator<(const CurveName &other) const { + + return ticker < other.ticker || + ((ticker == other.ticker) && (seniority < other.seniority)) || + ((ticker == other.ticker) && (seniority == other.seniority) && (doc_clause < other.doc_clause)); + } + + std::string str_seniority() const { + switch (seniority) { + case Seniority::Senior: + return "Senior"; + case Seniority::Subordinated: + return "Subordinated"; + }; + } + + std::string str_doc_clause() const { + switch (doc_clause) { + case DocClause::XR14: + return "XR14"; + case DocClause::MR14: + return "MR14"; + case DocClause::MM14: + return "MM14"; + case DocClause::CR14: + return "CR14"; + } + } + + std::string ticker; + Seniority seniority; + DocClause doc_clause; +}; -- cgit v1.2.3-70-g09d2