Skip to content
Snippets Groups Projects
Commit 491c2853 authored by Marcel Loose's avatar Marcel Loose :sunglasses:
Browse files

Task #4269: Unified code layout, using uncrustify

parent 9a6bd071
No related branches found
No related tags found
No related merge requests found
Showing
with 1271 additions and 1157 deletions
......@@ -25,14 +25,17 @@
#include <cstddef>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
/*
* Returns true iff n is a power of two.
*/
template <typename T> inline static bool powerOfTwo(T n)
template <typename T>
inline static bool powerOfTwo(T n)
{
return (n | (n - 1)) == 2 * n - 1;
}
......@@ -41,7 +44,8 @@ template <typename T> inline static bool powerOfTwo(T n)
/*
* Returns the first power of two higher than n.
*/
template <typename T> inline static T nextPowerOfTwo(T n)
template <typename T>
inline static T nextPowerOfTwo(T n)
{
T p;
......@@ -55,7 +59,8 @@ template <typename T> inline static T nextPowerOfTwo(T n)
/*
* Returns `value' rounded up to `alignment'.
*/
template <typename T> inline static T align(T value, size_t alignment)
template <typename T>
inline static T align(T value, size_t alignment)
{
#if defined __GNUC__
if (__builtin_constant_p(alignment) && powerOfTwo(alignment))
......@@ -69,7 +74,8 @@ template <typename T> inline static T align(T value, size_t alignment)
/*
* Returns `value' rounded up to `alignment', in bytes.
*/
template <typename T> inline static T *align(T *value, size_t alignment)
template <typename T>
inline static T *align(T *value, size_t alignment)
{
return reinterpret_cast<T *>(align(reinterpret_cast<size_t>(value), alignment));
}
......@@ -78,7 +84,8 @@ template <typename T> inline static T *align(T *value, size_t alignment)
/*
* Returns true if `value' is aligned to `alignment'.
*/
template <typename T> inline static bool aligned(T value, size_t alignment)
template <typename T>
inline static bool aligned(T value, size_t alignment)
{
return value % alignment == 0;
}
......@@ -87,7 +94,8 @@ template <typename T> inline static bool aligned(T value, size_t alignment)
/*
* Returns true if `value' is aligned to `alignment', in bytes.
*/
template <typename T> inline static bool aligned(T *value, size_t alignment)
template <typename T>
inline static bool aligned(T *value, size_t alignment)
{
return reinterpret_cast<size_t>(value) % alignment == 0;
}
......
......@@ -4,10 +4,13 @@
#include <CoInterface/Allocator.h>
#include <memory>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
template <typename T, size_t ALIGNMENT> class AlignedStdAllocator : public std::allocator<T>
template <typename T, size_t ALIGNMENT>
class AlignedStdAllocator : public std::allocator<T>
{
// NOTE: An std::allocator cannot hold *any* state because they're
// constructed and destructed at will by the STL. The STL does not
......@@ -18,7 +21,8 @@ template <typename T, size_t ALIGNMENT> class AlignedStdAllocator : public std::
typedef typename std::allocator<T>::pointer pointer;
typedef typename std::allocator<T>::const_pointer const_pointer;
template <class U> struct rebind
template <class U>
struct rebind
{
typedef AlignedStdAllocator<U, ALIGNMENT> other;
};
......
......@@ -9,8 +9,10 @@
#include <malloc.h>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
MallocedArena::MallocedArena(size_t size, size_t alignment)
......
......@@ -6,8 +6,10 @@
#include <map>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
// There is a strict separation between a memory allocator and the physical
// memory (arena) that it manages.
......@@ -18,8 +20,14 @@ namespace RTCP {
class Arena
{
public:
void *begin() const { return itsBegin; }
size_t size() const { return itsSize; }
void *begin() const
{
return itsBegin;
}
size_t size() const
{
return itsSize;
}
protected:
void *itsBegin;
......@@ -63,13 +71,18 @@ class Allocator
/*
* Allows TYPE *foo = allocator.allocateTyped() without type-casting.
*/
class TypedAllocator {
class TypedAllocator
{
public:
TypedAllocator(Allocator &allocator, size_t alignment): allocator(allocator), alignment(alignment) {}
TypedAllocator(Allocator &allocator, size_t alignment) : allocator(allocator), alignment(alignment)
{
}
// cast-operator overloading is the only way to let C++ automatically deduce the type that we want
// to return.
template<typename T> operator T* () {
template<typename T>
operator T* ()
{
return static_cast<T*>(allocator.allocate(sizeof(T), alignment));
}
private:
......@@ -77,7 +90,10 @@ class Allocator
const size_t alignment;
};
TypedAllocator allocateTyped(size_t alignment = 1) { return TypedAllocator(*this, alignment); }
TypedAllocator allocateTyped(size_t alignment = 1)
{
return TypedAllocator(*this, alignment);
}
};
......@@ -110,7 +126,11 @@ class SparseSetAllocator : public Allocator
virtual void *allocate(size_t size, size_t alignment = 1);
virtual void deallocate(void *);
bool empty() { ScopedLock sl(mutex); return sizes.empty(); }
bool empty()
{
ScopedLock sl(mutex);
return sizes.empty();
}
private:
Mutex mutex;
......
......@@ -5,8 +5,10 @@
#include <cstring>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
extern "C" {
......@@ -66,7 +68,8 @@ static inline void _add_1_single_precision_vectors(
float *dst,
const float *src1,
unsigned count /* non-zero; multiple of 16 */
) {
)
{
// nothing to add, so just copy the values
memcpy( dst, src1, count * sizeof(float) );
}
......@@ -81,7 +84,8 @@ static inline void _add_7_single_precision_vectors(
const float *src6,
const float *src7,
unsigned count /* non-zero; multiple of 16 */
) {
)
{
_add_4_single_precision_vectors( dst, src1, src2, src3, src4, count );
_add_4_single_precision_vectors( dst, dst, src5, src6, src7, count );
}
......
......@@ -8,8 +8,10 @@
#define M_SQRT3 1.73205080756887719000
#endif
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
void BeamCoord3D::read(Stream *s)
{
......
......@@ -8,15 +8,19 @@
#include <cmath>
#include <ostream>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
// Beam coordinates are offsets for pencil beams (tied array beams) relative to the center
// of the station/beamformer beam.
class BeamCoord3D {
class BeamCoord3D
{
public:
BeamCoord3D(double ra, double dec) {
BeamCoord3D(double ra, double dec)
{
itsXYZ[0] = ra;
itsXYZ[1] = dec;
itsXYZ[2] = sqrt(1.0 - ra * ra - dec * dec);
......@@ -44,19 +48,22 @@ class BeamCoord3D {
*/
}
BeamCoord3D(double x, double y, double z) {
BeamCoord3D(double x, double y, double z)
{
itsXYZ[0] = x;
itsXYZ[1] = y;
itsXYZ[2] = z;
}
BeamCoord3D(const double xyz[3]) {
BeamCoord3D(const double xyz[3])
{
itsXYZ[0] = xyz[0];
itsXYZ[1] = xyz[1];
itsXYZ[2] = xyz[2];
}
BeamCoord3D(std::vector<double> xyz) {
BeamCoord3D(std::vector<double> xyz)
{
itsXYZ[0] = xyz[0];
itsXYZ[1] = xyz[1];
itsXYZ[2] = xyz[2];
......@@ -118,18 +125,28 @@ class BeamCoord3D {
class BeamCoordinates
{
public:
BeamCoordinates() {}
BeamCoordinates(const std::vector<BeamCoord3D> &coordinates): itsCoordinates(coordinates) {}
BeamCoordinates()
{
}
BeamCoordinates(const std::vector<BeamCoord3D> &coordinates) : itsCoordinates(coordinates)
{
}
BeamCoordinates(const Matrix<double> &coordinates);
inline std::vector<BeamCoord3D>& getCoordinates()
{ return itsCoordinates; }
{
return itsCoordinates;
}
inline size_t size() const
{ return itsCoordinates.size(); }
{
return itsCoordinates.size();
}
inline const BeamCoord3D &operator[] (unsigned nr) const
{ return itsCoordinates[nr]; }
{
return itsCoordinates[nr];
}
void read(Stream *s);
void write(Stream *s) const;
......
......@@ -9,8 +9,10 @@
#include <CoInterface/SparseSet.h>
#include <CoInterface/StreamableData.h>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
/*
* Data flow:
......
......@@ -27,8 +27,10 @@
#include <string>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
class CN_Command
{
......
......@@ -22,8 +22,10 @@
#include <CoInterface/CN_Mapping.h>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
unsigned CN_Mapping::mapCoreOnPset(unsigned core, unsigned pset)
{
......
......@@ -25,8 +25,10 @@
#define LOFAR_INTERFACE_CN_MAPPING_H
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
class CN_Mapping
{
......
......@@ -12,8 +12,10 @@
#include <Stream/Stream.h>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
class CorrelatedData : public StreamableData, public IntegratableData
{
......@@ -144,14 +146,16 @@ inline void CorrelatedData::writeData(Stream *str)
}
template <typename T> inline void addNrValidSamples(T * __restrict__ dst, const T * __restrict__ src, unsigned count)
template <typename T>
inline void addNrValidSamples(T * __restrict__ dst, const T * __restrict__ src, unsigned count)
{
for (unsigned i = 0; i < count; i++)
dst[i] += src[i];
}
template<> inline void addNrValidSamples<uint16_t>(uint16_t * __restrict__ dst, const uint16_t * __restrict__ src, unsigned count)
template<>
inline void addNrValidSamples<uint16_t>(uint16_t * __restrict__ dst, const uint16_t * __restrict__ src, unsigned count)
{
addNrValidSamples<uint32_t>(reinterpret_cast<uint32_t*>(dst), reinterpret_cast<const uint32_t*>(src), count / 2);
......@@ -160,7 +164,8 @@ template<> inline void addNrValidSamples<uint16_t>(uint16_t * __restrict__ dst,
}
template<> inline void addNrValidSamples<uint8_t>(uint8_t * __restrict__ dst, const uint8_t * __restrict__ src, unsigned count)
template<>
inline void addNrValidSamples<uint8_t>(uint8_t * __restrict__ dst, const uint8_t * __restrict__ src, unsigned count)
{
addNrValidSamples<uint16_t>(reinterpret_cast<uint16_t*>(dst), reinterpret_cast<const uint16_t*>(src), count / 2);
......
......@@ -30,8 +30,10 @@
#include <CoInterface/TriggerData.h>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
StreamableData *newStreamableData(const Parset &parset, OutputType outputType, int streamNr, Allocator &allocator)
......
......@@ -29,8 +29,10 @@
#include <CoInterface/StreamableData.h>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
StreamableData *newStreamableData(const Parset &, OutputType, int streamNr = -1, Allocator & = heapAllocator);
......
......@@ -27,8 +27,10 @@
#include <Common/Exceptions.h>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
//
// This exception will be thrown when an rtcp fails.
//
......
......@@ -8,12 +8,17 @@
#include <Common/LofarTypes.h>
#include <cmath>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
class FakeData {
class FakeData
{
public:
FakeData( const Parset &parset ): itsParset(parset) {}
FakeData( const Parset &parset ) : itsParset(parset)
{
}
void fill( FilteredData *data, unsigned subband ) const;
void check( const FilteredData *data ) const;
......@@ -25,18 +30,28 @@ class FakeData {
const Parset &itsParset;
static const double TOLERANCE = 1e-6;
template<typename T> bool equal( const T a, const T b ) const { return a == b; }
template<typename T>
bool equal( const T a, const T b ) const
{
return a == b;
}
};
template<> bool FakeData::equal( const float a, const float b ) const {
template<>
bool FakeData::equal( const float a, const float b ) const
{
return fabsf(a - b) < TOLERANCE;
}
template<> bool FakeData::equal( const double a, const double b ) const {
template<>
bool FakeData::equal( const double a, const double b ) const
{
return fabs(a - b) < TOLERANCE;
}
template<> bool FakeData::equal( const fcomplex a, const fcomplex b ) const {
template<>
bool FakeData::equal( const fcomplex a, const fcomplex b ) const
{
return equal(real(a), real(b)) && equal(imag(a), imag(b));
}
......
......@@ -9,8 +9,10 @@
#include <CoInterface/SparseSet.h>
#include <CoInterface/StreamableData.h>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
class FilteredData : public SampleData<fcomplex, 4, 2>
{
......
......@@ -26,24 +26,31 @@
#include <Common/LofarTypes.h>
#include <Common/DataConvert.h>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
// TODO: Export these functions to be globally available
template<typename T> class StreamWriter {
template<typename T>
class StreamWriter
{
public:
static void write( Stream &s, const T &data );
static void read( Stream &s, T &data );
};
template<typename T> class StreamWriter< std::vector<T> > {
template<typename T>
class StreamWriter< std::vector<T> >
{
public:
static void write( Stream &s, const std::vector<T> &data );
static void read( Stream &s, std::vector<T> &data );
};
template<> void StreamWriter<size_t>::write( Stream &s, const size_t &data )
template<>
void StreamWriter<size_t>::write( Stream &s, const size_t &data )
{
uint64 raw = data;
......@@ -54,7 +61,8 @@ template<> void StreamWriter<size_t>::write( Stream &s, const size_t &data )
s.write(&raw, sizeof raw);
}
template<> void StreamWriter<size_t>::read( Stream &s, size_t &data )
template<>
void StreamWriter<size_t>::read( Stream &s, size_t &data )
{
uint64 raw_nr;
......@@ -67,7 +75,8 @@ template<> void StreamWriter<size_t>::read( Stream &s, size_t &data )
data = raw_nr;
}
template<> void StreamWriter<std::string>::write( Stream &s, const std::string &data )
template<>
void StreamWriter<std::string>::write( Stream &s, const std::string &data )
{
size_t len = data.size();
......@@ -77,7 +86,8 @@ template<> void StreamWriter<std::string>::write( Stream &s, const std::string &
s.write(data.data(), len);
}
template<> void StreamWriter<std::string>::read( Stream &s, std::string &data )
template<>
void StreamWriter<std::string>::read( Stream &s, std::string &data )
{
size_t len;
......@@ -89,7 +99,8 @@ template<> void StreamWriter<std::string>::read( Stream &s, std::string &data )
data.assign(&buffer[0], len);
}
template<typename T> void StreamWriter< std::vector<T> >::write( Stream &s, const std::vector<T> &data )
template<typename T>
void StreamWriter< std::vector<T> >::write( Stream &s, const std::vector<T> &data )
{
size_t len = data.size();
......@@ -99,7 +110,8 @@ template<typename T> void StreamWriter< std::vector<T> >::write( Stream &s, cons
StreamWriter<T>::write(s, data[i]);
}
template<typename T> void StreamWriter< std::vector<T> >::read( Stream &s, std::vector<T> &data )
template<typename T>
void StreamWriter< std::vector<T> >::read( Stream &s, std::vector<T> &data )
{
size_t len;
......@@ -111,7 +123,8 @@ template<typename T> void StreamWriter< std::vector<T> >::read( Stream &s, std::
StreamWriter<T>::read(s, data[i]);
}
template<> void StreamWriter<struct FinalMetaData::BrokenRCU>::write( Stream &s, const struct FinalMetaData::BrokenRCU &data )
template<>
void StreamWriter<struct FinalMetaData::BrokenRCU>::write( Stream &s, const struct FinalMetaData::BrokenRCU &data )
{
StreamWriter<std::string>::write(s, data.station);
StreamWriter<std::string>::write(s, data.type);
......@@ -119,7 +132,8 @@ template<> void StreamWriter<struct FinalMetaData::BrokenRCU>::write( Stream &s,
StreamWriter<std::string>::write(s, data.time);
}
template<> void StreamWriter<struct FinalMetaData::BrokenRCU>::read( Stream &s, struct FinalMetaData::BrokenRCU &data )
template<>
void StreamWriter<struct FinalMetaData::BrokenRCU>::read( Stream &s, struct FinalMetaData::BrokenRCU &data )
{
StreamWriter<std::string>::read(s, data.station);
StreamWriter<std::string>::read(s, data.type);
......
......@@ -7,8 +7,10 @@
#include <cstddef>
#include <ostream>
namespace LOFAR {
namespace RTCP {
namespace LOFAR
{
namespace RTCP
{
class FinalMetaData
{
......@@ -19,11 +21,16 @@ class FinalMetaData
size_t seqnr; // RCU/antenna number
std::string time; // date time of break
BrokenRCU() {}
BrokenRCU()
{
}
BrokenRCU(const std::string &station, const std::string &type, size_t seqnr, const std::string &time) :
station(station), type(type), seqnr(seqnr), time(time) {}
station(station), type(type), seqnr(seqnr), time(time)
{
}
bool operator==(const BrokenRCU &other) const {
bool operator==(const BrokenRCU &other) const
{
return station == other.station && type == other.type && seqnr == other.seqnr && time == other.time;
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment