Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latest from CODA-OSS #592

Merged
merged 15 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ std::unique_ptr<cli::Results> cli::ArgumentParser::parse(const std::string& prog
case cli::SUB_OPTIONS:
{
if (optionsStr.empty())
parseError(str::Format("invalid sub option: [%s]", argVar.c_str()));
parseError(str::Format("invalid sub option: [%s]", argVar));

auto v_ = std::make_unique<cli::Value>();
auto v = currentResults->hasValue(optionsStr) ? currentResults->getValue(optionsStr) : v_.get();
Expand Down Expand Up @@ -706,7 +706,7 @@ std::unique_ptr<cli::Results> cli::ArgumentParser::parse(const std::string& prog
}
if (!isValid)
{
parseError(str::Format("invalid option for [%s]", argVar.c_str()));
parseError(str::Format("invalid option for [%s]", argVar));
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions externals/coda-oss/modules/c++/coda-oss.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRuleSet>coda-oss.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -580,6 +581,7 @@
<EnablePREfast>true</EnablePREfast>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void BufferViewStream<T>::write(const void* buffer, size_t numBytes)
{
std::ostringstream msg;
msg << "Write of size " << numBytes << " runs out of bounds.";
throw except::Exception(Ctxt(msg.str()));
throw except::Exception(Ctxt(msg));
}

::memcpy(mBufferView.data + mPosition, buffer, numBytes);
Expand Down
2 changes: 1 addition & 1 deletion externals/coda-oss/modules/c++/io/include/io/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ inline void move(const std::string& path,
oss << "Move Failed: Could not move source [" <<
path << "] to destination [" <<
newPath << "]";
throw except::Exception(Ctxt(oss.str()));
throw except::Exception(Ctxt(oss));
}
}

Expand Down
5 changes: 2 additions & 3 deletions externals/coda-oss/modules/c++/io/source/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void io::copy(const std::string& path,
oss << "Copy Failed: Could not copy source [" <<
path << "] to destination [" <<
newFile << "]";
throw except::Exception(Ctxt(oss.str()));
throw except::Exception(Ctxt(oss));
}
}
}
Expand All @@ -133,8 +133,7 @@ std::string io::FileUtils::createFile(std::string dirname,
sys::OS os;

if (!os.exists(dirname))
throw except::IOException(Ctxt(str::Format("Directory does not exist: %s",
dirname.c_str())));
throw except::IOException(Ctxt(str::Format("Directory does not exist: %s", dirname)));

str::trim(filename);

Expand Down
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/io/source/InputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ sys::SSize_T InputStream::read(void* buffer,
{
std::ostringstream ostr;
ostr << "Tried to read " << len << " bytes but read failed";
throw except::IOException(Ctxt(ostr.str()));
throw except::IOException(Ctxt(ostr));
}
else if (numBytes != static_cast<sys::SSize_T>(len))
{
std::ostringstream ostr;
ostr << "Tried to read " << len << " bytes but only read "
<< numBytes << " bytes";
throw except::IOException(Ctxt(ostr.str()));
throw except::IOException(Ctxt(ostr));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void io::MMapInputStream::open(const std::string& fname, char* flags)
// std::cout << mLength << std::endl;
mFile = fopen(fname.c_str(), "r");
if (!mFile)
throw sys::SystemException(str::Format("Failure while opening file: %s", fname.c_str()));
throw sys::SystemException(str::Format("Failure while opening file: %s", fname));

_map();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ StreamSplitter::StreamSplitter(io::InputStream& inputStream,
std::ostringstream os;
os << "bufferSize must be >= twice the delimiter size + 1 byte. "
<< "Normally it should be much larger for good performance.";
throw except::InvalidArgumentException(Ctxt(os.str()));
throw except::InvalidArgumentException(Ctxt(os));
}
}

Expand Down
6 changes: 3 additions & 3 deletions externals/coda-oss/modules/c++/io/tests/serializeTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class A : public Serializable
string vec_2 = fillString(is);

assert(classType == "Class A");
dbg.writeln(str::Format("vec[0] = %s", vec_0.c_str()));
dbg.writeln(str::Format("vec[1] = %s", vec_1.c_str()));
dbg.writeln(str::Format("vec[2] = %s", vec_2.c_str()));
dbg.writeln(str::Format("vec[0] = %s", vec_0));
dbg.writeln(str::Format("vec[1] = %s", vec_1));
dbg.writeln(str::Format("vec[2] = %s", vec_2));

vec[0] = str::toType<float>(vec_0);
vec[1] = str::toType<float>(vec_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct LogLevel final
else if (s == "SEVERE")
value = LOG_CRITICAL;
else
throw except::InvalidFormatException(Ctxt(str::Format("Invalid enum value: %s", s.c_str())));
throw except::InvalidFormatException(Ctxt(str::Format("Invalid enum value: %s", s)));
}

//! int constructor
Expand Down
13 changes: 13 additions & 0 deletions externals/coda-oss/modules/c++/logging/include/logging/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
// Logger.h
///////////////////////////////////////////////////////////

#pragma once
#ifndef CODA_OSS_logging_Logger_h_INCLUDED_
#define CODA_OSS_logging_Logger_h_INCLUDED_

#include <string>
#include <vector>
#include <memory>
#include <sstream>

#include "config/Exports.h"
#include "logging/Filterer.h"
Expand Down Expand Up @@ -79,6 +81,17 @@ struct CODA_OSS_API Logger : public Filterer
//! Logs a message at the CRITICAL LogLevel
void critical(const std::string& msg);

//! Logs a message at the DEBUG LogLevel
void debug(const std::ostringstream& msg);
//! Logs a message at the INFO LogLevel
void info(const std::ostringstream& msg);
//! Logs a message at the WARNING LogLevel
void warn(const std::ostringstream& msg);
//! Logs a message at the ERROR LogLevel
void error(const std::ostringstream& msg);
//! Logs a message at the CRITICAL LogLevel
void critical(const std::ostringstream& msg);

//! Logs an Exception Context at the DEBUG LogLevel
void debug(const except::Context& ctxt);
//! Logs an Exception Context at the INFO LogLevel
Expand Down
24 changes: 24 additions & 0 deletions externals/coda-oss/modules/c++/logging/source/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,30 @@ void logging::Logger::critical(const std::string& msg)
log(LogLevel::LOG_CRITICAL, msg);
}

void logging::Logger::debug(const std::ostringstream& msg)
{
log(LogLevel::LOG_DEBUG, msg.str());
}

void logging::Logger::info(const std::ostringstream& msg)
{
log(LogLevel::LOG_INFO, msg.str());
}

void logging::Logger::warn(const std::ostringstream& msg)
{
log(LogLevel::LOG_WARNING, msg.str());
}

void logging::Logger::error(const std::ostringstream& msg)
{
log(LogLevel::LOG_ERROR, msg.str());
}

void logging::Logger::critical(const std::ostringstream& msg)
{
log(LogLevel::LOG_CRITICAL, msg.str());
}

void logging::Logger::debug(const except::Context& ctxt)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ template<typename Vector_T> OneD<double> fit(const Vector_T& x,
<< sizeX << " points for an order-" << order
<< "fit)! You should really have at least (order+1) = "
<< (order+1) << " points for this to do what you expect.";
throw except::Exception(Ctxt(excSS.str()));
throw except::Exception(Ctxt(excSS));
}

// Compute mean value
Expand Down Expand Up @@ -206,7 +206,7 @@ inline math::poly::TwoD<double> fit(const math::linear::Matrix2D<double>& x,
<< x.size() << " points for a " << acols << "-coefficient fit)!"
<< " You should really have at least (orderX+1)*(orderY+1) = "
<< acols << " points for this to do what you expect.";
throw except::Exception(Ctxt(excSS.str()));
throw except::Exception(Ctxt(excSS));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,9 @@ OneD<_T>::operator [] (size_t i)
}
else
{
std::stringstream str;
str << "index: " << i << " not within range [0..."
<< mCoef.size() << ")";
throw except::IndexOutOfRangeException(Ctxt(str.str()));
std::ostringstream str;
str << "index: " << i << " not within range [0..." << mCoef.size() << ")";
throw except::IndexOutOfRangeException(Ctxt(str));
}
}

Expand All @@ -196,9 +195,9 @@ OneD<_T>::operator [] (size_t i) const
}
else
{
std::stringstream str;
std::ostringstream str;
str << "idx(" << i << ") not within range [0..." << mCoef.size() << ")";
throw except::IndexOutOfRangeException(Ctxt(str.str()));
throw except::IndexOutOfRangeException(Ctxt(str));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ TwoD<_T>::operator [] (size_t i) const
}
else
{
std::stringstream str;
str << "index:" << i << " not within range [0..."
<< mCoef.size() << ")";

throw except::IndexOutOfRangeException(Ctxt(str.str()));
std::ostringstream str;
str << "index:" << i << " not within range [0..." << mCoef.size() << ")";
throw except::IndexOutOfRangeException(Ctxt(str));
}
return ret;
}
Expand All @@ -206,10 +204,9 @@ TwoD<_T>::operator [] (size_t i)
}
else
{
std::stringstream str;
str << "index: " << i << " not within range [0..."
<< mCoef.size() << ")";
throw except::IndexOutOfRangeException(Ctxt(str.str()));
std::ostringstream str;
str << "index: " << i << " not within range [0..." << mCoef.size() << ")";
throw except::IndexOutOfRangeException(Ctxt(str));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct BufferView
oss << "BufferView::section() called with sectionSize: " << sectionSize << " when";
oss << " there were only " << size << " elements in the BufferView";

throw except::Exception(Ctxt(oss.str()));
throw except::Exception(Ctxt(oss));
}

BufferView<T> newSection(data, sectionSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inline void ScratchMemory::put<sys::ubyte>(const std::string& key,
{
std::ostringstream oss;
oss << "Scratch memory space was already reserved for " << key;
throw except::Exception(Ctxt(oss.str()));
throw except::Exception(Ctxt(oss));
}
mSegments.insert(
iterSeg,
Expand Down
12 changes: 5 additions & 7 deletions externals/coda-oss/modules/c++/mem/source/ScratchMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,27 +212,25 @@ const ScratchMemory::Segment& ScratchMemory::lookupSegment(
if (mBuffer.data == nullptr)
{
std::ostringstream oss;
oss << "Tried to get scratch memory for \"" << key
<< "\" before running setup.";
throw except::Exception(Ctxt(oss.str()));
oss << "Tried to get scratch memory for \"" << key << "\" before running setup.";
throw except::Exception(Ctxt(oss));
}

std::map<std::string, Segment>::const_iterator iterSeg = mSegments.find(key);
if (iterSeg == mSegments.end())
{
std::ostringstream oss;
oss << "Scratch memory segment was not found for \"" << key << "\"";
throw except::Exception(Ctxt(oss.str()));
throw except::Exception(Ctxt(oss));
}

const Segment& segment = iterSeg->second;
if (indexBuffer >= segment.buffers.size())
{
std::ostringstream oss;
oss << "Trying to get buffer index " << indexBuffer << " for \""
<< key << "\", which has only " << segment.buffers.size()
<< " buffers";
throw except::Exception(Ctxt(oss.str()));
<< key << "\", which has only " << segment.buffers.size() << " buffers";
throw except::Exception(Ctxt(oss));
}
return segment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void runBalanced1D(size_t numElements,
std::ostringstream ostr;
ostr << "Got " << numThreads << " threads but " << ops.size()
<< " functors";
throw except::Exception(Ctxt(ostr.str()));
throw except::Exception(Ctxt(ostr));
}

if (numThreads <= 1)
Expand Down
2 changes: 1 addition & 1 deletion externals/coda-oss/modules/c++/mt/include/mt/Runnable1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void run1D(size_t numElements, size_t numThreads, const std::vector<OpT>& ops)
std::ostringstream ostr;
ostr << "Got " << numThreads << " threads but " << ops.size()
<< " functors";
throw except::Exception(Ctxt(ostr.str()));
throw except::Exception(Ctxt(ostr));
}

if (numThreads <= 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void runWorkSharingBalanced1D(size_t numElements,
std::ostringstream ostr;
ostr << "Got " << numThreads << " threads but " << ops.size()
<< " functors";
throw except::Exception(Ctxt(ostr.str()));
throw except::Exception(Ctxt(ostr));
}

std::vector<size_t> threadPoolEndElements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct AvailableCPUProvider final : public AbstractNextCPUProviderLinux
{
std::ostringstream msg;
msg << "No more CPUs available (size = " << mCPUs.size() << ")";
throw except::Exception(Ctxt(msg.str()));
throw except::Exception(Ctxt(msg));
}

std::unique_ptr<sys::ScopedCPUMaskUnix> mask(new sys::ScopedCPUMaskUnix());
Expand Down
2 changes: 1 addition & 1 deletion externals/coda-oss/modules/c++/net/include/net/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class Socket

std::ostringstream oss;
oss << "Socket setOptions failure: " << err.toString();
throw sys::SocketException(Ctxt(oss.str()));
throw sys::SocketException(Ctxt(oss));
}
}

Expand Down
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/net/source/DaemonUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ void DaemonUnix::redirectStreamsTo(const std::string& filename)
if (openFileFor(STDOUT_FILENO, filename, O_WRONLY|O_CREAT|O_TRUNC) < 0)
{
throw except::Exception(
Ctxt(str::Format("Failed to open file %s for STDOUT.", filename.c_str())));
Ctxt(str::Format("Failed to open file %s for STDOUT.", filename)));
}
if (openFileFor(STDERR_FILENO, filename, O_WRONLY|O_CREAT|O_TRUNC) < 0)
{
throw except::Exception(
Ctxt(str::Format("Failed to open file %s for STDERR.", filename.c_str())));
Ctxt(str::Format("Failed to open file %s for STDERR.", filename)));
}
}

Expand Down
Loading