Add doc strings to remaining assertions

This commit is contained in:
Chris Thrasher 2023-07-02 10:08:58 -06:00
parent 1cc9738dcb
commit 98df0fe4c9
20 changed files with 42 additions and 40 deletions

View File

@ -62,7 +62,7 @@ protected:
static const sf::Font& getFont()
{
assert(s_font != nullptr);
assert(s_font != nullptr && "Cannot get font until setFont() is called");
return *s_font;
}

View File

@ -28,7 +28,7 @@ constexpr float pi = 3.141592654f;
constexpr float positiveRemainder(float a, float b)
{
assert(b > 0.0f);
assert(b > 0.0f && "Cannot calculate remainder with non-positive divisor");
const float val = a - static_cast<float>(static_cast<int>(a / b)) * b;
if (val >= 0.f)
return val;

View File

@ -141,7 +141,7 @@ FLAC__StreamDecoderWriteStatus streamWrite(const FLAC__StreamDecoder*,
sample = static_cast<std::int16_t>(buffer[j][i] >> 16);
break;
default:
assert(false);
assert(false && "Invalid bits per sample. Must be 8, 16, 24, or 32.");
break;
}
@ -271,7 +271,7 @@ bool SoundFileReaderFlac::open(InputStream& stream, Info& info)
////////////////////////////////////////////////////////////
void SoundFileReaderFlac::seek(std::uint64_t sampleOffset)
{
assert(m_decoder);
assert(m_decoder && "No decoder available. Call SoundFileReaderFlac::open() to create a new one.");
// Reset the callback data (the "write" callback will be called)
m_clientData.buffer = nullptr;
@ -300,7 +300,7 @@ void SoundFileReaderFlac::seek(std::uint64_t sampleOffset)
////////////////////////////////////////////////////////////
std::uint64_t SoundFileReaderFlac::read(std::int16_t* samples, std::uint64_t maxCount)
{
assert(m_decoder);
assert(m_decoder && "No decoder available. Call SoundFileReaderFlac::open() to create a new one.");
// If there are leftovers from previous call, use it first
const std::size_t left = m_clientData.leftovers.size();

View File

@ -128,7 +128,7 @@ bool SoundFileReaderOgg::open(InputStream& stream, Info& info)
////////////////////////////////////////////////////////////
void SoundFileReaderOgg::seek(std::uint64_t sampleOffset)
{
assert(m_vorbis.datasource);
assert(m_vorbis.datasource && "Vorbis datasource is missing. Call SoundFileReaderOgg::open() to initialize it.");
ov_pcm_seek(&m_vorbis, static_cast<ogg_int64_t>(sampleOffset / m_channelCount));
}
@ -137,7 +137,7 @@ void SoundFileReaderOgg::seek(std::uint64_t sampleOffset)
////////////////////////////////////////////////////////////
std::uint64_t SoundFileReaderOgg::read(std::int16_t* samples, std::uint64_t maxCount)
{
assert(m_vorbis.datasource);
assert(m_vorbis.datasource && "Vorbis datasource is missing. Call SoundFileReaderOgg::open() to initialize it.");
// Try to read the requested number of samples, stop only on error or end of file
std::uint64_t count = 0;

View File

@ -141,7 +141,7 @@ bool SoundFileReaderWav::open(InputStream& stream, Info& info)
////////////////////////////////////////////////////////////
void SoundFileReaderWav::seek(std::uint64_t sampleOffset)
{
assert(m_stream);
assert(m_stream && "Input stream cannot be null. Call SoundFileReaderWav::open() to initialize it.");
if (m_stream->seek(static_cast<std::int64_t>(m_dataStart + sampleOffset * m_bytesPerSample) == -1))
err() << "Failed to seek WAV sound stream" << std::endl;
@ -151,7 +151,7 @@ void SoundFileReaderWav::seek(std::uint64_t sampleOffset)
////////////////////////////////////////////////////////////
std::uint64_t SoundFileReaderWav::read(std::int16_t* samples, std::uint64_t maxCount)
{
assert(m_stream);
assert(m_stream && "Input stream cannot be null. Call SoundFileReaderWav::open() to initialize it.");
std::uint64_t count = 0;
const auto startPos = static_cast<std::uint64_t>(m_stream->tell());
@ -204,7 +204,7 @@ std::uint64_t SoundFileReaderWav::read(std::int16_t* samples, std::uint64_t maxC
default:
{
assert(false);
assert(false && "Invalid bytes per sample. Must be 1, 2, 3, or 4.");
return 0;
}
}
@ -219,7 +219,7 @@ std::uint64_t SoundFileReaderWav::read(std::int16_t* samples, std::uint64_t maxC
////////////////////////////////////////////////////////////
bool SoundFileReaderWav::parseHeader(Info& info)
{
assert(m_stream);
assert(m_stream && "Input stream cannot be null. Call SoundFileReaderWav::open() to initialize it.");
// If we are here, it means that the first part of the header
// (the format) has already been checked

View File

@ -138,7 +138,7 @@ void SoundFileWriterOgg::write(const std::int16_t* samples, std::uint64_t count)
{
// Prepare a buffer to hold our samples
float** buffer = vorbis_analysis_buffer(&m_state, bufferSize);
assert(buffer);
assert(buffer && "Vorbis buffer failed to allocate");
// Write the samples to the buffer, converted to float
for (int i = 0; i < std::min(frameCount, bufferSize); ++i)

View File

@ -110,7 +110,7 @@ bool SoundFileWriterWav::open(const std::filesystem::path& filename, unsigned in
////////////////////////////////////////////////////////////
void SoundFileWriterWav::write(const std::int16_t* samples, std::uint64_t count)
{
assert(m_file.good());
assert(m_file.good() && "Most recent I/O operation failed");
while (count--)
encode(m_file, *samples++);
@ -120,7 +120,7 @@ void SoundFileWriterWav::write(const std::int16_t* samples, std::uint64_t count)
////////////////////////////////////////////////////////////
bool SoundFileWriterWav::writeHeader(unsigned int sampleRate, unsigned int channelCount)
{
assert(m_file.good());
assert(m_file.good() && "Most recent I/O operation failed");
// Write the main chunk ID
char mainChunkId[4] = {'R', 'I', 'F', 'F'};

View File

@ -332,7 +332,7 @@ void SoundRecorder::launchCapturingThread()
{
m_isCapturing = true;
assert(!m_thread.joinable());
assert(!m_thread.joinable() && "Capture thread is already running");
m_thread = std::thread(&SoundRecorder::record, this);
}

View File

@ -508,7 +508,7 @@ void SoundStream::launchStreamingThread(Status threadStartState)
m_threadStartState = threadStartState;
}
assert(!m_thread.joinable());
assert(!m_thread.joinable() && "Background thread is still running");
m_thread = std::thread(&SoundStream::streamData, this);
}

View File

@ -137,7 +137,7 @@ Vector2f Shape::getGeometricCenter() const
switch (count)
{
case 0:
assert(false);
assert(false && "Cannot calculate geometric center of shape with no points");
return Vector2f{};
case 1:
return getPoint(0);

View File

@ -130,7 +130,7 @@ FloatRect Sprite::getGlobalBounds() const
////////////////////////////////////////////////////////////
void Sprite::draw(RenderTarget& target, const RenderStates& states) const
{
assert(m_texture);
assert(m_texture && "Cannot use null texture. Call Sprite::setTexture() to initialize it.");
RenderStates statesCopy(states);

View File

@ -453,8 +453,8 @@ void Texture::update(const std::uint8_t* pixels)
////////////////////////////////////////////////////////////
void Texture::update(const std::uint8_t* pixels, const Vector2u& size, const Vector2u& dest)
{
assert(dest.x + size.x <= m_size.x);
assert(dest.y + size.y <= m_size.y);
assert(dest.x + size.x <= m_size.x && "Destination x coordinate is outside of texture");
assert(dest.y + size.y <= m_size.y && "Destination y coordinate is outside of texture");
if (pixels && m_texture)
{
@ -497,8 +497,8 @@ void Texture::update(const Texture& texture)
////////////////////////////////////////////////////////////
void Texture::update(const Texture& texture, const Vector2u& dest)
{
assert(dest.x + texture.m_size.x <= m_size.x);
assert(dest.y + texture.m_size.y <= m_size.y);
assert(dest.x + texture.m_size.x <= m_size.x && "Destination x coordinate is outside of texture");
assert(dest.y + texture.m_size.y <= m_size.y && "Destination y coordinate is outside of texture");
if (!m_texture || !texture.m_texture)
return;
@ -630,8 +630,8 @@ void Texture::update(const Window& window)
////////////////////////////////////////////////////////////
void Texture::update(const Window& window, const Vector2u& dest)
{
assert(dest.x + window.getSize().x <= m_size.x);
assert(dest.y + window.getSize().y <= m_size.y);
assert(dest.x + window.getSize().x <= m_size.x && "Destination x coordinate is outside of texture");
assert(dest.y + window.getSize().y <= m_size.y && "Destination y coordinate is outside of texture");
if (m_texture && window.setActive(true))
{

View File

@ -84,7 +84,7 @@ int getAndroidApiLevel(ANativeActivity* activity)
////////////////////////////////////////////////////////////
ActivityStates* retrieveStates(ANativeActivity* activity)
{
assert(activity != nullptr);
assert(activity != nullptr && "Activity cannot be null");
// Hide the ugly cast we find in each callback function
return static_cast<ActivityStates*>(activity->instance);

View File

@ -71,7 +71,8 @@ void resetActivity(ActivityStates* initializedStates)
ActivityStates& getActivity()
{
ActivityStates* const states = getActivityStatesPtr();
assert(states != nullptr);
assert(states != nullptr &&
"Cannot dereference null activity states pointer. Call priv::resetActivity() to initialize it.");
return *states;
}

View File

@ -355,7 +355,7 @@ EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixe
}
}
assert(bestScore < 0x7FFFFFFF);
assert(bestScore < 0x7FFFFFFF && "Failed to calculate best config");
return bestConfig;
}

View File

@ -333,7 +333,7 @@ struct GlContext::TransientContext
{
// TransientContext should never be created if there is
// already a context active on the current thread
assert(!GlContextImpl::CurrentContext::get().id);
assert(!GlContextImpl::CurrentContext::get().id && "Another context is active on the current thread");
// Lock ourselves so we don't create a new object if one doesn't already exist
sharedContext = SharedContext::getWeakPtr().lock();
@ -346,7 +346,7 @@ struct GlContext::TransientContext
else
{
// GlResources exist, currentContextId not yet set
assert(sharedContext);
assert(sharedContext && "Shared context does not exist");
// Lock the shared context for temporary use
sharedContextLock = std::unique_lock(sharedContext->mutex);
@ -520,14 +520,14 @@ void GlContext::acquireTransientContext()
}
// If we don't already have a context active on this thread the count should be 0
assert(!currentContext.transientCount);
assert(!currentContext.transientCount && "Transient count cannot be non-zero");
// If currentContextId is not set, this must be the first
// TransientContextLock on this thread, construct the state object
TransientContext::get().emplace();
// Make sure a context is active at this point
assert(currentContext.id);
assert(currentContext.id && "Current context ID cannot be zero");
}
@ -537,7 +537,7 @@ void GlContext::releaseTransientContext()
auto& currentContext = GlContextImpl::CurrentContext::get();
// Make sure a context was left active after acquireTransientContext() was called
assert(currentContext.id);
assert(currentContext.id && "Current context ID cannot be zero");
// Fast path if we already had a context active on this thread before acquireTransientContext() was called
if (currentContext.transientCount)

View File

@ -82,7 +82,7 @@ void closeDisplay(Display* display)
{
const std::lock_guard lock(mutex);
assert(display == sharedDisplay);
assert(display == sharedDisplay && "Display must match shared display");
--referenceCount;
if (referenceCount == 0)
@ -94,7 +94,7 @@ XIM openXim()
{
const std::lock_guard lock(mutex);
assert(sharedDisplay != nullptr);
assert(sharedDisplay != nullptr && "Shared display is null. Call priv::openDisplay() to initialize it.");
if (referenceCountXIM == 0)
{
@ -132,7 +132,7 @@ void closeXim(XIM xim)
{
const std::lock_guard lock(mutex);
assert(xim == sharedXIM);
assert(xim == sharedXIM && "XIM must match shared XIM");
--referenceCountXIM;

View File

@ -199,7 +199,8 @@ WglContext::~WglContext()
////////////////////////////////////////////////////////////
GlFunctionPointer WglContext::getFunction(const char* name)
{
assert(WglContextImpl::currentContext != nullptr);
assert(WglContextImpl::currentContext != nullptr &&
"Current WGL context cannot be null. Call WglContext::makeCurrent() to initialize it.");
// If we are using the generic GDI implementation, skip to loading directly from OpenGL32.dll since it doesn't support extensions
if (!WglContextImpl::currentContext->m_isGeneric)

View File

@ -37,17 +37,17 @@ public:
TemporaryFile(const std::string& contents) : m_path(getTemporaryFilePath())
{
std::ofstream ofs(m_path);
assert(ofs);
assert(ofs && "Stream encountered an error");
ofs << contents;
assert(ofs);
assert(ofs && "Stream encountered an error");
}
// Close and delete the generated file.
~TemporaryFile()
{
[[maybe_unused]] const bool removed = std::filesystem::remove(m_path);
assert(removed);
assert(removed && "m_path failed to be removed from filesystem");
}
// Prevent copies.

View File

@ -19,7 +19,7 @@ namespace
template <typename T>
auto select(const std::basic_string<T>& string16, const std::basic_string<T>& string32)
{
assert(string16 != string32);
assert(string16 != string32 && "Invalid to select between identical inputs");
if constexpr (sizeof(wchar_t) == 2)
return string16;
else