pgLab/pglablib/codebuilder/TypeMappings.h
eelke be0064f730 The codegen now can properly lookup array types.
Array type lookup failed previously because the typemapping class was
not yet receiving the list of types from the database. Fix was to pass
this data
2018-11-17 09:47:50 +01:00

46 lines
1.2 KiB
C++

#ifndef TYPEMAPPINGS_H
#define TYPEMAPPINGS_H
#include <Pgsql_declare.h>
#include <QString>
#include <initializer_list>
#include <unordered_map>
class PgTypeContainer;
class TypeMappings {
public:
using TypeMap = std::unordered_map<Oid, QString>;
using Mapping = std::pair<Oid, QString>;
TypeMappings(std::shared_ptr<const PgTypeContainer> types = nullptr);
TypeMappings(std::shared_ptr<const PgTypeContainer> types, std::initializer_list<Mapping> mappings);
QString getTypeForOid(Oid oid) const;
const TypeMap& typeMap() const { return m_typeMap; }
QString defaultStringType() const { return m_defaultStringType; }
void setTypes(std::shared_ptr<const PgTypeContainer> types);
void setDefaultStringType(QString str);
void setDefaultContainerType(QString str);
void set(Oid oid, QString type);
/** Removing a type from the mapping will reeastablish its default mapping
* which in most cases is the default string type for the language.
*/
void remove(Oid oid);
private:
TypeMap m_typeMap;
QString m_defaultStringType;
QString m_defaultContainerType; ///< This string should contain a format variable where the element type should go
std::shared_ptr<const PgTypeContainer> m_types;
};
#endif // TYPEMAPPINGS_H