Commit e1374064 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

new code

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1790
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 357942ae
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.17 2005-06-30 13:55:12 tforb Exp $
# $Id: Makefile,v 1.18 2005-07-01 07:40:40 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -29,7 +29,8 @@
#HEADERS=$(shell find . -name \*.h)
HEADERS=misc/range.h misc/xcmdline.h misc/error.h misc/commandline.h \
misc/complexio.h misc/misc.h misc/fortranio.h \
containers/handle.h
containers/handle.h strings/stringfunc.h misc/rangelist.h \
strings/rangestring.h
#misc/blitzfortranio.h
#misc/blitzutil.h
#hacks/hack_blitztogrepg.h
......@@ -37,9 +38,10 @@ HEADERS=misc/range.h misc/xcmdline.h misc/error.h misc/commandline.h \
#SRC=misc/fortranio.cc misc/commandline.cc misc/ioswap.cc misc/error.cc \
# misc/blitzfortranio.cc hacks/hack_blitztogrepg.cc
SRC=misc/fortranio.cc misc/commandline.cc misc/ioswap.cc misc/error.cc \
misc/xcmdline.cc
misc/xcmdline.cc strings/stringfunc.cc
#TESTS=$(filter-out tests/blitztest,$(wildcard tests/*.cc))
TESTS=tests/commandlinetest.cc tests/fortraniotest.cc
TESTS=tests/commandlinetest.cc tests/fortraniotest.cc \
tests/stringtest.cc
#tests/blitztest.cc
FTESTS=$(wildcard tests/*.f)
README=$(shell find . -name README) README.xtra
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: range.h,v 1.1 2002-11-27 14:58:56 forbrig Exp $
* $Id: range.h,v 1.2 2005-07-01 07:40:41 tforb Exp $
* \author Thomas Forbriger
* \date 09/06/2002
*
......@@ -24,7 +24,7 @@
#define TFXX_RANGE_H_VERSION \
"TFXX_RANGE_H V1.0 "
#define TFXX_RANGE_H_CVSID \
"$Id: range.h,v 1.1 2002-11-27 14:58:56 forbrig Exp $"
"$Id: range.h,v 1.2 2005-07-01 07:40:41 tforb Exp $"
namespace tfxx {
......@@ -59,6 +59,9 @@ template<class T=int>
//! does this range contain the other
bool contains(const Range& other) const
{ return ((Mfirst <= other.first()) && (Mlast >= other.last())); }
//! does this range contain then value v
bool contains(const Tvalue& v) const
{ return ((Mfirst <= v) && (Mlast >= v)); }
//! shrink to smaller of this and the other
Range& shrink(const Range& other)
{
......
/*! \file rangelist.h
* \brief handle a list of ranges (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: rangelist.h,v 1.1 2005-07-01 07:40:41 tforb Exp $
* \author Thomas Forbriger
* \date 30/06/2005
*
* handle a list of ranges (prototypes)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 30/06/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_RANGELIST_H_VERSION
#define TF_RANGELIST_H_VERSION \
"TF_RANGELIST_H V1.0 "
#define TF_RANGELIST_H_CVSID \
"$Id: rangelist.h,v 1.1 2005-07-01 07:40:41 tforb Exp $"
#include<tfxx/range.h>
#include<list>
namespace tfxx {
template<class T>
class RangeList {
public:
typedef T Tvalue;
typedef tfxx::Range<Tvalue> Trange;
typedef std::list<Trange> Tlist;
RangeList() { }
RangeList& append(const Trange& r)
{ Mlist.push_back(r); return *this; }
void clear()
{ Mlist.erase(Mlist.begin(), Mlist.end()); }
typename Tlist::size_type size() const { return Mlist.size(); }
bool contains(const Tvalue& v)
{
bool retval=false;
typename Tlist::const_iterator i=Mlist.begin();
while ((i!=Mist.end()) && (!retval))
{ retval = i->contains(v); ++i; }
return retval;
}
Tlist list() const { return Mlist; }
private:
Tlist Mlist;
}; // template class RangeList
}
#endif // TF_RANGELIST_H_VERSION (includeguard)
/* ----- END OF rangelist.h ----- */
This is a legacy version of the repository. It may be incomplete as well as
inconsistent. See README.history for details. For the old stock of the
repository copyright and licence conditions apply as specified for versions
commited after 2015-03-01. Use recent versions as a base for new development.
The legacy version is only stored to keep a record of history.
/*! \file rangestring.h
* \brief read ranges from strings (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: rangestring.h,v 1.1 2005-07-01 07:40:41 tforb Exp $
* \author Thomas Forbriger
* \date 30/06/2005
*
* read ranges from strings (prototypes)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 30/06/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_RANGESTRING_H_VERSION
#define TF_RANGESTRING_H_VERSION \
"TF_RANGESTRING_H V1.0 "
#define TF_RANGESTRING_H_CVSID \
"$Id: rangestring.h,v 1.1 2005-07-01 07:40:41 tforb Exp $"
#include<tfxx/range.h>
#include<tfxx/rangelist.h>
#include<tfxx/stringfunc.h>
#include<list>
#include<sstream>
namespace tfxx {
namespace string {
/* read range from string */
template<class T>
tfxx::Range<T> range(const std::string& s)
{
typedef tfxx::Range<T> Trange;
typename Trange::Tvalue v1, v2;
typedef std::list<std::string> Tslist;
Tslist slist=split<std::list>(s, "-", true);
Tslist::const_iterator i=slist.begin();
std::istringstream iss(*i);
iss >> v1;
if (slist.size()>1)
{ ++i; iss.str(*i); iss >> v2; }
else
{ v2=v1; }
Trange retval(v1,v2);
return retval;
}
/* read rangelist from string */
template<class T>
tfxx::RangeList<T> rangelist(const std::string& s)
{
typedef tfxx::RangeList<T> Tlist;
Tlist retval;
typedef std::list<std::string> Tslist;
Tslist slist=split<std::list>(s, ",", true);
Tslist::const_iterator i=slist.begin();
while (i!=slist.end())
{ retval.append(range<typename Tlist::Tvalue>(*i)); ++i; }
return retval;
}
} // namespace string
} // namespace tfxx
#endif // TF_RANGESTRING_H_VERSION (includeguard)
/* ----- END OF rangestring.h ----- */
/*! \file stringfunc.cc
* \brief string functions copied from former class library (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: stringfunc.cc,v 1.1 2005-07-01 07:40:42 tforb Exp $
* \author Thomas Forbriger
* \date 30/06/2005
*
* string functions copied from former class library (implementation)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 30/06/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_STRINGFUNC_CC_VERSION \
"TF_STRINGFUNC_CC V1.0 "
#define TF_STRINGFUNC_CC_CVSID \
"$Id: stringfunc.cc,v 1.1 2005-07-01 07:40:42 tforb Exp $"
#include <tfxx/stringfunc.h>
#include<algorithm>
#include<iterator>
#include<functional>
#include<ctype.h>
namespace tfxx {
namespace string {
// remove leading whitespace
std::string trimws_begin(std::string s)
{
s.erase(s.begin(), find_if(s.begin(), s.end(),
not1(std::ptr_fun(isspace))));
return(s);
}
// remove trailing whitespace
// This is not as straight forward as trimws_begin as I did not manage to
// get string::erase compiled with reverse iteraters. On the other hand
// the only appropriate method to start a search at the end of the string
// is to use a reverse iterator. Doing reverse twice IS ugly as it means
// copying the string twice. Maybe I'll write some better code some
// time...
std::string trimws_end(std::string s)
{
reverse(s.begin(), s.end());
s.erase(s.begin(), find_if(s.begin(), s.end(),
not1(std::ptr_fun(isspace))));
reverse(s.begin(), s.end());
return(s);
}
/*! strip substring
*
* \param c character to find in string
* \param delim delimiter to look for
* \return number of c characters in string
*/
std::string strip_string(std::string& s, const char& delim)
{
std::string::size_type i=s.find(delim);
std::string result;
if ((i>=0) && (i<s.size())) {
result=s.substr(0,i);
s.erase(0,i+1);
} else {
result=s;
s.erase();
}
return(result);
}
/*! count characters in string
*
* \param s string to look for c
* \param c character to find in string
* \return number of c characters in string
*/
int count_char(const std::string& s, const char& c)
{
int result=0;
for (std::string::const_iterator i=s.begin(); i!=s.end(); i++)
{ if (*i == c) { result++; } }
return(result);
}
} // namespace string
} // namespace tfxx
/* ----- END OF stringfunc.cc ----- */
/*! \file stringfunc.h
* \brief string functions copied from former class library (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: stringfunc.h,v 1.1 2005-07-01 07:40:42 tforb Exp $
* \author Thomas Forbriger
* \date 30/06/2005
*
* string functions copied from former class library (prototypes)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 30/06/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_STRINGFUNC_H_VERSION
#define TF_STRINGFUNC_H_VERSION \
"TF_STRINGFUNC_H V1.0 "
#define TF_STRINGFUNC_H_CVSID \
"$Id: stringfunc.h,v 1.1 2005-07-01 07:40:42 tforb Exp $"
#include<string>
namespace tfxx {
namespace string {
/*! template #tf::join#:
*
* The following takes any Container of string elements and joins all
* strings into one single string.
*
* This is the inverse operation to #tf::split#.
*
* \return concatenated string
* \param v any sequence container containing strings
* \param delimiter a string sequence that will put in between
* the individual strings when concatenating them
*
* \author Thomas Forbriger
* \version V1.0 (#$Revision: 1.1 $ $Date: 2005-07-01 07:40:42 $#)
* \memo template to join strings in any sequence container
* \see split
* \see gen_split
*/
template<template<class> class C>
std::string join(const C<std::string>& v,
const std::string& delimiter="")
{
std::string retval;
for (typename C<std::string>::const_iterator i=v.begin();
i!=v.end(); i++)
{ retval.append(*i); retval.append(delimiter); }
return(retval);
}
/*! template #tf:gen_split#:
*
* The following takes a string and splits it into substrings delimited
* by #delimiter#. The resulting substrings will be written into a
* container of strings.
*
* Neither the template mechanism nor the linker mechanism linker is
* able to deduce the correct function definition from the return value.
* Hence we have to use the container class template parameter in the
* functions formal parameter list.
*
* This is the inverse operation to #tf::join#.
*
* \param v sequence container that will receive the
* substrings
* \param s string to be split into substrings
* \param delimiter string sequence that intersects substrings
* \param dropdelimiter if #true# the delimiter itself will be
* excluded from the output
*
* \author Thomas Forbriger
* \version V1.0 (#$Revision: 1.1 $ $Date: 2005-07-01 07:40:42 $#)
* \memo split string into substrings
* \see join
* \see split
*/
template<template<class> class C>
void gen_split(C<std::string>& v, const std::string& s,
const std::string& delimiter=" ",
bool dropdelimiter=false)
{
v.clear();
if (!s.empty()) {
std::string::size_type posend=0, pos=0;
std::string::size_type len=0;
while (posend!=std::string::npos) {
posend=s.find(delimiter, pos);
len=posend-pos;
if (dropdelimiter){
v.push_back(s.substr(pos, len));
if (posend!=std::string::npos) { len+=delimiter.length(); }
} else {
if (posend!=std::string::npos) { len+=delimiter.length(); }
v.push_back(s.substr(pos, len));
}
pos+=len;
}
}
}
/*! template #tf::split#
*
* Use the following interface to the gen_split function by explicitely
* passing a template type argument like:
*
* #list<string> l;#
* #string s="a,b,c,d,e";#
* #l=split<list>(s);#
*
* This is the inverse operation to #tf::join#.
*
* \return seqeunce container containing substrings
* \param s string to be split into substrings
* \param delimiter string sequence that intersects substrings
* \param dropdelimiter if #true# the delimiter itself will be
* excluded from the output
*
* \author Thomas Forbriger
* \version V1.0 (#$Revision: 1.1 $ $Date: 2005-07-01 07:40:42 $#)
* \see join
* \see gen_split
* \memo adapter to gen_split
*/
template<template<class> class C>
C<std::string> split(const std::string& s,
const std::string& delimiter=" ",
bool dropdelimiter=false)
{
C<std::string> v;
gen_split(v, s, delimiter, dropdelimiter);
return(v);
}
/*! function #tf::trimws_begin#:
* Erase leading whitespace from a string.
*
* \return string with leading whitespace removed
* \param s string to remove leading whitespace from
* \author Thomas Forbriger
* \version V1.0 (#$Revision: 1.1 $ $Date: 2005-07-01 07:40:42 $#)
* \memo remove leading whitespace
* \see trimws_end
* \see trimws
*/
std::string trimws_begin(std::string s);
/*! function #tf::trimws_end#:
* Erase trailing whitespace from a string.
*
* \return string with trailing whitespace removed
* \param s string to remove trailing whitespace from
* \author Thomas Forbriger
* \version V1.0 (#$Revision: 1.1 $ $Date: 2005-07-01 07:40:42 $#)
* \memo remove trailing whitespace
* \see trimws_begin
* \see trimws
*/
std::string trimws_end(std::string s);
/*! function #tf::trimws#:
* Erase leading and trailing whitespace from a string.
* This in fact is an inline adapter to #trimws_begin# and #trimws_end#.
*
* \return string with leading and trailing whitespace removed
* \param s string to remove leading and trailing whitespace from
* \author Thomas Forbriger
* \version V1.0 (#$Revision: 1.1 $ $Date: 2005-07-01 07:40:42 $#)
* \memo remove leading and trailing whitespace
* \see trimws_begin
* \see trimws_end
*/
inline std::string trimws(const std::string& s)
{ return(trimws_end(trimws_begin(s))); }
/*! strip substring
*
* \param c character to find in string
* \param delim delimiter to look for
* \return number of c characters in string
*/
std::string strip_string(std::string& s, const char& delim=',');
/*! count characters in string
*
* \param s string to look for c (substring is stripped from this)
* \param c character to find in string
* \return number of c characters in string
*/
int count_char(const std::string& s, const char& c);
} // namespace string
} // namesapce tfxx
#endif // TF_STRINGFUNC_H_VERSION (includeguard)
/* ----- END OF stringfunc.h ----- */
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.8 2005-06-28 10:51:13 tforb Exp $
# $Id: Makefile,v 1.9 2005-07-01 07:40:42 tforb Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -46,7 +46,7 @@ clean: ;
# all that only need templates from the library
STANDARDTEST=
# all that need the binary library
BINARYTEST=commandlinetest fortraniotest blitztest
BINARYTEST=commandlinetest fortraniotest blitztest stringtest
# F77 part of the I/O test
FORTRANTEST=fortranF77
......
/*! \file stringtest.cc
* \brief test string functions
*
* ----------------------------------------------------------------------------
*
* $Id: stringtest.cc,v 1.1 2005-07-01 07:40:42 tforb Exp $
* \author Thomas Forbriger
* \date 30/06/2005
*
* test string functions
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 30/06/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define STRINGTEST_VERSION \
"STRINGTEST V1.0 test string functions"
#define STRINGTEST_CVSID \
"$Id: stringtest.cc,v 1.1 2005-07-01 07:40:42 tforb Exp $"
#include <iostream>
#include <tfxx/commandline.h>
#include <tfxx/rangestring.h>
using std::cout;
using std::cerr;
using std::endl;
/*----------------------------------------------------------------------*/
struct Options {
bool rangetest;
std::string rangestring;
}; // struct Options
/*======================================================================*/
template<class T>
std::ostream& operator<< (std::ostream& os, const tfxx::Range<T>& r)
{
os << r.first() << " - " << r.last();
return os;
}
/*======================================================================*/
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
STRINGTEST_VERSION "\n"
"usage: stringtest [-r r]" "\n"
" or: stringtest --help|-h" "\n"
};
// define full help text
char help_text[]=
{
STRINGTEST_CVSID
"-r r read ranges from \'r\'" "\n"
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: test range reading
{"r",arg_yes,"-"},
{NULL}
};
// no arguments? print usage...
if (iargc<2)
{
cerr << usage_text << endl;
exit(0);
}
// collect options from commandline