Skip to content

Commit

Permalink
apply clang-format style definition
Browse files Browse the repository at this point in the history
  • Loading branch information
passing authored and pljones committed May 16, 2021
1 parent 6d9d941 commit 2bd1654
Show file tree
Hide file tree
Showing 74 changed files with 6,508 additions and 7,983 deletions.
84 changes: 42 additions & 42 deletions android/androiddebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,60 @@
*
\******************************************************************************/

const char*const applicationName = "Jamulus";
const char* const applicationName = "Jamulus";

#ifdef ANDROIDDEBUG // Set in my myapp.pro file for android builds
#include <android/log.h>
#include <QString>
#include <QEvent>
#include <QDebug>
#include <stdio.h>
#include <math.h>
#include <string>
# include <android/log.h>
# include <QString>
# include <QEvent>
# include <QDebug>
# include <stdio.h>
# include <math.h>
# include <string>

void myMessageHandler ( QtMsgType type, const QMessageLogContext& context, const QString& msg )
{
QString report = msg;
QString report = msg;

if ( context.file && !QString ( context.file ).isEmpty() )
{
report += " in file ";
report += QString ( context.file );
report += " line ";
report += QString::number ( context.line );
}
if ( context.file && !QString ( context.file ).isEmpty() )
{
report += " in file ";
report += QString ( context.file );
report += " line ";
report += QString::number ( context.line );
}

if ( context.function && !QString ( context.function ).isEmpty() )
{
report +=+" function ";
report += QString(context.function);
}
if ( context.function && !QString ( context.function ).isEmpty() )
{
report += +" function ";
report += QString ( context.function );
}

const char*const local = report.toLocal8Bit().constData();
const char* const local = report.toLocal8Bit().constData();

switch ( type )
{
case QtDebugMsg:
__android_log_write ( ANDROID_LOG_DEBUG, applicationName, local) ;
break;
switch ( type )
{
case QtDebugMsg:
__android_log_write ( ANDROID_LOG_DEBUG, applicationName, local );
break;

case QtInfoMsg:
__android_log_write ( ANDROID_LOG_INFO, applicationName, local );
break;
case QtInfoMsg:
__android_log_write ( ANDROID_LOG_INFO, applicationName, local );
break;

case QtWarningMsg:
__android_log_write ( ANDROID_LOG_WARN, applicationName, local );
break;
case QtWarningMsg:
__android_log_write ( ANDROID_LOG_WARN, applicationName, local );
break;

case QtCriticalMsg:
__android_log_write ( ANDROID_LOG_ERROR, applicationName, local );
break;
case QtCriticalMsg:
__android_log_write ( ANDROID_LOG_ERROR, applicationName, local );
break;

case QtFatalMsg:
default:
__android_log_write ( ANDROID_LOG_FATAL, applicationName, local );
abort();
break;
}
case QtFatalMsg:
default:
__android_log_write ( ANDROID_LOG_FATAL, applicationName, local );
abort();
break;
}
}
#endif
114 changes: 70 additions & 44 deletions android/ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,42 @@
* Data is contained in a vector dynamically allocated.
*/
template<typename T>
class RingBuffer {
class RingBuffer
{
public:
/**
* @brief RingBuffer
* @param max maximum number of elements that can be contained in the ring buffer
*/
RingBuffer(std::size_t max = 0):mData(max),mRead(0),mWrite(0),mFull(false) { }
RingBuffer ( std::size_t max = 0 ) : mData ( max ), mRead ( 0 ), mWrite ( 0 ), mFull ( false ) {}

/**
* @brief Resets the ring_buffer
* @param max maximum number of elements that can be contained in the ring buffer.
*/
void reset(std::size_t max = 0) {
mData = std::vector<T>(max);
mRead = 0;
void reset ( std::size_t max = 0 )
{
mData = std::vector<T> ( max );
mRead = 0;
mWrite = 0;
mFull = false;
mFull = false;
}

/**
* @brief Current number of elements contained in the ring buffer
* @return
*/
std::size_t size() const {
std::size_t size() const
{
std::size_t size = capacity();
if(!mFull) {
if(mWrite >= mRead) {
if ( !mFull )
{
if ( mWrite >= mRead )
{
size = mWrite - mRead;
} else {
}
else
{
size = capacity() + mWrite - mRead;
}
}
Expand All @@ -75,7 +82,7 @@ class RingBuffer {
* @brief whether the ring buffer is empty.
* @return
*/
bool isEmpty() const { return !isFull() && (mRead == mWrite); }
bool isEmpty() const { return !isFull() && ( mRead == mWrite ); }

/**
* @brief Maximum number of elements in the ring buffer
Expand All @@ -87,7 +94,8 @@ class RingBuffer {
* @brief Adds a single value
* @param v the value to add
*/
void put(const T &v) {
void put ( const T& v )
{
mData[mWrite] = v;
forward();
}
Expand All @@ -97,12 +105,16 @@ class RingBuffer {
* @param v the value read
* @return true if the value was read
*/
bool get(T&v) {
if(!isEmpty()) {
bool get ( T& v )
{
if ( !isEmpty() )
{
v = mData[mRead];
backward();
return true;
} else {
}
else
{
return false;
}
}
Expand All @@ -112,13 +124,15 @@ class RingBuffer {
* @param v pointer to the consecutive values
* @param count number of consecutive values.
*/
void put(const T *v, std::size_t count) {
std::size_t avail = mWrite - capacity();
std::size_t to_copy = std::min(count,avail);
memcpy(mData.data() + mWrite,v, to_copy*sizeof(T));
forward(to_copy);
if(to_copy < count) {
put(v+to_copy,count - to_copy);
void put ( const T* v, std::size_t count )
{
std::size_t avail = mWrite - capacity();
std::size_t to_copy = std::min ( count, avail );
memcpy ( mData.data() + mWrite, v, to_copy * sizeof ( T ) );
forward ( to_copy );
if ( to_copy < count )
{
put ( v + to_copy, count - to_copy );
}
}

Expand All @@ -128,45 +142,57 @@ class RingBuffer {
* @param count Maximum available size in the memory area
* @return actual number of elements read.
*/
std::size_t get(T *v, std::size_t count) {
std::size_t get ( T* v, std::size_t count )
{
std::size_t avail = 0;
if(mRead < mWrite) {
if ( mRead < mWrite )
{
avail = mWrite - mRead;
} else {
}
else
{
avail = mRead - capacity();
}
std::size_t to_copy = std::min(count, avail);
memcpy(v, mData.data() + mRead, to_copy * sizeof(T));
backward(to_copy);
if((size()>0)&&(count > to_copy)) {
return to_copy + get(v + to_copy, count - to_copy);
} else {
std::size_t to_copy = std::min ( count, avail );
memcpy ( v, mData.data() + mRead, to_copy * sizeof ( T ) );
backward ( to_copy );
if ( ( size() > 0 ) && ( count > to_copy ) )
{
return to_copy + get ( v + to_copy, count - to_copy );
}
else
{
return to_copy;
}
}

private:
void forward() {
if(isFull()) {
mRead = (mRead + 1) % capacity();
void forward()
{
if ( isFull() )
{
mRead = ( mRead + 1 ) % capacity();
}
mWrite = (mWrite + 1) % capacity();
mFull = (mRead == mWrite);
mWrite = ( mWrite + 1 ) % capacity();
mFull = ( mRead == mWrite );
}

void forward(std::size_t count) {
for(std::size_t i=0; i<count;i++) {
void forward ( std::size_t count )
{
for ( std::size_t i = 0; i < count; i++ )
{
forward();
}
}

void backward(std::size_t count) {
void backward ( std::size_t count )
{
mFull = false;
mRead = (mRead + count) % capacity();
mRead = ( mRead + count ) % capacity();
}

std::vector<T> mData;
std::size_t mRead; /** offset to reading point */
std::size_t mWrite; /** offset to writing point */
bool mFull;
std::size_t mRead; /** offset to reading point */
std::size_t mWrite; /** offset to writing point */
bool mFull;
};

Loading

0 comments on commit 2bd1654

Please sign in to comment.