[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [4870] Reimplement 'database' (formerly 'db4') product fil
From: |
Greg Chicares |
Subject: |
[lmi-commits] [4870] Reimplement 'database' (formerly 'db4') product files (VS) |
Date: |
Thu, 29 Apr 2010 19:13:13 +0000 |
Revision: 4870
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=4870
Author: chicares
Date: 2010-04-29 19:13:13 +0000 (Thu, 29 Apr 2010)
Log Message:
-----------
Reimplement 'database' (formerly 'db4') product files (VS)
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/Makefile.am
lmi/trunk/ihs_dbdict.cpp
lmi/trunk/ihs_dbvalue.cpp
lmi/trunk/ihs_dbvalue.hpp
lmi/trunk/main_wx.cpp
lmi/trunk/my_prod.cpp
lmi/trunk/objects.make
lmi/trunk/product_data.cpp
lmi/trunk/test_coding_rules.cpp
lmi/trunk/workhorse.make
Removed Paths:
-------------
lmi/trunk/ihs_fpios.cpp
lmi/trunk/ihs_fpios.hpp
lmi/trunk/ihs_pios.cpp
lmi/trunk/ihs_pios.hpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/ChangeLog 2010-04-29 19:13:13 UTC (rev 4870)
@@ -25088,3 +25088,42 @@
rounding_view_editor.hpp
Permit annotations in '.rounding' files.
+20100427T2340Z <address@hidden> [755]
+
+ database_view_editor.hpp
+Anticipate new database-file names.
+
+20100428T1231Z <address@hidden> [755]
+
+ dbnames.xpp
+ ihs_basicval.cpp
+ ihs_dbdict.cpp
+ mec_server.cpp
+ mortality_rates_fetch.cpp
+Redefine 'MaxMonthlyCoiRate' and 'NAARDiscount' as reciprocals. See:
+ http://lists.nongnu.org/archive/html/lmi/2010-03/msg00000.html
+
+20100429T1910Z <address@hidden> [755]
+
+ dbnames.cpp
+ dbnames.hpp
+Commute between database name and key (VS).
+
+20100429T1913Z <address@hidden> [745]
+
+ Makefile.am
+ ihs_dbdict.cpp
+ ihs_dbvalue.cpp
+ ihs_dbvalue.hpp
+ ihs_fpios.cpp [expunged]
+ ihs_fpios.hpp [expunged]
+ ihs_pios.cpp [expunged]
+ ihs_pios.hpp [expunged]
+ main_wx.cpp
+ my_prod.cpp
+ objects.make
+ product_data.cpp
+ test_coding_rules.cpp
+ workhorse.make
+Reimplement 'database' (formerly 'db4') product files (VS).
+
Modified: lmi/trunk/Makefile.am
===================================================================
--- lmi/trunk/Makefile.am 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/Makefile.am 2010-04-29 19:13:13 UTC (rev 4870)
@@ -329,12 +329,10 @@
ihs_database.cpp \
ihs_dbdict.cpp \
ihs_dbvalue.cpp \
- ihs_fpios.cpp \
ihs_funddata.cpp \
ihs_irc7702.cpp \
ihs_irc7702a.cpp \
ihs_mortal.cpp \
- ihs_pios.cpp \
mc_enum.cpp \
mc_enum_types.cpp \
mc_enum_types_aux.cpp \
@@ -732,9 +730,7 @@
global_settings.cpp \
ihs_dbdict.cpp \
ihs_dbvalue.cpp \
- ihs_fpios.cpp \
ihs_funddata.cpp \
- ihs_pios.cpp \
miscellany.cpp \
path_utility.cpp \
product_data.cpp \
@@ -916,11 +912,9 @@
ihs_commfns.hpp \
ihs_dbdict.hpp \
ihs_dbvalue.hpp \
- ihs_fpios.hpp \
ihs_funddata.hpp \
ihs_irc7702a.hpp \
ihs_irc7702.hpp \
- ihs_pios.hpp \
ihs_server7702.hpp \
ihs_server7702io.hpp \
ihs_x_type.hpp \
Modified: lmi/trunk/ihs_dbdict.cpp
===================================================================
--- lmi/trunk/ihs_dbdict.cpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/ihs_dbdict.cpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -35,6 +35,8 @@
#include "mc_enum_type_enums.hpp"
#include "miscellany.hpp"
#include "oecumenic_enumerations.hpp"
+#include "xml_lmi.hpp"
+#include "xml_serialize.hpp"
#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/fstream.hpp>
@@ -65,6 +67,58 @@
{
}
+namespace xml_serialize
+{
+template<> struct xml_io<TDBValue>
+{
+ typedef TDBValue T;
+ static void to_xml(xml::element& e, T const& t) {t.write(e);}
+ static void from_xml(xml::element const& e, T& t) {t.read (e);}
+};
+
+/// Specialize xml_io<> for dict_map rather than coding a generic
+/// xml_io<std::map>, because the key would be stored redundantly:
+/// it's already part of TDBValue.
+
+template<> struct xml_io<dict_map>
+{
+ static void to_xml(xml::element& e, dict_map const& t)
+ {
+ e.erase(e.begin(), e.end());
+ typedef dict_map::const_iterator tci;
+ for(tci i = t.begin(); i != t.end(); ++i)
+ {
+ // This is not equivalent to calling set_element():
+ // multiple <item> elements are expressly permitted.
+ xml::element z("item");
+ xml_serialize::to_xml(z, i->second);
+ e.push_back(z);
+ }
+ }
+
+ static void from_xml(xml::element const& e, dict_map& t)
+ {
+ t.clear();
+ xml::const_nodes_view const items(e.elements("item"));
+ typedef xml::const_nodes_view::const_iterator cnvi;
+ for(cnvi i = items.begin(); i != items.end(); ++i)
+ {
+ TDBValue z;
+ xml_serialize::from_xml(*i, z);
+ t[z.GetKey()] = z;
+ }
+ }
+};
+} // namespace xml_serialize
+
+namespace
+{
+std::string xml_root_name()
+{
+ return "database";
+}
+} // Unnamed namespace.
+
//============================================================================
void DBDictionary::Init(std::string const& NewFilename)
{
@@ -88,47 +142,34 @@
}
CachedFilename = NewFilename;
- dictionary.erase(dictionary.begin(), dictionary.end());
- JRPS::JrPs_ifpstream ips
- (NewFilename.c_str()
- );
- if(!ips)
+ if(access(NewFilename.c_str(), R_OK))
{
- BadFile(NewFilename, "could not be found.");
+ BadFile(NewFilename, "could not be found."); // dubious
+ fatal_error()
+ << "File '"
+ << NewFilename
+ << "' is required but could not be found. Try reinstalling."
+ << LMI_FLUSH
+ ;
}
- int n;
- ips >> n;
- if(NumberOfEntries != n)
+
+ xml_lmi::dom_parser parser(NewFilename);
+ xml::element const& root = parser.root_node(xml_root_name());
+
+ xml_serialize::from_xml(root, dictionary);
+
+ if(NumberOfEntries != static_cast<int>(dictionary.size()))
{
std::ostringstream oss;
oss
<< "is not up to date or is corrupted."
<< " It should contain " << NumberOfEntries
- << " elements, but it actually contains " << n
+ << " elements, but it actually contains " << dictionary.size()
<< " elements."
;
BadFile(NewFilename, oss.str());
}
- for(int j = 0; j < n; j++)
- {
- TDBValue* temp;
- ips >> temp;
- if(0 == temp)
- {
- std::ostringstream oss;
- oss
- << "is not up to date or is corrupted."
- << " Its element number " << j
- << ", which is '" << GetDBNames()[j].ShortName
- << "', cannot be read."
- ;
- BadFile(NewFilename, oss.str());
- break;
- }
- dictionary[temp->GetKey()] = *temp;
- delete temp;
- }
}
//============================================================================
@@ -161,17 +202,6 @@
//============================================================================
void DBDictionary::WriteDB(std::string const& filename)
{
- JRPS::JrPs_ofpstream ops
- (filename.c_str()
- ,JRPS::JrPs_pstream::xxtrunc | JRPS::JrPs_pstream::xxcreat
- );
- if(!ops)
- {
- fatal_error()
- << "Cannot open database file '" << filename << "'."
- << LMI_FLUSH
- ;
- }
if(NumberOfEntries != static_cast<int>(dictionary.size()))
{
fatal_error()
@@ -189,11 +219,20 @@
}
fatal_error() << LMI_FLUSH;
}
- ops << dictionary.size();
- for(unsigned int j = 0; j < dictionary.size(); j++)
- {
- ops << &dictionary[j];
- }
+
+ xml_lmi::xml_document document(xml_root_name());
+ xml::element& root = document.root_node();
+
+ xml_lmi::set_attr(root, "version", "0");
+ xml_serialize::to_xml(root, dictionary);
+
+ // Instead of this:
+// document.save(filename);
+ // for the nonce, explicitly change the extension, in order to
+ // force external product-file code to use the new extension.
+ fs::path path(filename, fs::native);
+ path = fs::change_extension(path, ".database");
+ document.save(path.string());
}
//===========================================================================
@@ -633,7 +672,7 @@
Add(TDBValue(DB_ExpRatIBNRMult , 6.0));
Add(TDBValue(DB_ExpRatAmortPeriod , 4.0));
- WriteDB(AddDataDir("sample.db4"));
+ WriteDB(AddDataDir("sample.database"));
}
//============================================================================
@@ -644,7 +683,7 @@
fs::directory_iterator end_i;
for(; i != end_i; ++i)
{
- if(is_directory(*i) || ".db4" != fs::extension(*i))
+ if(is_directory(*i) || ".database" != fs::extension(*i))
{
continue;
}
Modified: lmi/trunk/ihs_dbvalue.cpp
===================================================================
--- lmi/trunk/ihs_dbvalue.cpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/ihs_dbvalue.cpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -31,63 +31,19 @@
#include "alert.hpp"
#include "assert_lmi.hpp"
#include "dbnames.hpp"
-#include "math_functors.hpp" // greater_of(), lesser_of
+#include "math_functors.hpp" // greater_of(), lesser_of()
#include "print_matrix.hpp"
#include "value_cast.hpp"
+#include "xml_serialize.hpp"
#include <algorithm>
#include <functional>
#include <istream>
-#include <limits> // numeric_limits<>
+#include <iterator> // std::advance()
+#include <limits> // std::numeric_limits
#include <numeric>
#include <ostream>
-#ifndef stlstrm_hpp
-#define stlstrm_hpp
-
-// This misbegotten thing used to be a distinct header, but now we've
-// extirpated it everywhere else. TODO ?? Stop using it here too.
-
-// Stream STL containers with Joshua Rowe's object streaming.
-
-#include "ihs_fpios.hpp"
-namespace JRPS = JOSHUA_ROWE_PERSISTENT_STREAMS;
-
-#include <cassert>
-#include <iostream>
-#include <string>
-#include <vector>
-
-template<typename T>
-JRPS::JrPs_ipstream& operator>> (JRPS::JrPs_ipstream& ips, std::vector<T>& x)
-{
- x.erase(x.begin(), x.end());
- typename std::vector<T>::size_type vector_size;
- ips >> vector_size;
- x.reserve(vector_size);
- typename std::vector<T>::value_type z;
- for(typename std::vector<T>::size_type j = 0; j < vector_size; j++)
- {
- ips >> z;
- x.push_back(z);
- }
- assert(vector_size == x.size());
- return ips;
-}
-
-template<typename T>
-JRPS::JrPs_opstream& operator<< (JRPS::JrPs_opstream& ops, std::vector<T>
const& x)
-{
- ops << x.size();
- for(typename std::vector<T>::const_iterator i = x.begin(); i < x.end();
i++)
- {
- ops << *i;
- }
- return ops;
-}
-
-#endif // stlstrm_hpp
-
static int const ScalarDims[TDBValue::e_number_of_axes] = {1, 1, 1, 1, 1, 1,
1};
static int const MaxPossibleElements = std::numeric_limits<int>::max();
@@ -187,10 +143,9 @@
//============================================================================
TDBValue::TDBValue(TDBValue const& obj)
- :JRPS::JrPs_pstreamable()
- ,key(obj.key)
- ,axis_lengths(obj.axis_lengths)
- ,data_values(obj.data_values)
+ :key (obj.key)
+ ,axis_lengths (obj.axis_lengths)
+ ,data_values (obj.data_values)
{
}
@@ -692,71 +647,26 @@
return z.write(os);
}
-// Streaming implementation
-
-TDBValue::TDBValue(JRPS::JrPs_pstreamableInit)
- :key(0)
- ,axis_lengths(e_number_of_axes)
+void TDBValue::read(xml::element const& e)
{
-}
+ std::string short_name;
+ xml_serialize::get_element(e, "key" , short_name );
+ key = db_key_from_name(short_name);
+ xml_serialize::get_element(e, "axis_lengths" , axis_lengths );
+ xml_serialize::get_element(e, "extra_axes_values", extra_axes_values);
+ xml_serialize::get_element(e, "extra_axes_names" , extra_axes_names );
+ xml_serialize::get_element(e, "data_values" , data_values );
-JRPS::JrPs_pstreamable* TDBValue::jrps_build()
-{
- return new TDBValue(JRPS::JrPs_pstreamableinit);
-}
-
-JRPS::JrPs_pstreamreg RegTDBValue
- ("TDBValue"
- ,TDBValue::jrps_build
- ,JRPS_PSTREAM_DELTA(TDBValue)
- );
-
-// TODO ?? Couldn't templates handle this?
-JRPS::JrPs_opstream& operator<< (JRPS::JrPs_opstream& os, TDBValue const* p)
-{
- return os << (JRPS::JrPs_pstreamable const*)p;
-}
-
-JRPS::JrPs_ipstream& operator>> (JRPS::JrPs_ipstream& is, TDBValue*& p)
-{
- return is >> (void const*&)p;
-}
-
-void* TDBValue::read(JRPS::JrPs_ipstream& is)
-{
- int version;
- is >> version;
- if(version < StreamingVersion)
- {
- fatal_error()
- << "Program supports input versions up to "
- << StreamingVersion
- << " but input file is version "
- << version
- << " ."
- << LMI_FLUSH
- ;
- }
-
- is >> key;
- is >> axis_lengths;
- is >> extra_axes_values;
- is >> extra_axes_names;
- is >> data_values;
-
LMI_ASSERT(getndata() == static_cast<int>(data_values.size()));
LMI_ASSERT
( 0 < static_cast<int>(data_values.size())
&& static_cast<int>(data_values.size()) < MaxPossibleElements
);
-
- return this;
+ AreAllAxesOK();
}
-void TDBValue::write(JRPS::JrPs_opstream& os) const
+void TDBValue::write(xml::element& e) const
{
- os << StreamingVersion;
-
LMI_ASSERT(getndata() == static_cast<int>(data_values.size()));
LMI_ASSERT
( 0 < static_cast<int>(data_values.size())
@@ -764,15 +674,10 @@
);
AreAllAxesOK();
- os << key;
- os << axis_lengths;
- os << extra_axes_values;
- os << extra_axes_names;
- os << data_values;
+ xml_serialize::set_element(e, "key" , db_name_from_key(key));
+ xml_serialize::set_element(e, "axis_lengths" , axis_lengths );
+ xml_serialize::set_element(e, "extra_axes_values", extra_axes_values);
+ xml_serialize::set_element(e, "extra_axes_names" , extra_axes_names );
+ xml_serialize::set_element(e, "data_values" , data_values );
}
-char const* TDBValue::streamableName() const
-{
- return "TDBValue";
-}
-
Modified: lmi/trunk/ihs_dbvalue.hpp
===================================================================
--- lmi/trunk/ihs_dbvalue.hpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/ihs_dbvalue.hpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -32,10 +32,8 @@
#include "dbindex.hpp"
#include "so_attributes.hpp"
+#include "xml_lmi_fwd.hpp"
-#include "ihs_fpios.hpp"
-namespace JRPS = JOSHUA_ROWE_PERSISTENT_STREAMS;
-
#include <iosfwd>
#include <string>
#include <vector>
@@ -49,11 +47,13 @@
,e_Incremental
};
+namespace xml_serialize {template<typename T> struct xml_io;}
+
class LMI_SO TDBValue
- :private JRPS::JrPs_pstreamable
{
friend std::istream& operator>>(std::istream&, TDBValue&);
friend std::ostream& operator<<(std::ostream&, TDBValue const&);
+ friend struct xml_serialize::xml_io<TDBValue>;
public:
// Separate enumerators here facilitate compile-time assertions
@@ -123,6 +123,9 @@
bool AreAllAxesOK() const;
void FixupIndex(std::vector<double>& idx) const;
+ void read (xml::element const&);
+ void write(xml::element&) const;
+
int key; // Database dictionary key
// Each database item has a number of axes.
@@ -151,24 +154,6 @@
std::vector<std::string> extra_axes_names;
std::vector<double> extra_axes_values;
std::vector<e_IdxType> extra_axes_types;
-
-// The following sections don't follow the normal order for access
-// specifiers. Grouping them together here facilitates their
-// expunction as soon as we get rid of 'ihs_[f]pios.?pp'.
-
- public:
- static JRPS::JrPs_pstreamable* jrps_build();
- friend JRPS::JrPs_ipstream& operator>> (JRPS::JrPs_ipstream&, TDBValue*&);
- friend JRPS::JrPs_opstream& operator<< (JRPS::JrPs_opstream&, TDBValue
const*);
-
- protected:
- virtual void* read(JRPS::JrPs_ipstream&);
- virtual void write(JRPS::JrPs_opstream&) const;
-
- private:
- TDBValue(JRPS::JrPs_pstreamableInit);
- virtual char const* streamableName() const;
- enum {StreamingVersion = 1};
};
/*
Deleted: lmi/trunk/ihs_fpios.cpp
===================================================================
--- lmi/trunk/ihs_fpios.cpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/ihs_fpios.cpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -1,343 +0,0 @@
-// Joshua Rowe's "Really cool persistent object stream library".
-//
-// Copyright (C) 2000, 2005, 2006, 2007, 2008, 2009, 2010 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
-//
-// http://savannah.nongnu.org/projects/lmi
-// email: <address@hidden>
-// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
-
-// $Id$
-
-// This is a derived work based on Joshua Rowe's
-// "Really cool persistent object stream library"
-// which he released this under GNU General Public License version 2.
-//
-// The original, version 0.0.3, was downloaded from:
-// http://metalab.unc.edu/pub/Linux/devel/lang/c++/pstream-0.0.3.tar.gz
-// and was modified as follows:
-//
-// 20000528 Gregory W. Chicares made changes marked inline 'GWC',
-// and released the modified version it under the same version of
-// the same license as the original. Any defect in this modified
-// version should not reflect on Joshua Rowe's reputation.
-//
-// 20050108 Gregory W. Chicares substituted 'LMI_MSW' for a
-// proprietary macro.
-//
-// and in any later years given in the copyright notice above as
-// detailed in ChangeLog.
-
-/* fpios.cc
- * Written by Joshua Rowe
- * file-based persistent object streams
- */
-
-#ifdef __BORLANDC__
-# include "pchfile.hpp"
-# pragma hdrstop
-#endif // __BORLANDC__
-
-#include "ihs_fpios.hpp" // GWC arbitrarily changed .hh to .hpp
-
-// Begin GWC mods
-// Neither of these is in the language standard
-//#include <unistd.h>
-#include "platform_dependent.hpp" // unistd.h and other platforms too
-// End GWC mods
-
-#include <errno.h>
-#include <fcntl.h>
-
-// TODO ?? Probably anything here that's actually useful should be
-// moved to 'platform_dependent.hpp'.
-#if defined LMI_POSIX
-# include <sys/types.h>
-# include <sys/stat.h>
-#elif defined LMI_MSW
-# if defined __GNUC__ && defined __STRICT_ANSI__
-# define GNU_STRICT_ANSI_ORIGINALLY_NOT_DEFINED
-# undef __STRICT_ANSI__
-# endif // !(defined(__GNUC__) && defined(__STRICT_ANSI__))
-# include <io.h>
-# if defined __GNUC__ && defined GNU_STRICT_ANSI_ORIGINALLY_NOT_DEFINED
-# define __STRICT_ANSI__ ""
-# endif // !(defined(__GNUC__) && defined(__STRICT_ANSI__))
-#else // Unknown OS.
-# error Unknown operating system. Consider contributing support.
-#endif // Unknown OS.
-
-namespace JOSHUA_ROWE_PERSISTENT_STREAMS
-{
-
-JrPs_fdpstreambuf::JrPs_fdpstreambuf()
- :fd(-1)
-{
-}
-
-JrPs_fdpstreambuf::JrPs_fdpstreambuf(int afd, int aflags)
- :JrPs_pstreambuf (aflags)
- ,fd (afd)
-{
-}
-
-JrPs_fdpstreambuf::~JrPs_fdpstreambuf()
-{
-// GWC suppressed the next line under the assumption it should always be closed
-// if (flags & JrPs_pstream::xxclose)
- close();
-}
-
-void JrPs_fdpstreambuf::close()
-{
- if (::close(fd) == -1)
- err = errno;
- else
- err = 0;
- fd = -1;
-}
-
-void JrPs_fdpstreambuf::open(int afd, int aflags)
-{
- if (flags & JrPs_pstream::xxclose)
- close();
- fd = afd;
- flags = aflags;
-}
-
-void* JrPs_fdpstreambuf::read(void* d, int l)
-{
- if (error())
- return 0;
- if (::read(fd, d, l) == -1)
- err = errno;
- else
- err = 0;
- if (error())
- return 0;
- else
- return d;
-}
-
-void JrPs_fdpstreambuf::write(const void* d, int l)
-{
- if (error())
- return;
- if (::write(fd, d, l) == -1)
- err = errno;
- else
- err = 0;
-}
-
-JrPs_fdpstream::JrPs_fdpstream()
-: JrPs_pstream(0, 0)
-{
-}
-
-JrPs_fdpstream::JrPs_fdpstream(int afd, int aflags)
-: JrPs_pstream(0, flags)
-{
- open(afd, aflags);
-}
-
-void JrPs_fdpstream::open(int afd, int aflags)
-{
-// if ((buf != 0) & (flags & xxkill)) // pretty sure this is incorrect
- if ((buf != 0) && (flags & xxkill))
- delete buf;
- buf = new JrPs_fdpstreambuf(afd, aflags);
- flags = aflags;
- flags |= xxkill;
-}
-
-JrPs_ifdpstream::JrPs_ifdpstream()
-: JrPs_fdpstream(0, 0)
-{
-}
-
-JrPs_ifdpstream::JrPs_ifdpstream(int afd, int aflags)
-: JrPs_fdpstream(afd, aflags)
-{
-}
-
-JrPs_ofdpstream::JrPs_ofdpstream()
-: JrPs_fdpstream(0, 0)
-{
-}
-
-JrPs_ofdpstream::JrPs_ofdpstream(int afd, int aflags)
-: JrPs_fdpstream(afd, aflags)
-{
-}
-
-JrPs_iofdpstream::JrPs_iofdpstream()
-: JrPs_fdpstream(0, 0)
-{
-}
-
-JrPs_iofdpstream::JrPs_iofdpstream(int afd, int aflags)
-: JrPs_fdpstream(afd, aflags | xxread | xxwrite)
-{
-}
-
-JrPs_fpstreambuf::JrPs_fpstreambuf(const char* aname, int aflags, int amode)
-: JrPs_fdpstreambuf()
-{
- open(aname, aflags, amode);
-}
-
-JrPs_fpstreambuf::~JrPs_fpstreambuf()
-{
-}
-
-// TODO ?? KLUDGE
-
-#if 0 && defined __GNUC__
-# define O_BINARY _O_BINARY
-# define O_WRONLY _O_WRONLY
-# define O_RDONLY _O_RDONLY
-# define O_APPEND _O_APPEND
-# define O_TRUNC _O_TRUNC
-# define O_EXCL _O_EXCL
-# define O_CREAT _O_CREAT
-#endif // __GNUC__
-
-// COMPILER !! (all compilers) Make certain nonstandard functions available.
-// TODO ?? We're going to a lot of trouble for three crummy symbols.
-// Maybe we should instead define _O_BINARY and prototype _fileno() and
-// _setmode() with simpler conditions--the way _setmode() is treated
-// for borland below.
-// INELEGANT !! Why not do this in "platform_dependent.hpp"?
-
-#ifdef LMI_MSW
-# if defined __GNUC__ && defined __STRICT_ANSI__
-# define GNU_STRICT_ANSI_ORIGINALLY_NOT_DEFINED
-# undef __STRICT_ANSI__
-# endif // !(defined(__GNUC__) && defined(__STRICT_ANSI__))
-// for _O_BINARY, _fileno(), _setmode()
-# include <io.h>
-# include <fcntl.h>
-# if defined __GNUC__ && defined GNU_STRICT_ANSI_ORIGINALLY_NOT_DEFINED
-# define __STRICT_ANSI__ ""
-# endif // !(defined(__GNUC__) && defined(__STRICT_ANSI__))
-# if defined __BORLANDC__
-# define _setmode setmode
-# endif // __BORLANDC__
-# include <stdio.h>
-#endif
-
-void JrPs_fpstreambuf::open(const char* aname, int aflags, int amode)
-{
-
- // GWC: changed from
- // ind fd = ::open(...
- // which I assume is an oversight because it shadows a class member
- unsigned int inspectable_flags = // OOPS aflags | // GWC added aflags |
-#ifdef O_BINARY
- O_BINARY |
-#endif
- ((aflags & JrPs_pstream::xxwrite) ? O_WRONLY : 0) |
- ((aflags & JrPs_pstream::xxread) ? O_RDONLY : 0) |
- ((aflags & JrPs_pstream::xxappen) ? O_APPEND : 0) |
- ((aflags & JrPs_pstream::xxtrunc) ? O_TRUNC : 0) |
- ((aflags & JrPs_pstream::xxexcl) ? O_EXCL : 0) |
- ((aflags & JrPs_pstream::xxcreat) ? O_CREAT : 0)
- ;
- fd = ::open(aname,
- inspectable_flags,
-/*
- O_BINARY |
- ((aflags & JrPs_pstream::xxwrite) ? O_WRONLY : 0) |
- ((aflags & JrPs_pstream::xxread) ? O_RDONLY : 0) |
- ((aflags & JrPs_pstream::xxappen) ? O_APPEND : 0) |
- ((aflags & JrPs_pstream::xxtrunc) ? O_TRUNC : 0) |
- ((aflags & JrPs_pstream::xxexcl) ? O_EXCL : 0) |
- ((aflags & JrPs_pstream::xxcreat) ? O_CREAT : 0),
-*/
- amode);
- if (fd == -1)
- error(errno);
- else
- error(0);
- JrPs_fdpstreambuf::open(fd, aflags | JrPs_pstream::xxclose);
-}
-
-JrPs_fpstream::JrPs_fpstream()
-{
-}
-
-JrPs_fpstream::JrPs_fpstream(const char* aname, int aflags, int amode)
-{
- open(aname, aflags, amode);
-}
-
-JrPs_fpstream::~JrPs_fpstream()
-{
-}
-
-void JrPs_fpstream::open(const char* aname, int aflags, int amode)
-{
- if (buf != 0)
- delete buf;
- buf = new JrPs_fpstreambuf(aname, aflags, amode);
- flags = aflags;
-}
-
-JrPs_ifpstream::JrPs_ifpstream()
-{
-}
-
-JrPs_ifpstream::JrPs_ifpstream(const char* aname, int aflags, int amode)
-{
- open(aname, aflags | xxread, amode);
-}
-
-void JrPs_ifpstream::open(const char* aname, int aflags, int amode)
-{
- JrPs_fpstream::open(aname, aflags, amode);
- // GWC: add this header for compatibility with borland pstreams
- char bi_header[5];
- readbytes(bi_header, 5);
-}
-
-JrPs_ofpstream::JrPs_ofpstream()
-{
-}
-
-JrPs_ofpstream::JrPs_ofpstream(const char* aname, int aflags, int amode)
-{
- open(aname, aflags | xxwrite, amode);
-}
-
-void JrPs_ofpstream::open(const char* aname, int aflags, int amode)
-{
- JrPs_fpstream::open(aname, aflags, amode);
- // GWC: add this header for compatibility with borland pstreams
- const char bi_header[5] = {0x03a, 0x01, 0x01, 0x0, 0x0};
- writebytes((const void*)bi_header, 5);
-}
-
-JrPs_iofpstream::JrPs_iofpstream()
-{
-}
-
-JrPs_iofpstream::JrPs_iofpstream(const char* aname, int aflags, int amode)
-{
- JrPs_fpstream::open(aname, aflags | xxwrite | xxappen | xxread, amode);
- // GWC: TODO ?? What would we do about the borland header here?
-}
-
-} // namespace JOSHUA_ROWE_PERSISTENT_STREAMS
-
Deleted: lmi/trunk/ihs_fpios.hpp
===================================================================
--- lmi/trunk/ihs_fpios.hpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/ihs_fpios.hpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -1,189 +0,0 @@
-// Joshua Rowe's "Really cool persistent object stream library".
-//
-// Copyright (C) 2000, 2005, 2006, 2007, 2008, 2009, 2010 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
-//
-// http://savannah.nongnu.org/projects/lmi
-// email: <address@hidden>
-// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
-
-// $Id$
-
-// This is a derived work based on Joshua Rowe's
-// "Really cool persistent object stream library"
-// which he released this under GNU General Public License version 2.
-//
-// The original, version 0.0.3, was downloaded from:
-// http://metalab.unc.edu/pub/Linux/devel/lang/c++/pstream-0.0.3.tar.gz
-// and was modified as follows:
-//
-// 20000528 Gregory W. Chicares made changes marked inline 'GWC',
-// and released the modified version it under the same version of
-// the same license as the original. Any defect in this modified
-// version should not reflect on Joshua Rowe's reputation.
-//
-// and in any later years given in the copyright notice above as
-// detailed in ChangeLog.
-
-/* fpios.hh
- * Written by Joshua Rowe
- * File-based persistent object streams
- */
-
-#ifndef ihs_fpios_hpp
-#define ihs_fpios_hpp
-
-#include "config.hpp"
-
-#include "ihs_pios.hpp" // GWC arbitrarily changed .hh to .hpp
-#include "so_attributes.hpp"
-
-#include <fcntl.h>
-#if defined LMI_MSW
-# include <io.h>
-#elif defined LMI_POSIX
-# include <sys/types.h>
-#endif // POSIX platform.
-#include <sys/stat.h>
-
-namespace JOSHUA_ROWE_PERSISTENT_STREAMS
-{
-
-class JrPs_fdpstreambuf;
-class JrPs_fdpstream;
-class JrPs_ifdpstream;
-class JrPs_ofdpstream;
-class JrPs_fpstreambuf;
-class JrPs_fpstream;
-class JrPs_ifpstream;
-class JrPs_ofpstream;
-class JrPs_iofpstream;
-
-class LMI_SO JrPs_fdpstreambuf : public JrPs_pstreambuf
-{
-protected:
- int fd;
-public:
- JrPs_fdpstreambuf();
- JrPs_fdpstreambuf(int afd, int aflags);
-// GWC made this dtor virtual--OOPS!
-// virtual ~JrPs_fdpstreambuf();
- ~JrPs_fdpstreambuf();
- virtual void close();
- void open(int afd, int aflags = 0);
- virtual void* read(void* d, int l);
- virtual void write(const void* d, int l);
-};
-
-class LMI_SO JrPs_fdpstream : virtual public JrPs_pstream
-{
- JrPs_fdpstream(const JrPs_fdpstream&);
- JrPs_fdpstream& operator= (const JrPs_fdpstream&);
-protected:
-public:
- JrPs_fdpstream();
- JrPs_fdpstream(int afd, int aflags = 0);
- void open(int afd, int aflags = 0);
-};
-
-class LMI_SO JrPs_ifdpstream : virtual public JrPs_fdpstream, virtual
public JrPs_ipstream
-{
- JrPs_ifdpstream(const JrPs_ifdpstream&);
- JrPs_ifdpstream& operator= (const JrPs_ifdpstream&);
-protected:
-public:
- JrPs_ifdpstream();
- JrPs_ifdpstream(int afd, int aflags = 0);
-};
-
-class LMI_SO JrPs_ofdpstream : virtual public JrPs_fdpstream, virtual
public JrPs_opstream
-{
- JrPs_ofdpstream(const JrPs_ofdpstream&);
- JrPs_ofdpstream& operator= (const JrPs_ofdpstream&);
-protected:
-public:
- JrPs_ofdpstream();
- JrPs_ofdpstream(int afd, int aflags = 0);
-};
-
-class LMI_SO JrPs_iofdpstream : virtual public JrPs_ifdpstream, virtual
public JrPs_ofdpstream
-{
- JrPs_iofdpstream(const JrPs_iofdpstream&);
- JrPs_iofdpstream& operator= (const JrPs_iofdpstream&);
-protected:
-public:
- JrPs_iofdpstream();
- JrPs_iofdpstream(int afd, int aflags = 0);
-};
-
-class LMI_SO JrPs_fpstreambuf : public JrPs_fdpstreambuf
-{
-protected:
-public:
- JrPs_fpstreambuf();
- virtual ~JrPs_fpstreambuf();
- JrPs_fpstreambuf(const char* aname, int aflags, int amode = 0644);
- void open(const char* aname, int aflags, int amode = 0644);
-};
-
-class LMI_SO JrPs_fpstream : virtual public JrPs_fdpstream
-{
- JrPs_fpstream(const JrPs_fpstream&);
- JrPs_fpstream& operator= (const JrPs_fpstream&);
-protected:
-public:
- JrPs_fpstream();
- virtual ~JrPs_fpstream();
- JrPs_fpstream(const char* aname, int aflags, int amode = 0644);
- void open(const char* aname, int aflags, int amode = 0644);
-};
-
-class LMI_SO JrPs_ifpstream : virtual public JrPs_fpstream, virtual public
JrPs_ifdpstream
-{
- JrPs_ifpstream(const JrPs_ifpstream&);
- JrPs_ifpstream& operator= (const JrPs_ifpstream&);
-protected:
-public:
- JrPs_ifpstream();
- JrPs_ifpstream(const char* aname, int aflags = 0, int amode = 0644);
- void open(const char* aname, int aflags, int amode = 0644);
-};
-
-class LMI_SO JrPs_ofpstream : virtual public JrPs_fpstream, virtual public
JrPs_ofdpstream
-{
- JrPs_ofpstream(const JrPs_ofpstream&);
- JrPs_ofpstream& operator= (const JrPs_ofpstream&);
-protected:
-public:
- JrPs_ofpstream();
- JrPs_ofpstream(const char* aname, int aflags =
JOSHUA_ROWE_PERSISTENT_STREAMS::JrPs_pstream::xxcreat, int amode = 0644);
-// JrPs_ofpstream(const char* aname, int aflags = 0x0020, int amode = 0644);
- void open(const char* aname, int aflags, int amode = 0644);
-};
-
-class LMI_SO JrPs_iofpstream : virtual public JrPs_ifpstream, virtual
public JrPs_ofpstream
-{
- JrPs_iofpstream(const JrPs_iofpstream&);
- JrPs_iofpstream& operator= (const JrPs_iofpstream&);
-protected:
-public:
- JrPs_iofpstream();
- JrPs_iofpstream(const char* aname, int aflags =
JOSHUA_ROWE_PERSISTENT_STREAMS::JrPs_pstream::xxcreat, int amode = 0644);
-// JrPs_iofpstream(const char* aname, int aflags = 0x0020, int amode = 0644);
-};
-
-} // namespace JOSHUA_ROWE_PERSISTENT_STREAMS
-#endif // ihs_fpios_hpp
-
Deleted: lmi/trunk/ihs_pios.cpp
===================================================================
--- lmi/trunk/ihs_pios.cpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/ihs_pios.cpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -1,617 +0,0 @@
-// Joshua Rowe's "Really cool persistent object stream library".
-//
-// Copyright (C) 2000, 2005, 2006, 2007, 2008, 2009, 2010 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
-//
-// http://savannah.nongnu.org/projects/lmi
-// email: <address@hidden>
-// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
-
-// $Id$
-
-// This is a derived work based on Joshua Rowe's
-// "Really cool persistent object stream library"
-// which he released this under GNU General Public License version 2.
-//
-// The original, version 0.0.3, was downloaded from:
-// http://metalab.unc.edu/pub/Linux/devel/lang/c++/pstream-0.0.3.tar.gz
-// and was modified as follows:
-//
-// 20000528 Gregory W. Chicares made changes marked inline 'GWC',
-// and released the modified version it under the same version of
-// the same license as the original. Any defect in this modified
-// version should not reflect on Joshua Rowe's reputation.
-//
-// and in any later years given in the copyright notice above as
-// detailed in ChangeLog.
-
-/* pios.cc
- * Written by Joshua Rowe
- * Definitions for the streamable class library
- */
-
-#ifdef __BORLANDC__
-# include "pchfile.hpp"
-# pragma hdrstop
-#endif // __BORLANDC__
-
-#include "ihs_pios.hpp" // GWC arbitrarily changed .hh to .hpp
-
-#include <cstring>
-
-namespace JOSHUA_ROWE_PERSISTENT_STREAMS
-{
-
-JrPs_pstream::JrPs_pstream(JrPs_pstreambuf *abuf, int aflags)
- :buf (abuf)
- ,curid (1)
- ,err (0)
- ,flags (aflags)
- ,streamed (0)
-{
-}
-
-JrPs_pstream::~JrPs_pstream()
-{
- close();
- // GWC: Perhaps the intention was to pass creation flags including
- // xxkill to ctors of intermediate classes; that does not occur,
- // so close() never deletes buf.
- delete buf;
- buf = 0;
-}
-
-void JrPs_pstream::addstreamed(const JrPs_pstreamable* obj)
-{
- streamed = new JrPs_pstreamed(curid++, streamed, static_cast<const
void*>(obj));
-}
-
-void JrPs_pstream::close()
-{
- const JrPs_pstreamed * p = streamed;
- const JrPs_pstreamed * q;
- for(; p != 0; p = q)
- {
- q = p->next;
- delete p;
- }
- if (buf != 0)
- {
- if (flags & xxkill)
- {
- delete buf;
- buf = 0;
- }
- else if (flags & xxclose)
- {
- buf->close();
- error(buf->error());
- }
- }
- else
- error(peNoBuffer);
- curid = 1;
- streamed = 0;
- err = 0;
-}
-
-void JrPs_pstream::error(int aerror)
-{
- err = aerror;
-}
-
-int JrPs_pstream::error()
-{
- return err;
-}
-
-// GWC added: compatibility with BI
-int JrPs_pstream::good()
-{
- return 0 == err;
-}
-
-int JrPs_pstream::lookup(const void* q)
-{
- const JrPs_pstreamed * p = streamed;
- for (; p != 0; p = p->next)
- if (p->p == q)
- break;
- if (p)
- return p->id; // p = 0 if not found, otherwise
- // it points to the JrPs_pstreamreg
- return 0;
-}
-
-const JrPs_pstreamed * JrPs_pstream::lookup(int aid)
-{
- const JrPs_pstreamed * p = streamed;
- for (; p != 0; p = p->next)
- if (p->id == aid)
- break;
- return p;
-}
-
-int JrPs_pstream::operator!()
-{
- return err;
-}
-
-JrPs_opstream::JrPs_opstream(JrPs_pstreambuf *abuf, int aflags)
-: JrPs_pstream(abuf, aflags)
-{
-}
-
-void JrPs_opstream::writebyte(char c)
-{
- writebytes((const void*) &c, sizeof(c));
-}
-
-void JrPs_opstream::writebytes(const void* d, int l)
-{
- if (error())
- return;
- if (buf != 0)
- buf->write(d, l);
- else
- error(peNoBuffer);
- error(buf->error());
-}
-
-void JrPs_opstream::writeint(int i)
-{
- writebytes(&i, sizeof(i));
-}
-
-void JrPs_opstream::writeobj(const JrPs_pstreamable * obj)
-{
- int index;
- if (obj == 0)
- writebyte(JrPs_pstream::ptNULL);
- else if ((index = lookup(static_cast<const void*>(obj))) != 0)
- {
- writebyte(JrPs_pstream::ptIndex);
- writeint(index);
- }
- else
- {
- writebyte(JrPs_pstream::ptObject);
- // Write the object Prefix
- writebyte('[');
- writestring(obj->streamableName());
- // Write the object data
- addstreamed(obj);
- obj->write(*this);
- // Write the object suffix
- writebyte(']');
- }
-}
-
-// GWC added: see comment under
-// JrPs_opstream& operator<< (JrPs_opstream & os, const JrPs_pstreamable& x)
-void JrPs_opstream::writeref(const JrPs_pstreamable * obj)
-{
- // Write the object Prefix
- writebyte('[');
- writestring(obj->streamableName());
- // Write the object data
- addstreamed(obj);
- obj->write(*this);
- // Write the object suffix
- writebyte(']');
-}
-
-void JrPs_opstream::writestring(const char* s)
-{
- int l = std::strlen(s);
- writeint(l);
- char* temp = new char[1 + l];
- std::strcpy(temp, s);
- writebytes(reinterpret_cast<void*>(temp), l);
- delete[]temp;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, bool c)
-{
- os.writebytes(&c, sizeof(c));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, char c)
-{
- os.writebyte(c);
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, signed char c)
-{
- os.writebyte(c);
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, unsigned char c)
-{
- os.writebyte(c);
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, const char* s)
-{
- os.writestring(s);
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, signed char const* s)
-{
- os.writestring(reinterpret_cast<const char*>(s));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, unsigned char const* s)
-{
- os.writestring(reinterpret_cast<const char*>(s));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, std::string const& s)
-{
- os.writestring(const_cast<char*>(s.c_str()));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, short int c)
-{
- os.writebytes(&c, sizeof(c));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, unsigned short int c)
-{
- os.writebytes(&c, sizeof(c));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, int c)
-{
- os.writebytes(&c, sizeof(c));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, unsigned int c)
-{
- os.writebytes(&c, sizeof(c));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, long int c)
-{
- os.writebytes(&c, sizeof(c));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, unsigned long int c)
-{
- os.writebytes(&c, sizeof(c));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, float c)
-{
- os.writebytes(&c, sizeof(c));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, double c)
-{
- os.writebytes(&c, sizeof(c));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, long double c)
-{
- os.writebytes(&c, sizeof(c));
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, const JrPs_pstreamable& x)
-{
-// os.writeobj(&x); // GWC replaced this with the following
-// GWC: In the original code, this function did the same thing as
-// JrPs_opstream& operator<< (JrPs_opstream & os, const JrPs_pstreamable* x)
-// although the corresponding operator>> implementations differ
-// for reference vs. pointer arguments.
- os.writeref(&x);
- return os;
-}
-
-JrPs_opstream& operator<< (JrPs_opstream & os, const JrPs_pstreamable* x)
-{
- os.writeobj(x);
- return os;
-}
-
-JrPs_ipstream::JrPs_ipstream(JrPs_pstreambuf *abuf, int aflags)
-: JrPs_pstream(abuf, aflags)
-{
-}
-
-char JrPs_ipstream::readbyte()
-{
- char c;
- readbytes(&c, sizeof(c));
- return c;
-}
-
-const void* JrPs_ipstream::readbytes(void* d, int l)
-{
- if (error())
- return 0;
- const void* x = 0;
- if (buf != 0)
- x = buf->read(d, l);
- else
- error(peNoBuffer);
- return x;
-}
-
-int JrPs_ipstream::readint()
-{
- int i;
- readbytes(&i, sizeof(i));
- return i;
-}
-
-void* JrPs_ipstream::readobj(JrPs_pstreamreg *d, JrPs_pstreamable *m)
-{
- if (error())
- return 0;
- if (m == 0)
- m = d->builder();
- streamed = new JrPs_pstreamed(curid++, streamed, ((char *)m - d->delta));
- void* q = m->read(*this);
- readbyte();
- if (error())
- return 0;
- return q;
-}
-
-char * JrPs_ipstream::readstring()
-{
- int l = readint();
- char * s = new char[l+1];
- readbytes(s, l);
- s[l] = 0;
- if (error())
- {
- delete[] s;
- s = 0;
- }
- return s;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, bool &c)
-{
- is.readbytes(&c, sizeof(c));
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, char &c)
-{
- c = is.readbyte();
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, signed char &c)
-{
- c = is.readbyte();
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, unsigned char &c)
-{
- c = is.readbyte();
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, char * &s)
-{
- s = is.readstring();
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, signed char * &s)
-{
- s = reinterpret_cast<signed char*>(is.readstring());
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, unsigned char * &s)
-{
- s = reinterpret_cast<unsigned char*>(is.readstring());
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, std::string& s)
-{
- char * c = is.readstring();
- s = c;
- delete[] c;
-
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, short int &c)
-{
- is.readbytes(&c, sizeof(c));
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, unsigned short int &c)
-{
- is.readbytes(&c, sizeof(c));
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, int &c)
-{
- is.readbytes(&c, sizeof(c));
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, unsigned int &c)
-{
- is.readbytes(&c, sizeof(c));
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, long int &c)
-{
- is.readbytes(&c, sizeof(c));
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, unsigned long int &c)
-{
- is.readbytes(&c, sizeof(c));
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, float &c)
-{
- is.readbytes(&c, sizeof(c));
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, double &c)
-{
- is.readbytes(&c, sizeof(c));
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, long double &c)
-{
- is.readbytes(&c, sizeof(c));
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, JrPs_pstreamable & x)
-{
- is.readbyte();
-// is.readbyte(); // GWC: TODO ?? Isn't this second call erroneous?
- char * c = is.readstring();
- JrPs_pstreamreg * d = JrPs_pstreamreg::findclass(c);
- delete[] c;
- is.readobj(d, &x);
- return is;
-}
-
-JrPs_ipstream& operator>> (JrPs_ipstream & is, const void*& x)
-{
- char c = is.readbyte();
- switch (c)
- {
- default:
- break;
- case JrPs_pstream::ptNULL:
- x = 0;
- return is;
- // break;
- case JrPs_pstream::ptIndex:
- x = static_cast<const void*>(is.lookup(is.readint())->p);
- return is;
- // break;
- case JrPs_pstream::ptObject:
- is.readbyte();
- case 91:
- char * d = is.readstring();
- JrPs_pstreamreg * r = JrPs_pstreamreg::findclass(d);
- delete[] d;
- x = is.readobj(r, 0);
- break;
- }
- return is;
-}
-
-JrPs_pstreamed::JrPs_pstreamed(int aid, const JrPs_pstreamed* anext, const
void* ap)
- :id (aid)
- ,next (anext)
- ,p (ap)
-{
-}
-
-JrPs_pstreamable::JrPs_pstreamable()
-{
-}
-
-JrPs_pstreamable::JrPs_pstreamable(JrPs_pstreamableInit)
-{
-}
-
-JrPs_pstreamable::~JrPs_pstreamable()
-{
-}
-
-JrPs_pstreamreg * pstreamreged = 0;
-
-JrPs_pstreamreg::JrPs_pstreamreg(const char* aname, BUILDER abuilder,
std::size_t adelta)
- :name (aname)
- ,next (pstreamreged) // TODO ??
- ,builder (abuilder)
- ,delta (adelta)
-{
- // GWC TODO ?? Is pstreamreged static so that it holds all streamable
classes?
-// next = pstreamreged; // TODO ??
- pstreamreged = this;
-}
-
-JrPs_pstreamreg * JrPs_pstreamreg::findclass(const char* aname)
-{
- JrPs_pstreamreg * p = pstreamreged;
- for (; p != 0; p = p->next)
- if (std::strcmp(aname, p->name) == 0)
- break;
- return p; // p = 0 if not found, otherwise
- // it points to the JrPs_pstreamreg
-}
-
-JrPs_pstreambuf::JrPs_pstreambuf(int aflags)
- :err (0) // GWC: presumably this is to be initialized to zero
- ,flags (aflags)
-{
- flags = aflags;
-}
-
-JrPs_pstreambuf::~JrPs_pstreambuf()
-{
- if (flags & JrPs_pstream::xxclose)
- close();
-}
-
-void JrPs_pstreambuf::close()
-{
-}
-
-int JrPs_pstreambuf::error()
-{
- return err;
-}
-
-void JrPs_pstreambuf::error(int aerror)
-{
- err = aerror;
-}
-
-} // namespace JOSHUA_ROWE_PERSISTENT_STREAMS
-
Deleted: lmi/trunk/ihs_pios.hpp
===================================================================
--- lmi/trunk/ihs_pios.hpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/ihs_pios.hpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -1,295 +0,0 @@
-// Joshua Rowe's "Really cool persistent object stream library".
-//
-// Copyright (C) 2000, 2005, 2006, 2007, 2008, 2009, 2010 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
-//
-// http://savannah.nongnu.org/projects/lmi
-// email: <address@hidden>
-// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
-
-// $Id$
-
-// This is a derived work based on Joshua Rowe's
-// "Really cool persistent object stream library"
-// which he released this under GNU General Public License version 2.
-//
-// The original, version 0.0.3, was downloaded from:
-// http://metalab.unc.edu/pub/Linux/devel/lang/c++/pstream-0.0.3.tar.gz
-// and was modified as follows:
-//
-// 20000528 Gregory W. Chicares made changes marked inline 'GWC',
-// and released the modified version it under the same version of
-// the same license as the original. Any defect in this modified
-// version should not reflect on Joshua Rowe's reputation.
-//
-// and in any later years given in the copyright notice above as
-// detailed in ChangeLog.
-
-/* pios.hh
- * Written by Joshua Rowe
- * Really cool persistent object stream library
- */
-
-#ifndef ihs_pios_hpp
-#define ihs_pios_hpp
-
-#include "config.hpp"
-
-#include "so_attributes.hpp"
-
-#include <cstddef> // std::size_t
-
-//#ifndef __BORLANDC__
-#if 1
-# include <string>
-//using std::string;
-#elif defined(__BORLANDC__) && __BORLANDC__ < 0x0550
-# include <cstring.h>
- // This BC++5.02 class uses upper case NPOS, but
- // ISO std C++ uses lower case npos .
- #define npos (std::size_t(-1))
- // This would be preferable, but the borland class doesn't
- // have string::size_type :
- // static const size_type npos = static_cast<size_type>(-1);
-#elif defined(__BORLANDC__) && 0x0550 <= __BORLANDC__
-# include </bc5/include/cstring.h>
-#endif
-
-namespace JOSHUA_ROWE_PERSISTENT_STREAMS
-{
-
-// GWC: replaced with void*
-//#ifndef pvoid
-//typedef void * pvoid;
-//#endif
-
-class JrPs_pstream;
-class JrPs_opstream;
-class JrPs_ipstream;
-class JrPs_pstreamed;
-class JrPs_pstreamable;
-class JrPs_pstreamreg;
-class JrPs_pstreambuf;
-
-typedef JrPs_pstreamable * (*BUILDER)();
-
-enum JrPs_pstreamableInit
-{
- JrPs_pstreamableinit
-};
-
-class LMI_SO JrPs_pstream
-{
-protected:
- JrPs_pstreambuf* buf;
- int curid;
- int err;
- int flags;
- JrPs_pstreamed* streamed;
- JrPs_pstream(const JrPs_pstream&);
- JrPs_pstream& operator= (const JrPs_pstream&);
-public:
- enum psFlags {
- xxclose = 0x0001,
- xxread = 0x0002,
- xxwrite = 0x0004,
- xxtrunc = 0x0008,
- xxexcl = 0x0010,
- xxcreat = 0x0020,
- xxappen = 0x0040,
- xxkill = 0x0080
- };
- enum ptTypes {
- ptNULL,
- ptIndex,
- ptObject
- };
- enum peError {
- peNULL,
- peNotRegistered,
- peNoBuffer
- };
- JrPs_pstream(JrPs_pstreambuf *abuf = 0, int aflags = 0);
- virtual ~JrPs_pstream();
- void addstreamed(const JrPs_pstreamable* obj);
- void close();
- void error(int aerror);
- int error();
- int good(); // GWC added: compatibility with BI
- int lookup(const void* q); // Look up an already written object by
- // its pointer.
- const JrPs_pstreamed* lookup(int id); // Look up an already read object
- // by its id number
- int operator !(); // Returns err
-};
-
-class LMI_SO JrPs_opstream : virtual public JrPs_pstream
-{
- JrPs_opstream(const JrPs_opstream&);
- JrPs_opstream& operator= (const JrPs_opstream&);
-protected:
-public:
- JrPs_opstream(JrPs_pstreambuf *abuf = 0, int aflags = 0);
- void writebyte(char c);
- virtual void writebytes(const void* d, int l);
- void writeint(int i);
- void writeobj(const JrPs_pstreamable* obj);
- void writeref(const JrPs_pstreamable* obj); // GWC added: see .cpp file
-
- void writestring(const char* s);
-
-friend JrPs_opstream & operator <<(JrPs_opstream& os, const JrPs_pstreamable&
x);
-friend JrPs_opstream & operator <<(JrPs_opstream& os, const JrPs_pstreamable*
x);
-
- // for POD types
-friend JrPs_opstream& operator<< (JrPs_opstream& os,
bool );
-friend JrPs_opstream& operator<< (JrPs_opstream& os,
char );
-friend JrPs_opstream& operator<< (JrPs_opstream& os, signed
char );
-friend JrPs_opstream& operator<< (JrPs_opstream& os, unsigned
char );
-friend JrPs_opstream& operator<< (JrPs_opstream& os, short
int );
-friend JrPs_opstream& operator<< (JrPs_opstream& os, unsigned short
int );
-friend JrPs_opstream& operator<< (JrPs_opstream& os,
int );
-friend JrPs_opstream& operator<< (JrPs_opstream& os, unsigned
int );
-friend JrPs_opstream& operator<< (JrPs_opstream& os, long
int );
-friend JrPs_opstream& operator<< (JrPs_opstream& os, unsigned long
int );
-friend JrPs_opstream& operator<< (JrPs_opstream& os,
float );
-friend JrPs_opstream& operator<< (JrPs_opstream& os,
double );
-friend JrPs_opstream& operator<< (JrPs_opstream& os, long
double );
-
- // for C strings
-friend JrPs_opstream& operator<< (JrPs_opstream& os,
char const*);
-friend JrPs_opstream& operator<< (JrPs_opstream& os, signed
char const*);
-friend JrPs_opstream& operator<< (JrPs_opstream& os, unsigned
char const*);
-
- // for C++ strings
-friend JrPs_opstream& operator<< (JrPs_opstream& os, std::string const&);
-
-};
-
-class LMI_SO JrPs_ipstream : virtual public JrPs_pstream
-{
- JrPs_ipstream(const JrPs_ipstream&);
- JrPs_ipstream& operator= (const JrPs_ipstream&);
-protected:
-public:
- JrPs_ipstream(JrPs_pstreambuf *abuf = 0, int aflags = 0);
- char readbyte();
- virtual const void* readbytes(void* d, int l);
- int readint();
- void* readobj(JrPs_pstreamreg *d, JrPs_pstreamable *m);
- char* readstring();
-
-friend JrPs_ipstream & operator >>(JrPs_ipstream& is, JrPs_pstreamable &x);
-friend JrPs_ipstream & operator >>(JrPs_ipstream& is, const void* &x);
-
- // for POD types
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is,
bool &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is,
char &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, signed char
&);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, unsigned
char &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, short
int &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, unsigned short
int &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is,
int &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, unsigned
int &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, long
int &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, unsigned long
int &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is,
float &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is,
double &);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, long
double &);
-
- // for C strings
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is,
char*&);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, signed
char*&);
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, unsigned
char*&);
-
- // for C++ strings
-friend JrPs_ipstream& operator>> (JrPs_ipstream& is, std::string&);
-
-};
-
-class JrPs_pstreamed
-{
-friend JrPs_opstream & operator <<(JrPs_opstream& os, const JrPs_pstreamable&
x);
-friend JrPs_opstream & operator <<(JrPs_opstream& os, const JrPs_pstreamable*
x);
-friend JrPs_ipstream & operator >>(JrPs_ipstream& is, JrPs_pstreamable &x);
-friend JrPs_ipstream & operator >>(JrPs_ipstream& is, void* &x);
-friend class JrPs_pstream;
-friend class JrPs_ipstream;
-friend class JrPs_opstream;
- JrPs_pstreamed(const JrPs_pstreamed&);
- JrPs_pstreamed& operator= (const JrPs_pstreamed&);
-protected:
- int id;
- const JrPs_pstreamed* next;
- JrPs_pstreamed(int aid, const JrPs_pstreamed* anext, const void* ap);
-public:
- const void* p;
-};
-
-class JrPs_pstreamable
-{
- friend class JrPs_opstream;
- friend class JrPs_ipstream;
- virtual const char* streamableName() const = 0;
-protected:
- virtual void* read(JrPs_ipstream& is) = 0;
- virtual void write(JrPs_opstream& os) const = 0;
-public:
- JrPs_pstreamable();
- JrPs_pstreamable(JrPs_pstreamableInit);
- virtual ~JrPs_pstreamable();
-};
-
-class JrPs_pstreamreg
-{
- friend class JrPs_opstream;
- friend class JrPs_ipstream;
- JrPs_pstreamreg(const JrPs_pstreamreg&);
- JrPs_pstreamreg& operator= (const JrPs_pstreamreg&);
-protected:
- const char* name;
- JrPs_pstreamreg * next;
- BUILDER builder;
- std::size_t delta;
-public:
- JrPs_pstreamreg(const char* aname, BUILDER abuilder, std::size_t adelta);
- static JrPs_pstreamreg * findclass(const char* aname);
-};
-
-class JrPs_pstreambuf
-{
-friend class JrPs_pstream;
-friend class JrPs_opstream;
-friend class JrPs_ipstream;
-protected:
- int err;
- int flags;
-public:
- JrPs_pstreambuf(int aflags = 0);
- virtual ~JrPs_pstreambuf();
- virtual void close();
- int error();
- void error(int aerror);
- virtual void* read(void* d, int l) = 0;
- virtual void write(const void* d, int l) = 0;
-};
-
-#define JRPS_PSTREAM_DELTA(d) \
-(std::size_t((JOSHUA_ROWE_PERSISTENT_STREAMS::JrPs_pstreamable *)(d *)1) - 1)
-
-} // namespace JOSHUA_ROWE_PERSISTENT_STREAMS
-
-#endif // ihs_pios_hpp
-
Modified: lmi/trunk/main_wx.cpp
===================================================================
--- lmi/trunk/main_wx.cpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/main_wx.cpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -362,9 +362,9 @@
new(wx) wxDocTemplate
(doc_manager_
,"Database"
- ,"*.db4"
+ ,"*.database"
,""
- ,"db4"
+ ,"database"
,"Database document"
,"Database view"
,CLASSINFO(DatabaseDocument)
Modified: lmi/trunk/my_prod.cpp
===================================================================
--- lmi/trunk/my_prod.cpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/my_prod.cpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -61,7 +61,7 @@
// Generic data for the 'sample' product.
- z.DatabaseFilename = glossed_string("sample.db4");
+ z.DatabaseFilename = glossed_string("sample.database");
z.FundFilename = glossed_string("sample.funds");
z.RoundingFilename = glossed_string("sample.rounding");
z.TierFilename = glossed_string("sample.strata");
@@ -107,7 +107,7 @@
// z.save(AddDataDir("sample.policy"));
// Copy the template above for other policy forms, e.g.:
-// z.DatabaseFilename = glossed_string("another.db4");
+// z.DatabaseFilename = glossed_string("another.database");
// ...
}
Modified: lmi/trunk/objects.make
===================================================================
--- lmi/trunk/objects.make 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/objects.make 2010-04-29 19:13:13 UTC (rev 4870)
@@ -276,12 +276,10 @@
ihs_database.o \
ihs_dbdict.o \
ihs_dbvalue.o \
- ihs_fpios.o \
ihs_funddata.o \
ihs_irc7702.o \
ihs_irc7702a.o \
ihs_mortal.o \
- ihs_pios.o \
md5.o \
mec_input.o \
mec_server.o \
@@ -389,10 +387,8 @@
ihs_database.o \
ihs_dbdict.o \
ihs_dbvalue.o \
- ihs_fpios.o \
ihs_funddata.o \
ihs_mortal.o \
- ihs_pios.o \
input.o \
input_harmonization.o \
input_realization.o \
@@ -781,9 +777,7 @@
global_settings.o \
ihs_dbdict.o \
ihs_dbvalue.o \
- ihs_fpios.o \
ihs_funddata.o \
- ihs_pios.o \
mc_enum.o \
mc_enum_types.o \
miscellany.o \
Modified: lmi/trunk/product_data.cpp
===================================================================
--- lmi/trunk/product_data.cpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/product_data.cpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -333,7 +333,7 @@
{
product_data z;
- z.DatabaseFilename = glossed_string("sample.db4");
+ z.DatabaseFilename = glossed_string("sample.database");
z.FundFilename = glossed_string("sample.funds");
z.RoundingFilename = glossed_string("sample.rounding");
z.TierFilename = glossed_string("sample.strata");
Modified: lmi/trunk/test_coding_rules.cpp
===================================================================
--- lmi/trunk/test_coding_rules.cpp 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/test_coding_rules.cpp 2010-04-29 19:13:13 UTC (rev 4870)
@@ -437,12 +437,6 @@
void check_cxx(file const& f)
{
- // Remove this once these hopeless files have been expunged.
- if(f.phyloanalyze("^ihs_f?pios.[ch]pp$"))
- {
- return;
- }
-
// Remove this once these files have been rewritten.
if(f.phyloanalyze("^md5.[ch]pp$"))
{
@@ -594,12 +588,6 @@
void check_label_indentation(file const& f)
{
- // Remove this once these hopeless files have been expunged.
- if(f.phyloanalyze("^ihs_f?pios.hpp$"))
- {
- return;
- }
-
if(!f.is_of_phylum(e_c_or_cxx))
{
return;
Modified: lmi/trunk/workhorse.make
===================================================================
--- lmi/trunk/workhorse.make 2010-04-29 19:10:15 UTC (rev 4869)
+++ lmi/trunk/workhorse.make 2010-04-29 19:13:13 UTC (rev 4870)
@@ -883,7 +883,7 @@
qx_ins.dat \
qx_ins.ndx \
sample.dat \
- sample.db4 \
+ sample.database \
sample.funds \
sample.ndx \
sample.policy \
@@ -977,7 +977,7 @@
fardel_checksummed_files = \
$(extra_fardel_checksummed_files) \
- *.dat *.db4 *.funds *.ndx *.policy *.rounding *.strata \
+ *.dat *.database *.funds *.ndx *.policy *.rounding *.strata \
expiry \
md5sum$(EXEEXT) \
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [4870] Reimplement 'database' (formerly 'db4') product files (VS),
Greg Chicares <=