summaryrefslogtreecommitdiffstats
path: root/c_layer/survival_curve.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'c_layer/survival_curve.hpp')
-rw-r--r--c_layer/survival_curve.hpp88
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;
+};