Skip to content

Instantly share code, notes, and snippets.

@uxdxdev
Created January 7, 2017 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uxdxdev/76df1ecb951483c2530b9904c365092f to your computer and use it in GitHub Desktop.
Save uxdxdev/76df1ecb951483c2530b9904c365092f to your computer and use it in GitHub Desktop.
Utils class
// 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