Skip to content

Commit

Permalink
Additional comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishYUO committed Apr 13, 2021
1 parent 265a865 commit f7daaa1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
41 changes: 35 additions & 6 deletions ciphers/uint128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,17 @@ class uint128_t {
#endif
}

inline uint32_t _len() { return _lez(); }

// Casting operators
inline explicit operator bool() const { return f || s; }
/**
* @brief casting operator to boolean value
* @returns true if value of this is non-zero, else false
*/
inline explicit operator bool() const { return (f || s); }

/**
* @brief casting operator to any integer valu
* @tparam T any integer type
* @returns integer value casted to mentioned type
*/
template <typename T, typename = typename std::enable_if<
std::is_integral<T>::value, T>::type>
inline explicit operator T() const {
Expand All @@ -200,20 +206,43 @@ class uint128_t {
*/
inline uint64_t upper() const { return f; }

/**
* @brief operator = for other types
* @tparam T denoting any integer type
* @param p an integer to assign it's value
* @returns this pointer with it's value equal to `p`
*/
template <typename T, typename = typename std::enable_if<
std::is_integral<T>::value, T>::type>
inline uint128_t &operator=(const T &p) {
this->s = p;
return *this;
}

/**
* @brief operator = for type string
* @param p a string to assign it's value to equivalent integer
* @returns this pointer with it's value equal to `p`
*/
inline uint128_t &operator=(const std::string &p) {
__get_integer_from_string(p);
this->__get_integer_from_string(p);
return *this;
}

inline uint128_t &operator=(const uint128_t &p) = default;
/**
* @brief operator = for uint128_t
* @param p an 128-bit integer to assign it's value
* @returns this pointer with it's value equal to `p`
*/
inline uint128_t &operator=(const uint128_t &p) {
f = p.f;
s = p.s;
return *this;
}

/**
* @brief Move assignment operator
*/
inline uint128_t &operator=(uint128_t &&p) = default;

/**
Expand Down
34 changes: 30 additions & 4 deletions ciphers/uint256_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,27 @@ class uint256_t {
return 128 + f._trz();
}

inline uint32_t _len() { return _lez(); }

/**
* @brief casting operator to boolean value
* @returns true if value of this is non-zero, else false
*/
inline explicit operator bool() const { return f || s; }

/**
* @brief casting operator
* @brief casting operator to any integer value
* @tparam T any integer type
* @returns integer value casted to mentioned type
*/
template <typename T, typename = typename std::enable_if<
std::is_integral<T>::value, T>::type>
inline explicit operator T() const {
return static_cast<T>(s);
}

/**
* @brief casting operator to uint128_t
* @returns returns lower 128-bit integer part
*/
inline explicit operator uint128_t() const { return s; }

/**
Expand All @@ -166,21 +174,39 @@ class uint256_t {
*/
inline uint128_t upper() const { return f; }

// Assign
/**
* @brief operator = for uint256_t
* @param p an 256-bit integer to assign it's value
* @returns this pointer with it's value equal to `p`
*/
inline uint256_t &operator=(const uint256_t &p) = default;

/**
* @brief operator = for other types
* @tparam T denoting any integer type
* @param p an integer to assign it's value
* @returns this pointer with it's value equal to `p`
*/
template <typename T, typename = typename std::enable_if<
std::is_integral<T>::value, T>::type>
inline uint256_t &operator=(const T &p) {
this->s = p;
return *this;
}

/**
* @brief operator = for type string
* @param p a string to assign it's value to equivalent integer
* @returns this pointer with it's value equal to `p`
*/
inline uint256_t &operator=(const std::string &p) {
__get_integer_from_string(p);
return *this;
}

/**
* @brief Move assignment operator
*/
inline uint256_t &operator=(uint256_t &&p) = default;

/**
Expand Down

0 comments on commit f7daaa1

Please sign in to comment.