diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2019-03-03 17:40:16 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2019-03-05 14:10:47 -0500 |
| commit | a8af544372950e71c8dcccb7e5034e8f42e6f3af (patch) | |
| tree | 41e0558c76d681842cab0e931f925682f91a96f5 /c_layer | |
| parent | e0745f3e6d9624bf0820ad1541d5e6c00b050fa0 (diff) | |
| download | pyisda-a8af544372950e71c8dcccb7e5034e8f42e6f3af.tar.gz | |
wip
Diffstat (limited to 'c_layer')
| -rw-r--r-- | c_layer/survival_curve.hpp | 88 |
1 files changed, 88 insertions, 0 deletions
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 <string> + +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; +}; |
