adjusts braces to agreed conventions

This commit is contained in:
tosh 2013-04-04 10:52:42 +02:00
parent f859d8ed9c
commit 7d479af9c7
6 changed files with 111 additions and 108 deletions

View file

@ -11,22 +11,22 @@
#include <math.h>
struct Degrees
{
struct Degrees {
static float pi() { return 180.0f; }
static float twicePi() { return 360.0f; }
static float halfPi() { return 90.0f; }
};
struct Radians
{
struct Radians {
static float pi() { return 3.141592653589793f; }
static float twicePi() { return 6.283185307179586f; }
static float halfPi() { return 1.5707963267948966; }
};
struct Rotations
{
struct Rotations {
static float pi() { return 0.5f; }
static float twicePi() { return 1.0f; }
static float halfPi() { return 0.25f; }
@ -36,8 +36,8 @@ struct Rotations
* Converts an angle from one unit to another.
*/
template< class UnitFrom, class UnitTo >
float angleConvert(float a)
{
float angleConvert(float a) {
return a * (UnitTo::halfPi() / UnitFrom::halfPi());
}
@ -46,8 +46,8 @@ float angleConvert(float a)
* Clamps an angle to the range of [-180; 180) degrees.
*/
template< class Unit >
float angleSignedNormal(float a)
{
float angleSignedNormal(float a) {
float result = remainder(a, Unit::twicePi());
if (result == Unit::pi())
result = -Unit::pi();
@ -58,8 +58,8 @@ float angleSignedNormal(float a)
* Clamps an angle to the range of [0; 360) degrees.
*/
template< class Unit >
float angleUnsignedNormal(float a)
{
float angleUnsignedNormal(float a) {
return angleSignedNormal<Unit>(a - Unit::pi()) + Unit::pi();
}
@ -72,16 +72,16 @@ float angleUnsignedNormal(float a)
* Both poles can be reached from any azimuthal direction.
*/
template< class Unit >
void angleHorizontalPolar(float& azimuth, float& altitude)
{
void angleHorizontalPolar(float& azimuth, float& altitude) {
altitude = angleSignedNormal<Unit>(altitude);
if (altitude > Unit::halfPi())
{
if (altitude > Unit::halfPi()) {
altitude = Unit::pi() - altitude;
azimuth += Unit::pi();
}
else if (altitude < -Unit::halfPi())
{
} else if (altitude < -Unit::halfPi()) {
altitude = -Unit::pi() - altitude;
azimuth += Unit::pi();
}

View file

@ -18,8 +18,8 @@ void floodFill(Cursor const& position,
template< class Strategy, typename Cursor >
struct floodFill_impl : Strategy
{
struct floodFill_impl : Strategy {
floodFill_impl(Strategy const& s) : Strategy(s) { }
using Strategy::select;
@ -33,14 +33,15 @@ struct floodFill_impl : Strategy
using Strategy::defer;
using Strategy::deferred;
void go(Cursor position)
{
void go(Cursor position) {
Cursor higher, lower, h,l, i;
bool higherFound, lowerFound, hf, lf;
do
{
if (! select(position))
do {
if (! select(position)) {
continue;
}
process(position);
@ -51,33 +52,39 @@ struct floodFill_impl : Strategy
i = position, h = higher, l = lower;
hf = higherFound, lf = lowerFound;
do { right(i), right(h), right(l); yTest(h,hf); yTest(l,lf); }
while (selectAndProcess(i));
do {
right(i), right(h), right(l); yTest(h,hf); yTest(l,lf);
} while (selectAndProcess(i));
i = position, h = higher, l = lower;
hf = higherFound, lf = lowerFound;
do { left(i); left(h); left(l); yTest(h,hf); yTest(l,lf); }
while (selectAndProcess(i));
}
while (deferred(position));
do {
left(i); left(h); left(l); yTest(h,hf); yTest(l,lf);
} while (selectAndProcess(i));
} while (deferred(position));
}
bool selectAndProcess(Cursor const& i)
{
if (select(i))
{
bool selectAndProcess(Cursor const& i) {
if (select(i)) {
process(i);
return true;
}
return false;
}
void yTest(Cursor const& i, bool& state)
{
if (! select(i))
void yTest(Cursor const& i, bool& state) {
if (! select(i)) {
state = false;
else if (! state)
{
} else if (! state) {
state = true;
defer(i);
}
@ -85,8 +92,8 @@ struct floodFill_impl : Strategy
};
template< class Strategy, typename Cursor >
void floodFill(Cursor const& p, Strategy const& s)
{
void floodFill(Cursor const& p, Strategy const& s) {
floodFill_impl<Strategy,Cursor>(s).go(p);
}

View file

@ -25,30 +25,27 @@ void radix2InplaceSort( BidiIterator from, BidiIterator to,
template< class Scanner, typename Iterator >
struct radix2InplaceSort_impl : Scanner
{
struct radix2InplaceSort_impl : Scanner {
radix2InplaceSort_impl(Scanner const& s) : Scanner(s) { }
using Scanner::advance;
using Scanner::bit;
void go(Iterator& from, Iterator& to, typename Scanner::state_type s)
{
void go(Iterator& from, Iterator& to, typename Scanner::state_type s) {
Iterator l(from), r(to);
unsigned cl, cr;
using std::swap;
for (;;)
{
while (true) {
// scan from left for set bit
for (cl = cr = 0u; l != r ; ++l, ++cl)
if (bit(*l, s))
{
if (bit(*l, s)) {
// scan from the right for unset bit
for (++cr; --r != l ;++cr)
if (! bit(*r, s))
{
if (! bit(*r, s)) {
// swap, continue scanning from left
swap(*l, *r);
break;
@ -58,22 +55,23 @@ struct radix2InplaceSort_impl : Scanner
}
// on to the next digit, if any
if (! advance(s))
if (! advance(s)) {
return;
}
// recurse into smaller branch and prepare iterative
// processing of the other
if (cl < cr)
{
if (cl < cr) {
if (cl > 1u) go(from, l, s);
else if (cr <= 1u)
return;
l = from = r;
r = to;
}
else
{
} else {
if (cr > 1u) go(r, to, s);
else if (cl <= 1u)
return;
@ -87,8 +85,8 @@ struct radix2InplaceSort_impl : Scanner
template< class Radix2Scanner, typename BidiIterator >
void radix2InplaceSort( BidiIterator from, BidiIterator to,
Radix2Scanner const& scanner)
{
Radix2Scanner const& scanner) {
radix2InplaceSort_impl<Radix2Scanner, BidiIterator>(scanner)
.go(from, to, scanner.initial_state());
}

View file

@ -12,8 +12,8 @@
#include <stddef.h>
#include <stdint.h>
namespace type_traits // those are needed for the declaration, see below
{
namespace type_traits { // those are needed for the declaration, see below
// Note: There are better / more generally appicable implementations
// in C++11, make_signed is missing in TR1 too - so I just use C++98
// hacks that get the job done...
@ -39,8 +39,8 @@ class Radix2IntegerScanner;
template< typename UInt >
class Radix2IntegerScanner< UInt, false >
{
class Radix2IntegerScanner< UInt, false > {
UInt valMsb;
public:
@ -48,9 +48,8 @@ class Radix2IntegerScanner< UInt, false >
: valMsb(~UInt(0) &~ (~UInt(0) >> 1)) { }
explicit Radix2IntegerScanner(int bits)
: valMsb(UInt(1u) << (bits - 1))
{ }
: valMsb(UInt(1u) << (bits - 1)) {
}
typedef UInt state_type;
@ -67,12 +66,12 @@ class Radix2IntegerScanner< Int, true >
public:
Radix2IntegerScanner()
: valMsb(~state_type(0u) &~ (~state_type(0u) >> 1))
{ }
: valMsb(~state_type(0u) &~ (~state_type(0u) >> 1)) {
}
explicit Radix2IntegerScanner(int bits)
: valMsb(state_type(1u) << (bits - 1))
{ }
: valMsb(state_type(1u) << (bits - 1)) {
}
typedef typename type_traits::make_unsigned<Int>::type state_type;

View file

@ -23,8 +23,8 @@ char const* const UrlReader::error_leftover_input = "UrlReader: Incomplete pro
#define hnd_curl static_cast<CURL*>(_ptrImpl)
UrlReader::UrlReader()
: _ptrImpl(0l), _arrXtra(0l), _strError(0l)
{
: _ptrImpl(0l), _arrXtra(0l), _strError(0l) {
_arrXtra = new(std::nothrow) char[max_read_ahead];
if (! _arrXtra) { _strError = error_init_failed; return; }
_ptrImpl = curl_easy_init();
@ -34,15 +34,15 @@ UrlReader::UrlReader()
curl_easy_setopt(hnd_curl, CURLOPT_FILETIME, 1l);
}
UrlReader::~UrlReader()
{
UrlReader::~UrlReader() {
delete _arrXtra;
if (! hnd_curl) return;
curl_easy_cleanup(hnd_curl);
}
bool UrlReader::perform(char const* url, transfer_callback* cb)
{
bool UrlReader::perform(char const* url, transfer_callback* cb) {
curl_easy_setopt(hnd_curl, CURLOPT_URL, url);
curl_easy_setopt(hnd_curl, CURLOPT_WRITEFUNCTION, cb);
curl_easy_setopt(hnd_curl, CURLOPT_WRITEDATA, this);
@ -61,8 +61,8 @@ bool UrlReader::perform(char const* url, transfer_callback* cb)
}
void UrlReader::getinfo(char const*& url,
char const*& type, int64_t& length, int64_t& stardate)
{
char const*& type, int64_t& length, int64_t& stardate) {
curl_easy_getinfo(hnd_curl, CURLINFO_EFFECTIVE_URL, & url);
curl_easy_getinfo(hnd_curl, CURLINFO_CONTENT_TYPE, & type);

View file

@ -17,8 +17,8 @@
* UrlReader class that encapsulates a context for sequential data retrieval
* via URLs. Use one per thread.
*/
class UrlReader
{
class UrlReader {
void* _ptrImpl;
char* _arrXtra;
char const* _strError;
@ -149,8 +149,7 @@ class UrlReader
};
template< class ContentStream >
bool UrlReader::readUrl(char const* url, ContentStream& s)
{
bool UrlReader::readUrl(char const* url, ContentStream& s) {
if (! _ptrImpl) return false;
_strError = success;
_ptrStream = & s;
@ -162,24 +161,24 @@ bool UrlReader::readUrl(char const* url, ContentStream& s)
inline char const* UrlReader::getError() const { return this->_strError; }
inline void UrlReader::setError(char const* static_c_string)
{
inline void UrlReader::setError(char const* static_c_string) {
if (this->_strError == success)
this->_strError = static_c_string;
}
template< class Stream >
size_t UrlReader::callback_template(
char *input, size_t size, size_t nmemb, void* thiz)
{
char *input, size_t size, size_t nmemb, void* thiz) {
size *= nmemb;
UrlReader* me = static_cast<UrlReader*>(thiz);
Stream* stream = static_cast<Stream*>(me->_ptrStream);
// first call?
if (me->_valXtraSize == ~size_t(0))
{
if (me->_valXtraSize == ~size_t(0)) {
me->_valXtraSize = 0u;
// extract meta information and call 'begin'
char const* url, * type;
@ -190,14 +189,14 @@ size_t UrlReader::callback_template(
size_t input_offset = 0u;
for (;;)
{
while (true) {
char* buffer = input + input_offset;
size_t bytes = size - input_offset;
// data in extra buffer?
if (me->_valXtraSize > 0)
{
if (me->_valXtraSize > 0) {
// fill extra buffer with beginning of input
size_t fill = max_read_ahead - me->_valXtraSize;
if (bytes < fill) fill = bytes;
@ -210,36 +209,36 @@ size_t UrlReader::callback_template(
// call 'transfer'
size_t processed = stream->transfer(buffer, bytes);
if (processed == abort)
{
if (processed == abort) {
me->setError(error_aborted);
return 0u;
}
else if (! processed && ! input)
{
} else if (! processed && ! input) {
me->setError(error_leftover_input);
return 0u;
}
size_t unprocessed = bytes - processed;
// can switch to input buffer, now?
if (buffer == me->_arrXtra && unprocessed <= input_offset)
{
if (buffer == me->_arrXtra && unprocessed <= input_offset) {
me->_valXtraSize = 0u;
input_offset -= unprocessed;
}
else // no? unprocessed data -> extra buffer
{
if (unprocessed > max_read_ahead)
{
} else { // no? unprocessed data -> extra buffer
if (unprocessed > max_read_ahead) {
me->setError(error_buffer_overflow);
return 0;
}
me->_valXtraSize = unprocessed;
memmove(me->_arrXtra, buffer + processed, unprocessed);
if (input_offset == size || buffer != me->_arrXtra)
{
if (input_offset == size || buffer != me->_arrXtra) {
return size;
}
}