Commit bf5105f5 authored by Lynn Garren's avatar Lynn Garren
Browse files

This commit was generated by cvs2svn to compensate for changes in r2,

which included commits to RCS files with non-trunk default branches.
parent 39fc4c4c
// -*- C++ -*-
// $Id: Evaluator.h,v 1.1.1.1 2003/07/15 20:15:05 garren Exp $
// ---------------------------------------------------------------------------
#ifndef HEP_EVALUATOR_H
#define HEP_EVALUATOR_H
namespace HepTool {
/**
* Evaluator of arithmetic expressions with an extendable dictionary.
* Example:
* @code
* #include "CLHEP/Evaluator/Evaluator.h"
* HepTool::Evaluator eval;
* eval.setStdMath();
* double res = eval.evaluate("sin(30*degree)");
* if (eval.status() != HepTool::Evaluator::OK) eval.print_error();
* @endcode
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup evaluator
*/
class Evaluator {
public:
/**
* List of possible statuses.
* Status of the last operation can be obtained with status().
* In case if status() is an ERROR the corresponding error message
* can be printed with print_error().
*
* @see status
* @see error_position
* @see print_error
*/
enum {
OK, /**< Everything OK */
WARNING_EXISTING_VARIABLE, /**< Redefinition of existing variable */
WARNING_EXISTING_FUNCTION, /**< Redefinition of existing function */
WARNING_BLANK_STRING, /**< Empty input string */
ERROR_NOT_A_NAME, /**< Not allowed sysmbol in the name of variable or function */
ERROR_SYNTAX_ERROR, /**< Systax error */
ERROR_UNPAIRED_PARENTHESIS, /**< Unpaired parenthesis */
ERROR_UNEXPECTED_SYMBOL, /**< Unexpected sysbol */
ERROR_UNKNOWN_VARIABLE, /**< Non-existing variable */
ERROR_UNKNOWN_FUNCTION, /**< Non-existing function */
ERROR_EMPTY_PARAMETER, /**< Function call has empty parameter */
ERROR_CALCULATION_ERROR /**< Error during calculation */
};
/**
* Constructor.
*/
Evaluator();
/**
* Destructor.
*/
~Evaluator();
/**
* Evaluates the arithmetic expression given as character string.
* The expression may consist of numbers, variables and functions
* separated by arithmetic (+, - , /, *, ^, **) and logical
* operators (==, !=, >, >=, <, <=, &&, ||).
*
* @param expression input expression.
* @return result of the evaluation.
* @see status
* @see error_position
* @see print_error
*/
double evaluate(const char * expression);
/**
* Returns status of the last operation with the evaluator.
*/
int status() const;
/**
* Returns position in the input string where the problem occured.
*/
int error_position() const;
/**
* Prints error message if status() is an ERROR.
*/
void print_error() const;
/**
* Adds to the dictionary a variable with given value.
* If a variable with such a name already exist in the dictionary,
* then status will be set to WARNING_EXISTING_VARIABLE.
*
* @param name name of the variable.
* @param value value assigned to the variable.
*/
void setVariable(const char * name, double value);
/**
* Adds to the dictionary a variable with an arithmetic expression
* assigned to it.
* If a variable with such a name already exist in the dictionary,
* then status will be set to WARNING_EXISTING_VARIABLE.
*
* @param name name of the variable.
* @param expression arithmetic expression.
*/
void setVariable(const char * name, const char * expression);
/**
* Adds to the dictionary a function without parameters.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name, double (*fun)());
/**
* Adds to the dictionary a function with one parameter.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name, double (*fun)(double));
/**
* Adds to the dictionary a function with two parameters.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name, double (*fun)(double,double));
/**
* Adds to the dictionary a function with three parameters.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name, double (*fun)(double,double,double));
/**
* Adds to the dictionary a function with four parameters.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name,
double (*fun)(double,double,double,double));
/**
* Adds to the dictionary a function with five parameters.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name,
double (*fun)(double,double,double,double,double));
/**
* Finds the variable in the dictionary.
*
* @param name name of the variable.
* @return true if such a variable exists, false otherwise.
*/
bool findVariable(const char * name) const;
/**
* Finds the function in the dictionary.
*
* @param name name of the function to be unset.
* @param npar number of parameters of the function.
* @return true if such a function exists, false otherwise.
*/
bool findFunction(const char * name, int npar) const;
/**
* Removes the variable from the dictionary.
*
* @param name name of the variable.
*/
void removeVariable(const char * name);
/**
* Removes the function from the dictionary.
*
* @param name name of the function to be unset.
* @param npar number of parameters of the function.
*/
void removeFunction(const char * name, int npar);
/**
* Clear all settings.
*/
void clear();
/**
* Sets standard mathematical functions and constants.
*/
void setStdMath();
/**
* Sets system of units. Default is the SI system of units.
* To set the CGS (Centimeter-Gram-Second) system of units
* one should call:
* setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0);
*
* To set system of units accepted in the GEANT4 simulation toolkit
* one should call:
* @code
* setSystemOfUnits(1.e+3, 1./1.60217733e-25, 1.e+9, 1./1.60217733e-10,
* 1.0, 1.0, 1.0);
* @endcode
*
* The basic units in GEANT4 are:
* @code
* millimeter (millimeter = 1.)
* nanosecond (nanosecond = 1.)
* Mega electron Volt (MeV = 1.)
* positron charge (eplus = 1.)
* degree Kelvin (kelvin = 1.)
* the amount of substance (mole = 1.)
* luminous intensity (candela = 1.)
* radian (radian = 1.)
* steradian (steradian = 1.)
* @endcode
*/
void setSystemOfUnits(double meter = 1.0,
double kilogram = 1.0,
double second = 1.0,
double ampere = 1.0,
double kelvin = 1.0,
double mole = 1.0,
double candela = 1.0);
private:
void * p; // private data
Evaluator(const Evaluator &); // copy constructor is not allowed
Evaluator & operator=(const Evaluator &); // assignment is not allowed
};
} // namespace HepTool
#endif /* HEP_EVALUATOR_H */
## Process this file with automake to produce Makefile.in
pkginclude_HEADERS = \
Evaluator.h \
defs.h
#-------------------------------------------------------------
# installing from a source code tar ball
#-------------------------------------------------------------
Unwind the source code tar ball in some relevant directory.
Autoconf and automake will aready have been run.
Determine where the files will be installed.
Create a build directory that is NOT in the source code directory tree.
cd <build_directory>
<source_code_direcotry>/configure --prefix=<install_dir>
(Note that files will be installed under /usr/local if you do not
specify a prefix.)
make
(Build temporary copies of libraries and executables.)
make check
(Run the tests.)
make install
(Copy libraries, headers, executables, etc. to relevant
subdirectories under <install_dir>.)
#-------------------------------------------------------------
# building from cvs
#-------------------------------------------------------------
You will need current versions of automake, autoconf, and libtool.
See building autotools below.
cvs co CLHEP/package OR cvs co package
cd [CLHEP/]package
bootstrap
Now continue with directions as if you unpacked a source code tarball.
#-------------------------------------------------------------
# building autotools
#-------------------------------------------------------------
If you do not have at least autoconf 2.57 and automake 1.6, you will
need to build autoconf, automake, and libtool. On some platforms,
you may also need to build m4 and texinfo.
Download the relevant tarballs from gnu.org.
Untar them in a common source code tree.
Decide whether you want to install them in /usr/local or your own
install directory. If you use your own install directory, use
--prefix=<install_dir>
with configure.
For each autotool package:
<source_code_dir>/configure [--prefix=<install_dir>]
make
make install
Make sure that <install_dir>/bin is at the front of your path.
#-------------------------------------------------------------
## Process this file with automake to produce Makefile.in
includedir = $(prefix)/include/CLHEP
# put . first so that CLHEP directory is built before anything else
SUBDIRS = . Evaluator src
all-local: $(top_builddir)/CLHEP
$(top_builddir)/CLHEP:
$(top_srcdir)/makeCLHEPdir $(top_srcdir)/..
config.sub
config.guess
depcomp
install-sh
missing
mkinstalldirs
This diff is collapsed.
#! /bin/sh
# run autotool commands
set -x
aclocal -I autotools
autoheader
automake --add-missing --copy
autoconf
# ready to make a source code distribution tarball
#!/bin/sh
# use this in the build directory, NOT in the source code tree
usage()
{
cat <<EOF
Usage: buildLibraries <CLHEP source code directory> <build directory> <install directory>
All three directories must be specified and must be unique.
Use the full path for all directory names.
For example: buildLibraries /fullpath/CLHEP /fullpath/build /fullpath/inst
EOF
exit $1
}
if test $# -lt 3; then
usage 1
fi
if [ ! -d $1 ]
then
echo "source directory $1 does not exist"
exit 2
fi
if [ ! -d $2 ]
then
echo "build directory $2 does not exist"
exit 3
fi
if [ ! -d $3 ]
then
echo "install directory $3 does not exist"
exit 4
fi
# create subdirectory in build area for each package
if [ ! -d $2/Evaluator ]
then
mkdir $2/Evaluator
fi
cd $2/Evaluator
# create temporary include subdirectory
if [ ! -d CLHEP ]
then
mkdir CLHEP
for pkg in `ls $1`
do
if [ -d $1/$pkg/$pkg ]
then
ln -s $1/$pkg/$pkg CLHEP/$pkg
fi
done
fi
$1/Evaluator/configure --prefix=$3 --includedir=$3/include/CLHEP > log.configure.$$ 2>&1
make > log.make.$$ 2>&1
if [ -d test ]
then
make check > log.check.$$ 2>&1
fi
make install > log.install.$$ 2>&1
exit 0
# ======================================================================
# This is the Evaluator configuration input file
# Process this file with autoconf to produce a configure script.
# ======================================================================
# ----------------------------------------------------------------------
# Identify the package and initialize the autotools:
# ----------------------------------------------------------------------
AC_PREREQ(2.57)
AC_INIT(CLHEP Evaluator, toy1.9.0.0, CLHEP@cern.ch, Evaluator)
AC_CONFIG_AUX_DIR(autotools)
AC_CONFIG_SRCDIR([src/Evaluator.cc])
AM_INIT_AUTOMAKE(1.6 foreign)
AC_PROG_LIBTOOL
# ----------------------------------------------------------------------
# Identify the files that 'configure' is to produce:
# ----------------------------------------------------------------------
# Header containing #defines:
AM_CONFIG_HEADER([Evaluator/defs.h])
# Makefiles:
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([Evaluator/Makefile])
AC_CONFIG_FILES([src/Makefile])
# ----------------------------------------------------------------------
# Capture post-install information:
# ----------------------------------------------------------------------
Evaluator_CPPFLAGS="-I$includedir"
Evaluator_LDFLAGS="-L$libdir"
Evaluator_LIBS="-l$PACKAGE_TARNAME -lm"
AC_SUBST(Evaluator_CPPFLAGS)
AC_SUBST(Evaluator_LIBS)
AC_SUBST(Evaluator_LDFLAGS)
# ----------------------------------------------------------------------
# Supply boilerplate for Evaluator/defs.h source header:
# ----------------------------------------------------------------------
AH_TOP([#ifndef EVALUATOR_DEFS_H
#define EVALUATOR_DEFS_H])
AH_BOTTOM([#endif // EVALUATOR_DEFS_H])
# ----------------------------------------------------------------------
# Account for any user configuration options:
# ----------------------------------------------------------------------
# Determine whether optional thread support is requested:
AC_ARG_ENABLE(
threads,
[ --enable-threads Turn on thread support],
[case "${enableval}" in
yes) threads=true ;;
no) threads=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-threads) ;;
esac],
[threads=false]
)
AM_CONDITIONAL(USE_THREADS, test x$threads = xtrue)
# ----------------------------------------------------------------------
# Check for needed programs:
# ----------------------------------------------------------------------
# Locate a C++ compiler:
AC_PROG_CXX(aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC g++ c++ gpp)
# Use it hereinafter:
AC_LANG(C++)
# Ensure we've found a preprocessor:
AC_REQUIRE_CPP
# ----------------------------------------------------------------------
# Set system-dependent options:
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# Check for needed libraries:
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# Check for needed header files:
# ----------------------------------------------------------------------
AC_HEADER_STDC
AC_CHECK_HEADERS([string.h])
# ----------------------------------------------------------------------
# Check for needed typedefs, structures, and compiler characteristics:
# ----------------------------------------------------------------------
AC_CHECK_DECL(M_PI,
[],
AC_DEFINE(M_PI, 3.14159265358979323846, [Value of pi]),
[#include <cmath>])
AC_CHECK_DECL(M_PI_2,
[],
AC_DEFINE(M_PI_2, 1.57079632679489661923, [Value of pi/2]),
[#include <cmath>])
AC_CHECK_DECL(M_2PI,
[],
AC_DEFINE(M_2PI, 6.28318530717958647692, [Value of 2*pi]),
[#include <cmath>])
# ----------------------------------------------------------------------
# Check for needed library functions:
# ----------------------------------------------------------------------
AC_FUNC_STRTOD
AC_CHECK_FUNCS([pow sqrt])
# ----------------------------------------------------------------------
# Finish up:
# ----------------------------------------------------------------------
AC_OUTPUT
# ======================================================================
#!/bin/sh
# create a temporary CLHEP include subdirectory
# use this in the build directory, NOT in the source code tree
# makeCLHEP <top of source>
# $1 is the CLHEP (or equivalent) source code direcotry
# e.g. for /fullpath/somedir/Vector, $1 is /fullpath/somedir
# create temporary include subdirectory
if [ ! -d CLHEP ]
then
mkdir CLHEP
for pkg in `ls $1`
do
if [ -d $1/$pkg/$pkg ]
then
ln -s $1/$pkg/$pkg CLHEP/$pkg
fi
done
fi
This diff is collapsed.
## Process this file with automake to produce Makefile.in
INCLUDES = -I$(top_builddir)
lib_LTLIBRARIES = libEvaluator-@VERSION@.la
libEvaluator_@VERSION@_la_SOURCES = \
Evaluator.cc \
setStdMath.cc \
setSystemOfUnits.cc
// -*- C++ -*-
// $Id: hash_map.src,v 1.1.1.1 2003/07/15 20:15:05 garren Exp $
// ---------------------------------------------------------------------------
#ifdef DEBUG_MODE
#include <iostream>
#endif
#ifndef HEP_HASH_MAP_SRC
#define HEP_HASH_MAP_SRC
#include <string.h>
#include <utility>
#include "string.src"
/*
* Simplified hash_map class.
* It provides only basic functions of the standard <hash_map> and
* is intended to be used as a replacement of the standard class where
* full functionality of <hash_map> is not required, but it is essential
* to have highly portable and effective code.
*
* This file should be used exclusively inside *.cc files.
* Usage inside header files can result to a clash with standard <hash_map>.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
*/
template<class K, class T>