libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
reject_codes.cpp File Reference
#include "core/application.hpp"
#include "core/exit_codes.hpp"
#include <boost/algorithm/string/split.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
Include dependency graph for reject_codes.cpp:

Go to the source code of this file.

Typedefs

using row_t = std::vector< std::string >
 
using table_t = std::map< std::int32_t, row_t >
 
using parsed_csv_t = std::tuple< std::string, table_t, row_t::size_type, row_t::size_type >
 

Functions

void fixup_csv_line (std::string &line) noexcept(false)
 Some of the lines in the dratted CSV don't end with commas, so ensure that they do to allow the comma-recognition code to work correctly. More...
 
std::string deoctalify (std::string const &code) noexcept(false)
 Some of the reject-codes are prefixed with zeroes, which in C++ signifies an octal number, strip those zeroes to ensure the reject-codes are correctly treated as decimal. More...
 
std::string strip_trailing_junk (std::string const &code) noexcept(false)
 Sometimes the reject-code has trailing non-printable characters before the comma-separator. Strip it. More...
 
std::string make_digits (std::string const &code) noexcept(false)
 Suitably clean up the reject-code. More...
 
row_t make_row (std::string line) noexcept(false)
 Convert the scanned line from the input CSV-file into a collection of strings, one string per column. More...
 
std::string remove_quotes (std::string const &s) noexcept(false)
 
parsed_csv_t read_csv (std::string const &fname, std::string const &version_headers, std::string const &end_of_version_headers, std::vector< std::string > const &reject_code_headers, std::string const &reject_column_name) noexcept(false)
 Read in and parse the specified CSV-file. More...
 
std::string ASCII_ify (std::string const &arg) noexcept(false)
 Replace the non-alpha-numeric characters in the input string into underscores. More...
 
std::string reject_code_to_enum_tag (table_t::const_iterator row, const row_t::size_type reason_index, const row_t::size_type process_index) noexcept(false)
 Construct a suitable enum-tag from the parsed row. More...
 
template<class Colln , class Op , class Trail >
void fill (Colln &c, Op const &o, Trail const &t) noexcept(false)
 Apply a specified operator to all but the penultimate element in the collection, to which a different operation should be applied. More...
 
void write_reject_code_enum (table_t const &table, const row_t::size_type reason_index, const row_t::size_type process_index, std::ostream &os) noexcept(false)
 
void write_string_table (table_t const &table, const row_t::size_type reason_index, std::ostream &os) noexcept(false)
 
void write_code_to_reason (table_t const &table, const row_t::size_type reason_index, const row_t::size_type process_index, std::ostream &os) noexcept(false)
 
void write_header (parsed_csv_t const &parsed_csv, std::string const &fname, std::string const &nm_space) noexcept(false)
 
int main (int argc, char const *const *argv) noexcept(true)
 For MIT-based protocols, auto-generate a C++ function to convert the reject codes to strings. The mapping comes from the downloaded XLS that has been converted to a CSV file. More...
 

Variables

constexpr const char copyright []
 
constexpr const char header_guard_postfix [] ="#endif\n"
 
constexpr const row_t::size_type code_index =0
 The reject code must always be in the first column. More...
 
constexpr const row_t::size_type max_columns =5
 The maximum number of columns in the converted CSV. More...
 
constexpr const char reject_codes_enum_str [] ="reject_codes_enum"
 The name of the enum that is created with tags composed from the printable characters from the string relating to the reject-code. More...
 

Typedef Documentation

◆ parsed_csv_t

typedef std::tuple< std::string, table_t, row_t::size_type, row_t::size_type > parsed_csv_t

Definition at line 37 of file reject_codes.cpp.

◆ row_t

typedef std::vector< std::string > row_t

Definition at line 35 of file reject_codes.cpp.

◆ table_t

typedef std::map< std::int32_t, row_t > table_t

Definition at line 36 of file reject_codes.cpp.

Function Documentation

◆ ASCII_ify()

std::string ASCII_ify ( std::string const &  arg)
inlinenoexcept

Replace the non-alpha-numeric characters in the input string into underscores.

Definition at line 272 of file reject_codes.cpp.

◆ deoctalify()

std::string deoctalify ( std::string const &  code)
inlinenoexcept

Some of the reject-codes are prefixed with zeroes, which in C++ signifies an octal number, strip those zeroes to ensure the reject-codes are correctly treated as decimal.

Definition at line 82 of file reject_codes.cpp.

◆ fill()

template<class Colln , class Op , class Trail >
void fill ( Colln &  c,
Op const &  o,
Trail const &  t 
)
inlinenoexcept

Apply a specified operator to all but the penultimate element in the collection, to which a different operation should be applied.

Algorithmic complexity: O(n)

Parameters
cThe input collection.
oThe functor to be applied to all but the penultimate element in the input collection.
tThe functor to be applied to the penultimate element in the input collection.

Definition at line 302 of file reject_codes.cpp.

◆ fixup_csv_line()

void fixup_csv_line ( std::string &  line)
inlinenoexcept

Some of the lines in the dratted CSV don't end with commas, so ensure that they do to allow the comma-recognition code to work correctly.

If a terminal comma is omitted, that last column will be read as empty.

Definition at line 74 of file reject_codes.cpp.

◆ main()

int main ( int  argc,
char const *const *  argv 
)
noexcept

◆ make_digits()

std::string make_digits ( std::string const &  code)
inlinenoexcept

Suitably clean up the reject-code.

Definition at line 102 of file reject_codes.cpp.

◆ make_row()

row_t make_row ( std::string  line)
inlinenoexcept

Convert the scanned line from the input CSV-file into a collection of strings, one string per column.

Also replace non-printable ASCII characters with underscores.

Todo:
Consider using libjmmcg::csv_iterator

Also replace non-printable ASCII characters with underscores.

Todo:
Consider using libjmmcg::csv_iterator

Definition at line 113 of file reject_codes.cpp.

◆ read_csv()

parsed_csv_t read_csv ( std::string const &  fname,
std::string const &  version_headers,
std::string const &  end_of_version_headers,
std::vector< std::string > const &  reject_code_headers,
std::string const &  reject_column_name 
)
inlinenoexcept

Read in and parse the specified CSV-file.

Note that any lines with non-digit reject-codes will be silently ignored. All FixGateway reject-codes are ignored (as they cause duplicates) & the links are binary-only.

Parameters
fnameThe suitably-qualified path to the suitably-formatted CSV file. It must be comma separated, with no embedded commas.
ver_headersThe string that specifies the headers for the version-table.
Returns
An associative collection of reject-code to details, the version string and column numbers of the required details in the rows.

Definition at line 155 of file reject_codes.cpp.

◆ reject_code_to_enum_tag()

std::string reject_code_to_enum_tag ( table_t::const_iterator  row,
const row_t::size_type  reason_index,
const row_t::size_type  process_index 
)
inlinenoexcept

Construct a suitable enum-tag from the parsed row.

Definition at line 287 of file reject_codes.cpp.

◆ remove_quotes()

std::string remove_quotes ( std::string const &  s)
inlinenoexcept

Definition at line 141 of file reject_codes.cpp.

◆ strip_trailing_junk()

std::string strip_trailing_junk ( std::string const &  code)
inlinenoexcept

Sometimes the reject-code has trailing non-printable characters before the comma-separator. Strip it.

Definition at line 92 of file reject_codes.cpp.

◆ write_code_to_reason()

void write_code_to_reason ( table_t const &  table,
const row_t::size_type  reason_index,
const row_t::size_type  process_index,
std::ostream &  os 
)
inlinenoexcept

Definition at line 353 of file reject_codes.cpp.

References reject_codes_enum_str.

◆ write_header()

void write_header ( parsed_csv_t const &  parsed_csv,
std::string const &  fname,
std::string const &  nm_space 
)
inlinenoexcept

Definition at line 388 of file reject_codes.cpp.

References header_guard_postfix.

◆ write_reject_code_enum()

void write_reject_code_enum ( table_t const &  table,
const row_t::size_type  reason_index,
const row_t::size_type  process_index,
std::ostream &  os 
)
inlinenoexcept

Definition at line 313 of file reject_codes.cpp.

References reject_codes_enum_str.

◆ write_string_table()

void write_string_table ( table_t const &  table,
const row_t::size_type  reason_index,
std::ostream &  os 
)
inlinenoexcept

Definition at line 334 of file reject_codes.cpp.

Variable Documentation

◆ code_index

constexpr const row_t::size_type code_index =0
constexpr

The reject code must always be in the first column.

Definition at line 63 of file reject_codes.cpp.

◆ copyright

constexpr const char copyright
constexpr
Initial value:
=
"/******************************************************************************\n"
"** Copyright © 2016 by J.M.McGuiness, isimud@hussar.me.uk\n"
"**\n"
"** This library is free software; you can redistribute it and/or\n"
"** modify it under the terms of the GNU Lesser General Public\n"
"** License as published by the Free Software Foundation; either\n"
"** version 2.1 of the License, or (at your option) any later version.\n"
"**\n"
"** This library is distributed in the hope that it will be useful,\n"
"** but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
"** Lesser General Public License for more details.\n"
"**\n"
"** You should have received a copy of the GNU Lesser General Public\n"
"** License along with this library; if not, write to the Free Software\n"
"** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
"*/\n"
"#include \"../../common/config.h\"\n\n"
"#include <cassert>\n"
"#include <cstdint>\n"
"#include <iostream>\n"

Definition at line 39 of file reject_codes.cpp.

◆ header_guard_postfix

constexpr const char header_guard_postfix ="#endif\n"
constexpr

Definition at line 61 of file reject_codes.cpp.

Referenced by write_header().

◆ max_columns

constexpr const row_t::size_type max_columns =5
constexpr

The maximum number of columns in the converted CSV.

Definition at line 65 of file reject_codes.cpp.

◆ reject_codes_enum_str

constexpr const char reject_codes_enum_str ="reject_codes_enum"
constexpr

The name of the enum that is created with tags composed from the printable characters from the string relating to the reject-code.

Definition at line 67 of file reject_codes.cpp.

Referenced by write_code_to_reason(), and write_reject_code_enum().