Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+50
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Helper class for a vector of integer (stored as integer[] in the postgres database
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-05-03
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <QString>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace LtsUtils
|
||||
{
|
||||
|
||||
template<typename T, typename C>
|
||||
class PgArray
|
||||
{
|
||||
public:
|
||||
using Type = T;
|
||||
using ContainerType = C;
|
||||
|
||||
PgArray() = default;
|
||||
Q_DECL_CONSTEXPR explicit PgArray(const C &data)
|
||||
: m_data(data)
|
||||
{}
|
||||
|
||||
Q_DECL_CONSTEXPR C operator()()const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
QString toPgString() const;
|
||||
static PgArray fromPgString(const QString &str);
|
||||
private:
|
||||
C m_data;
|
||||
};
|
||||
|
||||
// helper to convert a postgres array (one-dimensional) into a std::vector<T> and vice versa
|
||||
// { 1, 5, 5, 2, 9 }
|
||||
using IntArray = PgArray<int, std::vector<int>>; // integer[]
|
||||
using BigintArray = PgArray<int64_t, std::vector<int64_t>>; // bigint[]
|
||||
// helper to convert a two-dimensional postgres array into a std::map<T, T> and vice versa
|
||||
// { { 1, 2 }, { 4, 3 }, { 10, 1 } }
|
||||
using IntArray2D = PgArray<int, std::map<int, int>>; // integer[][]
|
||||
using BigintArray2D = PgArray<int64_t, std::map<int64_t, int64_t>>; // bigint[][]
|
||||
|
||||
} // namespace LtsUtils
|
||||
Reference in new issue
Block a user