From 3b4afe8aebb8ed5b56c4f2e0e4d6cfb787c2d297 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Sat, 22 Aug 1998 16:00:19 +0000 Subject: [PATCH] Neue Klassen LogStream und JobIdentifier git-svn-id: https://svn.dealii.org/trunk@503 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/Attic/doc/Makefile | 27 ++++ deal.II/base/Make_dep.pl | 141 ++++++++++++++++++++ deal.II/base/Makefile | 24 ++++ deal.II/base/include/base/job_identifier.h | 30 +++++ deal.II/base/include/base/logstream.h | 144 +++++++++++++++++++++ deal.II/base/source/Makefile | 68 ++++++++++ deal.II/base/source/job_identifier.cc | 20 +++ deal.II/base/source/log.cc | 20 +++ deal.II/base/source/programid.cc | 9 ++ 9 files changed, 483 insertions(+) create mode 100644 deal.II/base/Attic/doc/Makefile create mode 100644 deal.II/base/Make_dep.pl create mode 100644 deal.II/base/Makefile create mode 100644 deal.II/base/include/base/job_identifier.h create mode 100644 deal.II/base/include/base/logstream.h create mode 100644 deal.II/base/source/Makefile create mode 100644 deal.II/base/source/job_identifier.cc create mode 100644 deal.II/base/source/log.cc create mode 100644 deal.II/base/source/programid.cc diff --git a/deal.II/base/Attic/doc/Makefile b/deal.II/base/Attic/doc/Makefile new file mode 100644 index 0000000000..0dda783976 --- /dev/null +++ b/deal.II/base/Attic/doc/Makefile @@ -0,0 +1,27 @@ +# $Id$ + + +KDOCFLAGS = -I../../../deal.II/doc/kdoc ../../../deal.II/doc/kdoc/kdoc -a -p +kdoc.inc = $(wildcard ../include/base/*.h) + + + +doc-html: kdoc cvslog + + +# make kdoc doc; make sure that the *.kdoc files exist by +# using the dependancies and the following rules. +kdoc: $(kdoc.inc) + cd doc.kdoc ; perl $(KDOCFLAGS) -ubase -dbase \ + base $(kdoc.inc:..%=../..%) + +cvslog: + @cd .. ; ../deal.II/doc/cvslog/cvs2html -o doc/cvslog/base #-a -k + +clean: + rm -f doc.kdoc/base/* \ + cvslog/* \ + *~ + + +.PHONY: doc-html kdoc cvslog clean diff --git a/deal.II/base/Make_dep.pl b/deal.II/base/Make_dep.pl new file mode 100644 index 0000000000..3a4f8b343a --- /dev/null +++ b/deal.II/base/Make_dep.pl @@ -0,0 +1,141 @@ +#Make a dependency file tree +#usage: make_dep library_base_name -Iinc_path1 -Iinc_path2 ... files + +#This program makes for each of the given files a makefile dependency +#list, also considering nested includes. It only considers included +#files which are located in the given include pathes (you can give any +#number of pathes). The output looks like this: +# +#lib_base_name.a(.o-file): file included_files +# +#secondly, a similar entry is created for the .g.a library with the +#.go-file. + +#Author: Wolfgang Bangerth, March 1998 + + +# list of include pathes (from command line) +@include_path = (); +# list of files to be checked (from command line) +@input_files = (); +# associate list of files together with the files they include +%include_files = (); + + +$library_base_name = shift; + + +# fill include pathes +while ($ARGV[0] =~ /^-I/) { + $_ = shift; + /^-I(.*)/; + $_ = $1; + if (m![^/]$!) { + @include_path = (@include_path, $_ . "/"); + } else { + @include_path = (@include_path, $_); + } +} + +#fill list of files to be processed +while ($ARGV[0]) { + @input_files = (@input_files, shift); +} + + +foreach $file (@input_files) { + make_include_tree ($file); +}; + + +foreach $file (keys %include_files) { + # complete list of included files by nested include files + foreach $include (split(' ',$include_files{$file})) { + complete ($file, $include); + } +} + +# print dependency list +foreach $file (@input_files) { + $file =~ /(.*)\.(cc)/; + + print "$library_base_name.a($1.o):"; + print "\\\n $file"; + foreach $f (split (' ', $include_files{$file})) { + print "\\\n $f"; + } + print "\n"; + + print "$library_base_name.g.a($1.go):"; + print "\\\n $file"; + foreach $f (split (' ', $include_files{$file})) { + print "\\\n $f"; + } + print "\n"; +} + + + + + + + + +# complete the list of included files by the files +# included by a file included by the original one +sub complete { + local ($file, $include) = ($_[0], $_[1]); + foreach $second_include (split(' ',$include_files{$include})) { + if (! ($include_files{$file} =~ $second_include)) { + #second_include not yet in list of included files + $include_files{$file} = + join(' ', $second_include, $include_files{$file}); + complete ($file, $second_include); + } + } +} + + + + +# make the include tree for a file +sub make_include_tree { + local ($filename) = $_[0]; + + open (FILE, $filename); + while () { + # look out for include statements + if (/^#\s*include\s*(["<])([^">]*)[">]/) { + local($include) = $2; + if ($1 =~ /. Try to find real path + for $include_dir (@include_path) { + $if = $include_dir . $include; + if (-r $if) { + # file found; delete ./ at beginning + if ($if =~ m!^\./(.*)!) { + $if = $1; + } + $include_files{$filename} = + join (' ', $if, $include_files{$filename}); + } + } + } else { + # included by "..." + # only append file if it exists + if (-r $if) { + $include_files{$filename} = + join (' ', $include, $include_files{$filename}); + } + } + } + } + + # for each file included here: make up include tree itself + for $if (split(/ /,$include_files{$filename})) { + # if include file list not yet made up + if (! defined ($include_files{$if})) { + make_include_tree($if); + } + } +} diff --git a/deal.II/base/Makefile b/deal.II/base/Makefile new file mode 100644 index 0000000000..dcfb589eee --- /dev/null +++ b/deal.II/base/Makefile @@ -0,0 +1,24 @@ +# $Id$ + + +all: lac doc + +clean: doc-clean source-clean + rm -f *~ include/*~ include/*/*~ lib/lib* + +lac: + cd source ; make + +doc: + cd doc ; make + + +doc-clean: + cd doc ; make clean + +source-clean: + cd source ; make clean + + +.PHONY: all deal.II doc +.PHONY: clean doc-clean source-clean diff --git a/deal.II/base/include/base/job_identifier.h b/deal.II/base/include/base/job_identifier.h new file mode 100644 index 0000000000..9322595409 --- /dev/null +++ b/deal.II/base/include/base/job_identifier.h @@ -0,0 +1,30 @@ +// $Id$ + +#ifndef __jobidentifier_H +#define __jobidentifier_H + +#include +#include + +/** Identification of a program run. #JobIdentifier# determines the + start time of a program run and stores it as a program + identifier. There exists a library object #dealjobid# of this + class. This object can be accessed by all output functions to + provide an id for the current job. +*/ + +class JobIdentifier +{ +public: + JobIdentifier(); + ~JobIdentifier(); + + static const char* program_id(); + const string operator () ()const; +private: + string id; +}; + +extern JobIdentifier dealjobid; + +#endif diff --git a/deal.II/base/include/base/logstream.h b/deal.II/base/include/base/logstream.h new file mode 100644 index 0000000000..fb7f9502a5 --- /dev/null +++ b/deal.II/base/include/base/logstream.h @@ -0,0 +1,144 @@ +// $Id$ + +#ifndef __logstream_H +#define __logstream_H + +#include +#include +#include + +/** + A class that simplifies the process of execution logging by + providing +
  • a push and pop mechanism for prefixes and +
  • the possibility of distributing information to files and the +console. +
+*/ +class LogStream +{ +public: + stack prefixes; + ostream& std; + ostream* file; + + bool was_endl; + unsigned std_depth, fil_depth; + +public: + /** Standard constructor, since we + intend to provide an object + clog in the library. + */ + LogStream(); + /** Enable output to a second + stream. + */ + void attach(ostream& o); + /** Disable output to the second + stream. + */ + void detach() + { + file = 0; + } + /** Push another prefix on the + stack. Prefixes are + automatically separated by a + colon and there is a double + colon after the last prefix. + */ + void push(const string& text) + { + string pre=prefixes.top(); + pre += text; + pre += string(":"); + prefixes.push(pre); + } + /** Remove the last prefix. + */ + void pop() + { + prefixes.pop(); + } + /** Maximum number of levels to be + printed on the console. This + function allows to restrict + console output to the upmost + levels of iterations. Only + output with less than #n# + prefixes is printed. By calling + this function with #n=0#, no + console output will be written. + */ + void depth_console(unsigned n) + { + std_depth = n; + } + /** Maximum number of levels to be + written to the log file. The + functionality is the same as + #depth_console#, nevertheless, + this function should be used + with care, since it may spoile + the value of a log file. + */ + void depth_file(unsigned n) + { + fil_depth = n; + } +}; + +template +inline void +writestuff(LogStream& s, const T& t) +{ +// if (s.prefixes.size()<=s.std_depth) + s.std << t; +// if (s.file && (s.prefixes.size()<=s.fil_depth)) + *(s.file) << t; +} + +template +inline LogStream& +operator << (LogStream& s, const T& t) +{ + if (s.was_endl) + { + writestuff(s, s.prefixes.top()); + writestuff(s,':'); + } + s.was_endl = false; + writestuff(s,t); + return s; +} + +//template <> +inline LogStream& +operator << (LogStream& s, const char* c) +{ + if (s.was_endl) + { + writestuff(s, s.prefixes.top()); + writestuff(s,':'); + } + s.was_endl = false; + writestuff(s, c); + return s; +} + +inline void endl(LogStream& s) +{ + writestuff(s,"\n"); + s.was_endl = true; +} + +//template <> +inline LogStream& +operator << (LogStream& s, void (*f)(LogStream&)) +{ + f(s); + return s; +} + +#endif diff --git a/deal.II/base/source/Makefile b/deal.II/base/source/Makefile new file mode 100644 index 0000000000..7000f51cea --- /dev/null +++ b/deal.II/base/source/Makefile @@ -0,0 +1,68 @@ +# $Id$ + +CXX = c++ +INCLUDE = -I../include -I../../base/include +CXXFLAGS.g= -DDEBUG -g -Wall -W -pedantic -Wconversion \ + -Winline -Woverloaded-virtual -fno-rtti \ + $(INCLUDE) +CXXFLAGS =-O3 -Wuninitialized -finline-functions -ffast-math \ + -funroll-loops -felide-constructors -fnonnull-objects \ + -fno-rtti $(INCLUDE) + +ifeq ($(shell uname),Linux) +CXX = /home/wolf/bin/gcc/bin/c++ +endif + +ifeq ($(shell uname),SunOS) +//CXX = /usr/local/gcc/egcs-19980803/bin/c++ +CXX = g++ +endif + + +cc-files = $(wildcard *.cc) +o-files = $(cc-files:.cc=.o) +go-files = $(cc-files:.cc=.go) +h-files = $(wildcard ../include/*/*.h) + + +%.go : %.cc Makefile + @echo ============================ Compiling with debugging information: $< + @echo $(CXX) ... -c $< -o $@ + @$(CXX) $(CXXFLAGS.g) -c $< -o $@ +%.o : %.cc Makefile + @echo ============================ Compiling with optimization: $< + @echo $(CXX) ... -c $< -o $@ + @$(CXX) $(CXXFLAGS) -c $< -o $@ + + +lib: lib.g.a lib.a + + +lib.a: ../lib/libbase.a($(o-files)) + +lib.g.a: ../lib/libbase.g.a($(go-files)) + +clean: + rm -f *.o *.go *~ Makefile.dep ../lib/lib* + + + +.PHONY: lib lib.a lib.g.a clean + + +#Rule to generate the dependency file. This file is +#automagically remade whenever needed, i.e. whenever +#one of the cc-/h-files changed. Make detects whether +#to remake this file upon inclusion at the bottom +#of this file. +# +#use perl to generate rules for the .go files as well +#as to make rules not for tria.o and the like, but +#rather for libbasic.a(tria.o) +Makefile.dep: $(cc-files) $(h-files) + @echo ============================ Remaking Makefile + @perl ../Make_dep.pl ../lib/libbase $(INCLUDE) $(cc-files) \ + > Makefile.dep + + +include Makefile.dep diff --git a/deal.II/base/source/job_identifier.cc b/deal.II/base/source/job_identifier.cc new file mode 100644 index 0000000000..72264338e0 --- /dev/null +++ b/deal.II/base/source/job_identifier.cc @@ -0,0 +1,20 @@ +// $Id$ + +#include + +JobIdentifier dealjobid; + +JobIdentifier::JobIdentifier() +{ + time_t t = time(0); + id = string(program_id()) + string(ctime(&t)); +} + +JobIdentifier::~JobIdentifier() +{} + +const string +JobIdentifier::operator ()() const +{ + return id; +} diff --git a/deal.II/base/source/log.cc b/deal.II/base/source/log.cc new file mode 100644 index 0000000000..ec904aac4b --- /dev/null +++ b/deal.II/base/source/log.cc @@ -0,0 +1,20 @@ +// $Id$ + +#include +#include + +LogStream deallog; + +LogStream::LogStream() + : std(cerr), file(0), was_endl(true), + std_depth(10000), fil_depth(10000) +{ + prefixes.push("DEAL:"); +} + +void +LogStream::attach(ostream& o) +{ + file = &o; + o << "DEAL:" << dealjobid(); +} diff --git a/deal.II/base/source/programid.cc b/deal.II/base/source/programid.cc new file mode 100644 index 0000000000..9ded9fe055 --- /dev/null +++ b/deal.II/base/source/programid.cc @@ -0,0 +1,9 @@ +// $Id$ + +#include + +const char* +JobIdentifier::program_id() +{ + return "JobId "; +} -- 2.39.5