[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master fe0e950 2/3: Add inchoate support for '.lingo
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master fe0e950 2/3: Add inchoate support for '.lingo' files |
Date: |
Mon, 9 Nov 2020 17:12:09 -0500 (EST) |
branch: master
commit fe0e95028719a9760d4a27e2617186e335417bc7
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add inchoate support for '.lingo' files
---
Makefile.am | 5 ++++
lingo.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++
lingo.hpp | 55 ++++++++++++++++++++++++++++++++++
my_lingo.cpp | 43 +++++++++++++++++++++++++++
objects.make | 3 ++
sample.hpp | 29 ++++++++++++++++++
test_coding_rules.cpp | 1 +
7 files changed, 217 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index bed9d4c..62b10ea 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -424,6 +424,7 @@ liblmi_la_SOURCES = \
ihs_mortal.cpp \
ihs_server7702.cpp \
irc7702_tables.cpp \
+ lingo.cpp \
lmi.cpp \
md5.cpp \
md5sum.cpp \
@@ -529,6 +530,7 @@ product_files_SOURCES = \
main_common_non_wx.cpp \
my_db.cpp \
my_fund.cpp \
+ my_lingo.cpp \
my_prod.cpp \
my_proem.cpp \
my_rnd.cpp \
@@ -1076,6 +1078,7 @@ test_product_file_SOURCES = \
facets.cpp \
fund_data.cpp \
global_settings.cpp \
+ lingo.cpp \
lmi.cpp \
mc_enum.cpp \
mc_enum_types.cpp \
@@ -1367,6 +1370,7 @@ noinst_HEADERS = \
ledger_variant.hpp \
ledgervalues.hpp \
license.hpp \
+ lingo.hpp \
lmi.hpp \
loads.hpp \
loads_impl.hpp \
@@ -1436,6 +1440,7 @@ noinst_HEADERS = \
rounding_view_editor.hpp \
rtti_lmi.hpp \
safely_dereference_as.hpp \
+ sample.hpp \
sigfpe.hpp \
single_cell_document.hpp \
single_choice_popup_menu.hpp \
diff --git a/lingo.cpp b/lingo.cpp
new file mode 100644
index 0000000..00dc4ab
--- /dev/null
+++ b/lingo.cpp
@@ -0,0 +1,81 @@
+// Text to be dropped into report templates.
+//
+// Copyright (C) 2020 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// https://savannah.nongnu.org/projects/lmi
+// email: <gchicares@sbcglobal.net>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+#include "pchfile.hpp"
+
+#include "lingo.hpp"
+
+#include "alert.hpp"
+#include "data_directory.hpp" // AddDataDir()
+#include "my_proem.hpp" // ::write_proem()
+#include "xml_lmi.hpp"
+
+#include <boost/filesystem/convenience.hpp>
+#include <boost/filesystem/path.hpp>
+
+lingo::lingo(std::string const& filename)
+{
+ xml_lmi::dom_parser parser(filename);
+ xml::element const& root = parser.root_node(xml_root_name());
+ int file_version = 0;
+ if(!xml_lmi::get_attr(root, "version", file_version))
+ {
+ alarum()
+ << "XML tag <"
+ << xml_root_name()
+ << "> lacks required version attribute."
+ << LMI_FLUSH
+ ;
+ }
+}
+
+void lingo::write_lingo_files()
+{
+ fs::path const path(AddDataDir("sample.lingo"));
+ xml_lmi::xml_document document(xml_root_name());
+ write_proem(document, fs::basename(path));
+ xml::element& root = document.root_node();
+ xml_lmi::set_attr(root, "version", class_version());
+ document.save(path.string());
+}
+
+/// Backward-compatibility serial number of this class's xml version.
+///
+/// version 0: 20201109T1600Z
+
+int lingo::class_version()
+{
+ return 0;
+}
+
+std::string const& lingo::xml_root_name()
+{
+ static std::string const s("lingo");
+ return s;
+}
+
+void lingo::write_proem
+ (xml_lmi::xml_document& document
+ ,std::string const& file_leaf_name
+ )
+{
+ ::write_proem(document, file_leaf_name);
+}
diff --git a/lingo.hpp b/lingo.hpp
new file mode 100644
index 0000000..4d56fe6
--- /dev/null
+++ b/lingo.hpp
@@ -0,0 +1,55 @@
+// Text to be dropped into report templates.
+//
+// Copyright (C) 2020 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// https://savannah.nongnu.org/projects/lmi
+// email: <gchicares@sbcglobal.net>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+#ifndef lingo_hpp
+#define lingo_hpp
+
+#include "config.hpp"
+
+#include "so_attributes.hpp"
+#include "xml_lmi_fwd.hpp"
+
+#include <string>
+
+/// Company-specific lingo.
+
+class LMI_SO lingo final
+{
+ public:
+ explicit lingo(std::string const& filename);
+
+ // Legacy functions to support creating product files programmatically.
+ static void write_lingo_files();
+ static void write_proprietary_lingo_files();
+
+ private:
+ // This class does not derive from xml_serializable, but it
+ // implements these three functions that are akin to virtuals
+ // of class xml_serializable.
+ static int class_version();
+ static std::string const& xml_root_name();
+ static void write_proem
+ (xml_lmi::xml_document& document
+ ,std::string const& file_leaf_name
+ );
+};
+
+#endif // lingo_hpp
diff --git a/my_lingo.cpp b/my_lingo.cpp
new file mode 100644
index 0000000..c5068dc
--- /dev/null
+++ b/my_lingo.cpp
@@ -0,0 +1,43 @@
+// Text to be dropped into report templates.
+//
+// Copyright (C) 2020 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// https://savannah.nongnu.org/projects/lmi
+// email: <gchicares@sbcglobal.net>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+// This file is a template for embedding product-specific data. Doing
+// that creates a derived work covered by the GPL. But you may prefer
+// not to publish your data, for instance because it is proprietary.
+// In that case, the GPL does not permit you to distribute the derived
+// work at all. But read the second paragraph of section 0 of the GPL
+// carefully: it permits you to run your modified version of the
+// program--and to distribute its output, which is not a derived work
+// because it's merely your data, trivially cast in a format suitable
+// for use with lmi. You can therefore distribute the files created by
+// your modified version of this program, but not that program itself.
+// Those files are all you need: distributing the program itself isn't
+// necessary anyway.
+
+#include "pchfile.hpp"
+
+#include "lingo.hpp"
+
+void lingo::write_proprietary_lingo_files()
+{
+// Not necessary for 'sample*' products, because they're built in.
+// For other products, clone the write_lingo_files() implementation.
+}
diff --git a/objects.make b/objects.make
index 3b95865..e8f21e9 100644
--- a/objects.make
+++ b/objects.make
@@ -292,6 +292,7 @@ lmi_common_objects := \
ihs_mortal.o \
ihs_server7702.o \
irc7702_tables.o \
+ lingo.o \
lmi.o \
md5.o \
md5sum.o \
@@ -926,6 +927,7 @@ product_file_test$(EXEEXT): \
facets.o \
fund_data.o \
global_settings.o \
+ lingo.o \
lmi.o \
mc_enum.o \
mc_enum_types.o \
@@ -1195,6 +1197,7 @@ product_files$(EXEEXT): \
main_common_non_wx.o \
my_db.o \
my_fund.o \
+ my_lingo.o \
my_prod.o \
my_proem.o \
my_rnd.o \
diff --git a/sample.hpp b/sample.hpp
new file mode 100644
index 0000000..01024ae
--- /dev/null
+++ b/sample.hpp
@@ -0,0 +1,29 @@
+// Parameters for a company's entire portfolio of products.
+//
+// Copyright (C) 2020 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// https://savannah.nongnu.org/projects/lmi
+// email: <gchicares@sbcglobal.net>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+#ifndef sample_hpp
+#define sample_hpp
+
+#include "config.hpp"
+
+// Coming soon...
+
+#endif // sample_hpp
diff --git a/test_coding_rules.cpp b/test_coding_rules.cpp
index 85b8d68..4c79296 100644
--- a/test_coding_rules.cpp
+++ b/test_coding_rules.cpp
@@ -194,6 +194,7 @@ file::file(std::string const& file_path)
: ".inix" == extension() ? e_xml_input
: ".database" == extension() ? e_xml_other
: ".funds" == extension() ? e_xml_other
+ : ".lingo" == extension() ? e_xml_other
: ".policy" == extension() ? e_xml_other
: ".rounding" == extension() ? e_xml_other
: ".strata" == extension() ? e_xml_other