Created
January 7, 2017 15:32
-
-
Save uxdxdev/76df1ecb951483c2530b9904c365092f to your computer and use it in GitHub Desktop.
Utils class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2016 David Morton. All rights reserved. | |
// Use of this source code is governed by a license that can be | |
// found in the LICENSE file. | |
#ifndef BASE_UTILS_H | |
#define BASE_UTILS_H | |
#include <iostream> | |
class Utils { | |
public: | |
// Converts data to string | |
template<typename T> | |
static std::string to_str(T Number) { | |
std::ostringstream ss; | |
ss << Number; | |
return ss.str(); | |
} | |
template<typename T> | |
static int to_int(T string) { | |
std::istringstream ss(string); | |
int num; | |
ss >> num; | |
return num; | |
} | |
// Converts vector of bytes to string | |
static std::string vec_to_string(const std::vector<uint8_t>& v) { | |
return std::string(v.begin(), v.end()); | |
} | |
// Converts string to a vector of bytes | |
static std::vector<uint8_t> str_to_vector(const std::string& str) { | |
return std::vector < uint8_t > (str.begin(), str.end()); | |
} | |
static unsigned long long milli_to_sec(unsigned long long milliseconds) { | |
unsigned long long seconds = milliseconds / 1000; | |
return seconds; | |
} | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment