X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/a57a70eab1f0b259f3b488a58e1812b262455b33..b733cd4a9d1fcc19c3652b17fbd3065d0e0a72c7:/src/clave_fija.cpp?ds=inline diff --git a/src/clave_fija.cpp b/src/clave_fija.cpp index a954e24..d947e2a 100644 --- a/src/clave_fija.cpp +++ b/src/clave_fija.cpp @@ -2,26 +2,65 @@ #include #include "clave_fija.h" -ClaveFija::ClaveFija (int n) +ClaveFija::ClaveFija (int n, uint bd) { data = n; + block_data = bd; } ClaveFija::ClaveFija (uchar *n) { memcpy (&data, n, sizeof(int)); + memcpy (&block_data, n+sizeof(int), sizeof(int)); } uint ClaveFija::Size () const { - return sizeof (int); + return sizeof (int)+sizeof(uint); } uchar *ClaveFija::ToArray () const { uchar *out; - out = new uchar[sizeof(int)]; + out = new uchar[Size ()]; memcpy (out, &data, sizeof(int)); + memcpy (out+sizeof (int), &block_data, sizeof(int)); + return out; +} + +Clave *ClaveFija::Clone () const +{ + ClaveFija *k = new ClaveFija (*this); + return k; +} + +bool ClaveFija::operator < (const Clave &c) const +{ + return data < ((ClaveFija&)c).data; +} + +bool ClaveFija::operator == (const Clave &c) const +{ + return data == ((ClaveFija&)c).data; +} + +uchar *ClaveFija::ToRaw (uint &size) const +{ + std::stringstream ss; + + ss << "["; + ss << data; + ss << "]"; + ss << "["; + ss << block_data; + ss << "]"; + + std::string s = ss.str (); + + uchar *out = new uchar[s.size ()]; + memcpy (out, s.c_str (), s.size ()); + + size = s.size (); return out; }