Skip to content

Commit

Permalink
Squashed 'externals/nitro/' changes from ff335eeaf..cca11bf4c
Browse files Browse the repository at this point in the history
cca11bf4c Merge commit 'b40d3f96fff13bf708f319c684348ebd9884aff1' into cpp17
b40d3f96f Squashed 'externals/coda-oss/' changes from b6ead418cf..434b85fe53
2d6d5aa31 Merge branch 'main' into cpp17
1b631e578 latest from CODA-OSS (#587)
d32176660 Merge branch 'main' into cpp17
574bfe2b6 FmtX() -> str::Format() (#586)
a8e6556aa Squashed 'externals/coda-oss/' changes from 07bcb3a39b..b6ead418cf
53596f720 Merge commit 'a8e6556aa7bc5c105d3b4383589da7ef48982deb' into cpp17
29ccecf64 latest from CODA-OSS
b315d9b6c Merge branch 'main' into cpp17
edfa0f7ce latest from CODA-OSS (#585)
b708bd8ea `final` for NITFException
a2af78776 don't need FmtX() with no formatting
368cead55 Squashed 'externals/coda-oss/' changes from 70a006d8a4..07bcb3a39b
9b10c5340 Merge commit '368cead55f182d12953a6964b2598021f9629cf3' into cpp17
6e40d15b4 latest from CODA-OSS
31fc61888 develop/sync_externals

git-subtree-dir: externals/nitro
git-subtree-split: cca11bf4c8a99e779c2a7158e2fc214d3b097337
  • Loading branch information
Dan Smith committed Oct 10, 2023
1 parent 34a50a6 commit a6083af
Show file tree
Hide file tree
Showing 70 changed files with 325 additions and 442 deletions.
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ CMakeLists.txt text eol=lf

# Text file formats
*.txt text eol=lf
*.text text eol=lf
*.md text eol=lf
*.tex text eol=lf
*.?ml text eol=lf
*.kmz binary
*.log text eol=lf

# Programming languages
*.htm? text eol=lf
Expand Down Expand Up @@ -54,12 +56,21 @@ CMakeLists.txt text eol=lf
######################
# Known binary files

# executables, libraries; yes, sometimes they're part of a repository
*.exe binary
*.out binary
lib*.so* binary
*.dll binary
lib*.a* binary
*.lib binary

# from various unit_test/ directories
*.dat binary
*.*hdr binary
*.flat binary
*.sig binary
*.bin binary
*.dump binary

# images
*.bmp binary
Expand Down
11 changes: 11 additions & 0 deletions externals/coda-oss/.gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ CMakeLists.txt text eol=lf

# Text file formats
*.txt text eol=lf
*.text text eol=lf
*.md text eol=lf
*.tex text eol=lf
*.?ml text eol=lf
*.kmz binary
*.log text eol=lf

# Programming languages
*.htm? text eol=lf
Expand Down Expand Up @@ -54,12 +56,21 @@ CMakeLists.txt text eol=lf
######################
# Known binary files

# executables, libraries; yes, sometimes they're part of a repository
*.exe binary
*.out binary
lib*.so* binary
*.dll binary
lib*.a* binary
*.lib binary

# from various unit_test/ directories
*.dat binary
*.*hdr binary
*.flat binary
*.sig binary
*.bin binary
*.dump binary

# images
*.bmp binary
Expand Down
6 changes: 3 additions & 3 deletions externals/coda-oss/build/scripts/makeEnums.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def cmpValues(x, y):
s.write(' %sif (s == "%s")\n value = %s%s;\n' % (i > 0 and 'else ' or '',
n, values.cleanPrefix, item.names[0].replace(' ', '_')))
i += 1
s.write(' else\n throw except::InvalidFormatException(Ctxt(FmtX("Invalid enum value: %s", s.c_str())));\n')
s.write(' else\n throw except::InvalidFormatException(Ctxt(str::Format("Invalid enum value: %s", s.c_str())));\n')
s.write(' }\n\n')

s.write(' //! int constructor\n')
Expand All @@ -123,7 +123,7 @@ def cmpValues(x, y):
try:
idx += 1
except:{}
s.write(' default:\n throw except::InvalidFormatException(Ctxt(FmtX("Invalid enum value: %d", i)));\n')
s.write(' default:\n throw except::InvalidFormatException(Ctxt(str::Format("Invalid enum value: %d", i)));\n')
s.write(' }\n }\n\n')

s.write(' //! destructor\n')
Expand All @@ -142,7 +142,7 @@ def cmpValues(x, y):
try:
idx += 1
except:{}
s.write(' default:\n throw except::InvalidFormatException(Ctxt(FmtX("Invalid enum value: %d", value)));\n')
s.write(' default:\n throw except::InvalidFormatException(Ctxt(str::Format("Invalid enum value: %d", value)));\n')
s.write(' }\n }\n\n')

s.write(' //! assignment operator\n')
Expand Down
70 changes: 43 additions & 27 deletions externals/coda-oss/modules/c++/cli/include/cli/Results.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#define CODA_OSS_cli_Results_h_INCLUDED_

#include <map>
#include <memory>
#include <utility>
#include <stdexcept>

#include "sys/Conf.h"

Expand All @@ -33,24 +36,25 @@
namespace cli
{

class Results
class Results final
{
protected:
typedef std::map<std::string, cli::Value*> ValueStorage_T;
typedef std::map<std::string, std::unique_ptr<cli::Value>> ValueStorage_T;
typedef ValueStorage_T::iterator ValueIter_T;
typedef ValueStorage_T::const_iterator ConstValueIter_T;
typedef std::map<std::string, cli::Results*> ResultsStorage_T;
typedef ResultsStorage_T::iterator ResultsIter_T;
typedef ResultsStorage_T::const_iterator ConstResultsIter_T;

public:
Results()
{
}
Results() = default;
~Results()
{
destroy();
}
Results(const Results&) = delete;
Results& operator=(const Results&) = delete;
Results(Results&&) = default;
Results& operator=(Results&&) = default;

bool hasValue(const std::string& key) const
{
Expand All @@ -62,20 +66,30 @@ class Results
return mResults.find(key) != mResults.end();
}

cli::Value* operator[](const std::string& key) const
const cli::Value* operator[](const std::string& key) const
{
return getValue(key);
}

cli::Value* getValue(const std::string& key) const
const cli::Value* getValue(const std::string& key) const
{
ConstValueIter_T p = mValues.find(key);
auto const p = mValues.find(key);
if (p == mValues.end())
{
const std::string errorMessage = "No argument named " + key;
throw except::NoSuchKeyException(Ctxt(errorMessage));
}
return p->second;
return p->second.get();
}
cli::Value* getValue(const std::string& key)
{
auto const p = mValues.find(key);
if (p == mValues.end())
{
const std::string errorMessage = "No argument named " + key;
throw except::NoSuchKeyException(Ctxt(errorMessage));
}
return p->second.get();
}

template<typename T>
Expand All @@ -100,15 +114,22 @@ class Results
return p->second;
}

void put(const std::string& key, cli::Value *value)
void put(const std::string& key, std::unique_ptr<cli::Value> value)
{
if (hasValue(key) && (getValue(key) == value.get()))
{
return;
}
mValues[key] = std::move(value);
}
void put(const std::string& key, cli::Value* value)
{
if (hasValue(key))
cli::Value* pExistingValue = hasValue(key) ? getValue(key) : nullptr;
if ((pExistingValue == nullptr) || (pExistingValue != value))
{
cli::Value* existing = getValue(key);
if (existing != value)
delete getValue(key);
// Either 1) we didn't already have a value or 2) the existing value is different
put(key, std::unique_ptr<cli::Value>(value));
}
mValues[key] = value;
}

void put(const std::string& key, cli::Results *args)
Expand All @@ -122,26 +143,21 @@ class Results
mResults[key] = args;
}

typedef ValueStorage_T::iterator iterator;
typedef ValueStorage_T::const_iterator const_iterator;
auto begin() { return mValues.begin(); }
auto begin() const { return mValues.begin(); }
auto end() { return mValues.end(); }
auto end() const { return mValues.end(); }

iterator begin() { return mValues.begin(); }
const_iterator begin() const { return mValues.begin(); }
iterator end() { return mValues.end(); }
const_iterator end() const { return mValues.end(); }

protected:
private:
ValueStorage_T mValues;
ResultsStorage_T mResults;

void destroy()
{
for (ValueIter_T it = mValues.begin(), end = mValues.end(); it != end; ++it)
delete it->second;
mValues.clear();
for (ResultsIter_T it = mResults.begin(), end = mResults.end(); it
!= end; ++it)
delete it->second;
mValues.clear();
mResults.clear();
}
};
Expand Down
27 changes: 4 additions & 23 deletions externals/coda-oss/modules/c++/cli/include/cli/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <string>
#include <iterator>
#include <memory>

#include <import/str.h>
#include "sys/Conf.h"
Expand All @@ -38,12 +39,9 @@ namespace cli
* The Value class provides access to one or more actual values.
* It provides index-based access to parameters.
*/
class CODA_OSS_API Value
struct CODA_OSS_API Value final
{
public:
Value()
{
}
Value() = default;

template<typename T>
explicit Value(std::vector<T> value)
Expand All @@ -57,12 +55,6 @@ class CODA_OSS_API Value
set<T>(value);
}

template<typename T>
Value(T* value, size_t size, bool own = false)
{
set<T>(value, size, own);
}

~Value()
{
cleanup();
Expand All @@ -75,17 +67,6 @@ class CODA_OSS_API Value
mValues.push_back(str::toString(value));
}

template<typename T>
void set(T* value, size_t size, bool own = false)
{
cleanup();
mValues.reserve(size);
for (size_t i = 0; i < size; ++i)
add(value[i]);
if (own)
delete[] value;
}

template<typename T>
void setContainer(const std::vector<T>& c)
{
Expand All @@ -106,7 +87,7 @@ class CODA_OSS_API Value
{
if (index >= mValues.size())
throw except::IndexOutOfRangeException(
Ctxt(FmtX("Invalid index: %d", index)));
Ctxt(str::Format("Invalid index: %d", index)));
return str::toType<T>(mValues[index]);
}

Expand Down
2 changes: 1 addition & 1 deletion externals/coda-oss/modules/c++/cli/source/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ cli::Argument::~Argument()
cli::Argument* cli::Argument::addFlag(const std::string& flag)
{
char p = mParser->mPrefixChar;
std::string p2 = FmtX("%c%c", p, p);
std::string p2 = str::Format("%c%c", p, p);
if (flag.size() > 2 && str::startsWith(flag, p2) && flag[2] != p)
mLongFlags.push_back(validateFlag(flag.substr(2)));
else if (flag.size() > 1 && flag[0] == p && flag[1] != p)
Expand Down
Loading

0 comments on commit a6083af

Please sign in to comment.