/usr/include/soci/postgresql/common.h is in libsoci-dev 3.2.3-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | //
// Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef SOCI_POSTGRESQL_COMMON_H_INCLUDED
#define SOCI_POSTGRESQL_COMMON_H_INCLUDED
#include "soci-postgresql.h"
#include <limits>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <vector>
namespace soci
{
namespace details
{
namespace postgresql
{
// helper function for parsing integers
template <typename T>
T string_to_integer(char const * buf)
{
long long t(0);
int n(0);
int const converted = std::sscanf(buf, "%" LL_FMT_FLAGS "d%n", &t, &n);
if (converted == 1 && static_cast<std::size_t>(n) == std::strlen(buf))
{
// successfully converted to long long
// and no other characters were found in the buffer
const T max = (std::numeric_limits<T>::max)();
const T min = (std::numeric_limits<T>::min)();
if (t <= static_cast<long long>(max) &&
t >= static_cast<long long>(min))
{
return static_cast<T>(t);
}
else
{
// value out of target range
throw soci_error("Cannot convert data.");
}
}
else
{
// try additional conversion from boolean
// (PostgreSQL gives 't' or 'f' for boolean results)
if (buf[0] == 't' && buf[1] == '\0')
{
return static_cast<T>(1);
}
else if (buf[0] == 'f' && buf[1] == '\0')
{
return static_cast<T>(0);
}
else
{
throw soci_error("Cannot convert data.");
}
}
}
// helper function for parsing unsigned integers
template <typename T>
T string_to_unsigned_integer(char const * buf)
{
unsigned long long t(0);
int n(0);
int const converted = std::sscanf(buf, "%" LL_FMT_FLAGS "u%n", &t, &n);
if (converted == 1 && static_cast<std::size_t>(n) == std::strlen(buf))
{
// successfully converted to unsigned long long
// and no other characters were found in the buffer
const T max = (std::numeric_limits<T>::max)();
if (t <= static_cast<unsigned long long>(max))
{
return static_cast<T>(t);
}
else
{
// value out of target range
throw soci_error("Cannot convert data.");
}
}
else
{
// try additional conversion from boolean
// (PostgreSQL gives 't' or 'f' for boolean results)
if (buf[0] == 't' && buf[1] == '\0')
{
return static_cast<T>(1);
}
else if (buf[0] == 'f' && buf[1] == '\0')
{
return static_cast<T>(0);
}
else
{
throw soci_error("Cannot convert data.");
}
}
}
// helper function for parsing doubles
double string_to_double(char const * buf);
// helper function for parsing datetime values
void parse_std_tm(char const * buf, std::tm & t);
// helper for vector operations
template <typename T>
std::size_t get_vector_size(void * p)
{
std::vector<T> * v = static_cast<std::vector<T> *>(p);
return v->size();
}
} // namespace postgresql
} // namespace details
} // namespace soci
#endif // SOCI_POSTGRESQL_COMMON_H_INCLUDED
|