Code Utilities

These classes define code utility methods. Defined in src/utils/CodeUtils.h

class Caesar::CodeUtils : public TObject

Public Functions

CodeUtils()

Class constructor: initialize structures.

virtual ~CodeUtils()

Class destructor: free allocated memory.

template<>
inline std::vector<bool> StringVecToTypedVec(const std::vector<std::string> &vec)

Convert string vector to bool vector (specialization of general method)

Public Static Functions

static inline std::string GenerateUUID()

Generate uuid string.

static inline std::string GetStringCodeFromIntegers(std::vector<int> ids, size_t ndigits)

Convert json to string (DEPRECATED JSONCPP API)

Concatenate integers and create string code given digits

static inline long int GetCodeFromIntegers(std::vector<int> ids, size_t ndigits)

Concatenate integers and create int code given digits.

static inline std::vector<std::string> SplitStringInEqualParts(const std::string &str, int splitLength)

Split a string in equal parts.

static inline int DecodeIntCodes(std::vector<int> &ids, long int code, size_t ndigits)

Get integer codes from string codes.

static inline int JsonToString(std::string &jsonString, Json::Value &jsonObj, bool isMinified = true)

Convert json to string (NEW JSONCPP API)

static inline int StringToJson(Json::Value &root, std::string &jsonString)

Convert string to json.

template<typename T>
static inline int FindJsonValue(int &pos, Json::Value &root, T value, std::string key = "name")

Find json option in array by name.

template<class T>
static inline bool FindItem(std::vector<T> &v, T itemValue, int &pos)

Find item in a vector and returns item position.

template<class T, typename K>
static inline void DeleteItems(std::vector<T> &data, const std::vector<K> &deleteIndices)

Delete selected items from a vector.

template<class T, typename K>
static inline void DeletePtrItems(std::vector<T> &data, const std::vector<K> &deleteIndices)

Delete selected items from a vector.

template<class T>
static inline void DeletePtrCollection(std::vector<T*> &data)

Delete object pointer collection.

template<class T>
static inline void DeletePtrCollection(std::initializer_list<T*> data)

Delete object pointer collection.

template<class T>
static inline void DeletePtr(T *data)

Delete object pointer.

template<class T>
static inline void reorder(std::vector<T> &unordered, std::vector<size_t> const &index_map, std::vector<T> &ordered)

Reorder vector.

template<class T>
static inline void sort(std::vector<T> &unsorted, std::vector<T> &sorted, std::vector<size_t> &index_map)

Sort vector.

template<class T>
static inline void sort_descending(std::vector<T> &unsorted, std::vector<T> &sorted, std::vector<size_t> &index_map)

Sort vector in descending order.

template<class Iterator, class Comparator>
static inline IndexPairs FindIntersectionIndexes(Iterator first1, Iterator last1, Iterator first2, Iterator last2, Comparator comp, bool sorted = false)

Find index of equal elements in two vectors.

template<class Iterator>
static inline Iterator random_unique(Iterator begin, Iterator end, size_t num_random)

Extract a subset of random index without repetitions from a container.

template<typename T>
static inline int ExtractVectorRandomSample(std::vector<T> &sample_data, const std::vector<T> &data, long int n = -1, bool repeate = true)

Extract sample from data vector with given sample size, with/without repetitions and uniform weights.

template<typename T>
static inline int ExtractVectorRandomSamples(std::vector<std::vector<T>> &data_samples, const std::vector<T> &data, int nSamples, long int n = -1, bool repeate = true)

Extract a number of random samples from data vector with given sample size, with/without repetitions and uniform weights.

template<class T, class Comparator>
static inline T FindCumulativeSumFractionThr(std::vector<T> &data, Comparator comp, double thr, bool sorted = false)

Find vector index at which the cumulative sum is smaller then given value (comparator version)

template<class T>
static inline T FindCumulativeSumFractionThr(std::vector<T> &data, double thr, bool sorted = false)

Find vector index at which the cumulative sum is smaller then given value.

template<class InputIt, class T = typename std::iterator_traits<InputIt>::value_type>
static inline T FindVectorMode(InputIt begin, InputIt end, int &nmodes)

Find vector index at which the cumulative sum is smaller then given value.

static inline void StringFindAndReplace(std::string &str, const std::string &oldstr, const std::string &newstr)

String find and replace.

static inline void RemovePatternInString(std::string &str, const std::string pattern)

Remove pattern in string.

static inline std::string ExtractSubString(const std::string &s, const std::string &pattern, bool extractleft = true)

Extract substring.

static inline std::vector<std::string> SplitStringOnWhitespaces(const std::string &s)

Split string on whitespaces.

static inline std::vector<std::string> SplitStringOnPattern(const std::string &s, char delim)

Split string on pattern.

static inline std::string JoinStringVec(const std::vector<std::string> &vec, std::string delim)

Join string from string vector using delimiter.

template<typename T>
static inline std::vector<T> StringVecToTypedVec(const std::vector<std::string> &vec)

Convert string vector to typed vector.

static inline bool HasPatternInString(std::string str, std::string pattern)

Find pattern in string.

static inline int StripBlankSpaces(std::string &s)

Strip blank spaces from string.

template<typename Iter>
static inline std::string JoinCollection(Iter begin, Iter end, std::string separator = "")

Collapse a collection in a string (equivalent of python join)

template<typename T>
static inline std::string JoinVec(const std::vector<T> &data, std::string separator = "")

Join vectors.

static inline bool GetVecLogicalOr(const std::vector<bool> &v)

Perform logical OR among all vector elements.

static inline bool GetVecLogicalAnd(const std::vector<bool> &v)

Perform logical AND among all vector elements.

static inline bool AreEqualStringNoCase(std::string str1, std::string str2)

Compare string case insensitive.

static inline std::string ExtractFileNameFromPath(const std::string &s, bool strip_extension = false)

Extract filename from path.

template<typename T, typename K>
static inline bool HasMapKey(std::map<T, K> const &m, T key)

Check if map has key.

template<class T>
struct descending_index_cmp
template<class T>
struct index_cmp

Order vectors and get ordering index.