Skip to content
Snippets Groups Projects
Commit 0ed87326 authored by Ger van Diepen's avatar Ger van Diepen
Browse files

bug 1397:

Define an int8 and uint8 type for clearer signedness of char types.
parent 222b5a7d
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ AC_INIT
dnl AC_CONFIG_AUX_DIR(config)
dnl AM_CONFIG_HEADER(config/config.h)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(Common, 3.1, no-define)
AM_INIT_AUTOMAKE(Common, 3.3, no-define)
dnl Initialize for LOFAR (may set compilers)
lofar_INIT
......
......@@ -66,7 +66,8 @@ namespace LOFAR
// These functions can be used in templates.
// <group>
void dataConvert (DataFormat, char* inout, uint nrval);
void dataConvert (DataFormat, uchar* inout, uint nrval);
void dataConvert (DataFormat, int8* inout, uint nrval);
void dataConvert (DataFormat, uint8* inout, uint nrval);
void dataConvert (DataFormat, int16* inout, uint nrval);
void dataConvert (DataFormat, uint16* inout, uint nrval);
void dataConvert (DataFormat, int32* inout, uint nrval);
......@@ -84,11 +85,12 @@ namespace LOFAR
LFDC_TMPL_FP void dataConvert (DataFormat, dcomplex* inout, uint nrval);
// </group>
// \name Convert char or uchar.
// \name Convert char, int8, or uint8.
// Currently it simply returns the input.
// <group>
char dataConvert (DataFormat, char in);
unsigned char dataConvert (DataFormat, unsigned char in);
int8 dataConvert (DataFormat, int8 in);
uint8 dataConvert (DataFormat, uint8 in);
// </group>
// \name Convert 16 bit integers.
......@@ -190,7 +192,9 @@ namespace LOFAR
inline void dataConvert (DataFormat, char*, uint)
{}
inline void dataConvert (DataFormat, uchar*, uint)
inline void dataConvert (DataFormat, int8*, uint)
{}
inline void dataConvert (DataFormat, uint8*, uint)
{}
inline void dataConvert (DataFormat fmt, int16* inout, uint nrval)
{ dataConvert16 (fmt, inout, nrval); }
......@@ -223,7 +227,9 @@ namespace LOFAR
inline char dataConvert (DataFormat, char in)
{ return in; }
inline unsigned char dataConvert (DataFormat, unsigned char in)
inline int8 dataConvert (DataFormat, int8 in)
{ return in; }
inline uint8 dataConvert (DataFormat, uint8 in)
{ return in; }
inline int16 dataConvert (DataFormat, int16 in)
......
......@@ -45,11 +45,11 @@ namespace LOFAR {
typedef long double ldouble;
// Fixed data sizes.
typedef char int8;
typedef unsigned char uint8;
typedef signed char int8;
typedef short int16;
typedef int int32;
typedef long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
......
......@@ -45,7 +45,7 @@ namespace LOFAR
{
//# Make the type names defined in LofarTypedefs.h available in the
//# namespace LOFAR.
//# Note that QT defines ushort, uint, and ulong.
//# Note that QT defines uchar, uint, and ulong.
//# Otherwise check if it's there.
#ifdef HAVE_QT
using ::uchar;
......
......@@ -46,7 +46,8 @@ namespace LOFAR
const std::string& typeName (const void*);
const std::string& typeName (const bool*);
const std::string& typeName (const char*);
const std::string& typeName (const uchar*);
const std::string& typeName (const int8*);
const std::string& typeName (const uint8*);
const std::string& typeName (const int16*);
const std::string& typeName (const uint16*);
const std::string& typeName (const int32*);
......@@ -68,7 +69,7 @@ namespace LOFAR
const std::string& typeName (const std::complex<float>*);
const std::string& typeName (const std::complex<double>*);
#endif
template<typename T> const std::string& typeName (T**);
template<typename T> const std::string& typeName (T const* const*);
// </group>
......
......@@ -30,7 +30,7 @@
namespace LOFAR
{
template<typename T>
const std::string& typeName (const T**)
const std::string& typeName (T const* const*)
{
static std::string str ("array<" + typeName((const T*)0) + ">");
return str;
......
......@@ -47,7 +47,14 @@ namespace LOFAR
return str;
}
const std::string& typeName (const uchar*)
const std::string& typeName (const int8*)
{
// This is also char (for backward compatibility).
static std::string str ("char");
return str;
}
const std::string& typeName (const uint8*)
{
static std::string str ("uchar");
return str;
......
# programs to run through supplied checktools
CHECKTOOLPROGS = testLogger tAllocator tDataConvert \
CHECKTOOLPROGS = testLogger tAllocator tDataConvert tTypeNames \
tFileLocator tStringUtil tStreamUtil \
tHexdump testSocket tComplex tProcess \
tRunOnNode tTimer tNumeric tSingleton \
......@@ -9,7 +9,7 @@ CHECKTOOLPROGS = testLogger tAllocator tDataConvert \
check_PROGRAMS = $(CHECKTOOLPROGS)
TESTSCRIPTS = testLogger.sh tAllocator.sh tDataConvert.sh \
TESTSCRIPTS = testLogger.sh tAllocator.sh tDataConvert.sh tTypeNames.sh \
tFileLocator.sh tStringUtil.sh tStreamUtil.sh \
tHexdump.sh testSocket.sh tComplex.sh tProcess.sh \
tRunOnNode.sh tTimer.sh tNumeric.sh tSingleton.sh \
......@@ -47,6 +47,7 @@ EXTRA_DIST = $(TESTSCRIPTS) \
testLogger_SOURCES = testLogger.cc
tAllocator_SOURCES = tAllocator.cc
tDataConvert_SOURCES = tDataConvert.cc
tTypeNames_SOURCES = tTypeNames.cc
tFileLocator_SOURCES = tFileLocator.cc
tStringUtil_SOURCES = tStringUtil.cc
tStreamUtil_SOURCES = tStreamUtil.cc
......
//# tTypeNames.cc: Test program for the TypeNames functions
//#
//# Copyright (C) 2009
//# ASTRON (Netherlands Foundation for Research in Astronomy)
//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
//#
//# This program is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//# This program is distributed in the hope that it will be useful,
//# but WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//# GNU General Public License for more details.
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//#
//# $Id$
//# Always #include <lofar_config.h> first!
#include <lofar_config.h>
//# Includes
#include <Common/TypeNames.h>
#include <Common/lofar_iostream.h>
#include <Common/LofarLogger.h>
#include <stdexcept>
using namespace LOFAR;
int main()
{
try {
void* vp = 0;
bool* bp = 0;
char* cp = 0;
uchar* ucp = 0;
int8* i8p = 0;
uint8* u8p = 0;
int16* i16p = 0;
uint16* u16p = 0;
int32* i32p = 0;
uint32* u32p = 0;
int64* i64p = 0;
uint64* u64p = 0;
float* fp = 0;
double* dp = 0;
fcomplex* fcp = 0;
dcomplex* dcp = 0;
ASSERT (typeName(vp) == "unknown");
ASSERT (typeName(bp) == "bool");
ASSERT (typeName(cp) == "char");
ASSERT (typeName(ucp) == "uchar");
ASSERT (typeName(i8p) == "char");
ASSERT (typeName(u8p) == "uchar");
ASSERT (typeName(i16p) == "int16");
ASSERT (typeName(u16p) == "uint16");
ASSERT (typeName(i32p) == "int32");
ASSERT (typeName(u32p) == "uint32");
ASSERT (typeName(i64p) == "int64");
ASSERT (typeName(u64p) == "uint64");
ASSERT (typeName(fp) == "float");
ASSERT (typeName(dp) == "double");
ASSERT (typeName(fcp) == "fcomplex");
ASSERT (typeName(dcp) == "dcomplex");
ASSERT (typeName(&fp) == "array<float>");
} catch (std::exception& x) {
cout << x.what() << endl;
return 1;
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment