// $Id$
// Version: $Name$
//
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by the deal.II authors
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
//TODO[WB]: various functions here could be simplified by using namespace Utilities
namespace Patterns
-{
+{
PatternBase::~PatternBase ()
{}
else
return sizeof(*this) + 32;
}
-
+
const int Integer::min_int_value =
#else
1;
#endif
-
+
const int Integer::max_int_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
std::numeric_limits<int>::max();
#else
0;
#endif
-
+
Integer::Integer (const int lower_bound,
const int upper_bound)
bool Integer::match (const std::string &test_string) const
{
std::istringstream str(test_string);
-
+
int i;
if (str >> i)
{
else
return true;
};
-
+
return false;
}
// output their values
if (lower_bound <= upper_bound)
{
- std::ostringstream description;
-
+ std::ostringstream description;
+
description << "[Integer range "
<< lower_bound << "..." << upper_bound
<< " (inclusive)]";
#else
1;
#endif
-
+
const double Double::max_double_value =
#ifdef HAVE_STD_NUMERIC_LIMITS
std::numeric_limits<double>::max();
#else
0;
#endif
-
+
Double::Double (const double lower_bound,
const double upper_bound)
:
// output their values
if (lower_bound <= upper_bound)
{
- std::ostringstream description;
+ std::ostringstream description;
description << "[Floating point range "
<< lower_bound << "..." << upper_bound
std::vector<std::string> choices;
std::string tmp(sequence);
// check the different possibilities
- while (tmp.find('|') != std::string::npos)
+ while (tmp.find('|') != std::string::npos)
{
if (test_string == std::string(tmp, 0, tmp.find('|')))
return true;
-
+
tmp.erase (0, tmp.find('|')+1);
};
// check last choice, not finished by |
return (sizeof(PatternBase) +
MemoryConsumption::memory_consumption(sequence));
}
-
+
const unsigned int List::max_int_value =
}
else
tmp = "";
-
+
while ((name.length() != 0) &&
(std::isspace (name[0])))
name.erase (0,1);
// check the different possibilities
for (std::vector<std::string>::const_iterator
test_string = split_list.begin();
- test_string != split_list.end(); ++test_string)
+ test_string != split_list.end(); ++test_string)
if (pattern->match (*test_string) == false)
return false;
std::string List::description () const
{
- std::ostringstream description;
-
- description << "list of <" << pattern->description() << ">"
+ std::ostringstream description;
+
+ description << "list of <" << pattern->description() << ">"
<< " of length " << min_elements << "..." << max_elements
<< " (inclusive)";
MemoryConsumption::memory_consumption(*pattern));
}
-
-
+
+
MultipleSelection::MultipleSelection (const std::string &seq)
{
Assert (seq.find (",") == std::string::npos, ExcCommasNotAllowed(seq.find(",")));
-
+
sequence = seq;
while (sequence.find(" |") != std::string::npos)
sequence.replace (sequence.find(" |"), 2, "|");
{
std::string name;
name = tmp;
-
+
if (name.find(",") != std::string::npos)
{
name.erase (name.find(","), std::string::npos);
}
else
tmp = "";
-
+
while ((name.length() != 0) &&
(std::isspace (name[0])))
name.erase (0,1);
// check the different possibilities
for (std::list<std::string>::const_iterator test_string = split_list.begin();
- test_string != split_list.end(); ++test_string)
+ test_string != split_list.end(); ++test_string)
{
bool string_found = false;
-
+
tmp = sequence;
- while (tmp.find('|') != std::string::npos)
+ while (tmp.find('|') != std::string::npos)
{
if (*test_string == std::string(tmp, 0, tmp.find('|')))
{
string_found = true;
break;
};
-
+
tmp.erase (0, tmp.find('|')+1);
};
// check last choice, not finished by |
{
return new Anything();
}
-
+
} // end namespace Patterns
std::string line;
int lineno=0;
bool status = true;
-
- while (input)
+
+ while (input)
{
++lineno;
getline (input, line);
- if (!scan_line (line, lineno))
+ if (!scan_line (line, lineno))
status = false;
}
bool write_compact)
{
PathSearch search("PARAMETERS");
-
+
try
{
std::string openname = search.find(filename);
// if empty std::string then exit
// with success
if ((s == 0) || ((*s) == 0)) return true;
-
+
std::string line;
std::string input (s);
int lineno=0;
input += '\n';
bool status = true;
- while (input.size() != 0)
+ while (input.size() != 0)
{
// get one line from Input (=s)
line.assign (input, 0, input.find('\n'));
// the backspace
input.erase (0, input.find('\n')+1);
++lineno;
-
- if (!scan_line (line, lineno))
+
+ if (!scan_line (line, lineno))
status = false;
};
for (p=defaults.subsections.begin(); p!=defaults.subsections.end(); ++p)
delete p->second;
-
+
for (p=changed_entries.subsections.begin(); p!=changed_entries.subsections.end(); ++p)
if (p->second)
{
// memory leak
if (p->entries.find (entry) != p->entries.end())
delete p->entries[entry].pattern;
-
+
// if the entry didn't yet exist,
// but map::operator[] will create
// it
Section* pd = get_present_defaults_subsection ();
// does subsection already exist?
- if (pd->subsections.find (subsection) == pd->subsections.end())
+ if (pd->subsections.find (subsection) == pd->subsections.end())
{
// subsection does not yet exist:
// create entry in Defaults and
// whether there is a subsection to be left!)
Assert (subsection_path.size() != 0, ExcAlreadyAtTopLevel());
- if (subsection_path.size() == 0)
+ if (subsection_path.size() == 0)
return false;
subsection_path.pop_back ();
// already declared in the defaults tree
Assert (pd->entries.find (entry_string) != pd->entries.end(),
ExcEntryUndeclared(entry_string));
-
- if (pd->entries.find (entry_string) == pd->entries.end())
+
+ if (pd->entries.find (entry_string) == pd->entries.end())
{
static const std::string empty_string;
return empty_string;
// already declared in the defaults tree
Assert (pd->entries.find (entry_string) != pd->entries.end(),
ExcEntryUndeclared(entry_string));
-
+
// entry exists; now set it (if the entry
// in pc hasn't existed yet, create it and
// set the pattern to the null pointer
set (entry_string, std::string(new_value));
}
-
+
void
ParameterHandler::set (const std::string &entry_string,
const double &new_value)
const OutputStyle style)
{
AssertThrow (out, ExcIO());
-
- switch (style)
+
+ switch (style)
{
case Text:
out << "# Listing of Parameters" << std::endl
default:
Assert (false, ExcNotImplemented());
};
-
+
// dive recursively into the subsections
print_parameters_section (out, style, 0);
- switch (style)
+ switch (style)
{
case Text:
case Description:
default:
Assert (false, ExcNotImplemented());
};
-
+
return out;
}
// traverse entry list
Section::EntryType::const_iterator ptr;
- switch (style)
+ switch (style)
{
case Text:
case ShortText:
// default and documentation
// strings
unsigned int longest_value = 0;
- for (ptr = pd->entries.begin(); ptr != pd->entries.end(); ++ptr)
+ for (ptr = pd->entries.begin(); ptr != pd->entries.end(); ++ptr)
longest_value
= std::max (static_cast<size_t> (longest_value),
(pc->entries.find(ptr->first) != pc->entries.end()
pc->entries[ptr->first].value
:
pd->entries[ptr->first].value).length());
-
+
// print entries one by one
- for (ptr = pd->entries.begin(); ptr != pd->entries.end(); ++ptr)
+ for (ptr = pd->entries.begin(); ptr != pd->entries.end(); ++ptr)
{
// see whether the
// value is listed in
{
if (ptr != pd->entries.begin())
out << std::endl;
-
+
const std::vector<std::string> doc_lines
= Utilities::
break_text_into_lines (pd->entries[ptr->first].documentation,
78 - indent_level*2 - 2);
-
+
for (unsigned int i=0; i<doc_lines.size(); ++i)
out << std::setw(indent_level*2) << ""
<< "# "
<< doc_lines[i]
<< std::endl;
}
-
-
-
+
+
+
// print name and value
// of this entry
out << std::setw(indent_level*2) << ""
<< "# ";
out << "default: " << pd->entries[ptr->first].value;
}
-
+
out << std::endl;
}
-
+
break;
}
-
+
case LaTeX:
{
// print entries one by one
}
break;
}
-
+
case Description:
{
// first find out the longest
for (ptr = pd->entries.begin(); ptr != pd->entries.end(); ++ptr)
if (ptr->first.length() > longest_name)
longest_name = ptr->first.length();
-
+
// print entries one by one
for (ptr = pd->entries.begin(); ptr != pd->entries.end(); ++ptr)
{
const std::vector<std::string> description_str
= Utilities::break_text_into_lines (pd->entries[ptr->first].pattern->description(),
78 - indent_level*2 - 2, '|');
- if (description_str.size() > 1)
+ if (description_str.size() > 1)
{
out << std::endl;
for (unsigned int i=0; i<description_str.size(); ++i)
}
break;
}
-
+
default:
Assert (false, ExcNotImplemented());
}
if (ptrss->second->accumulated_no_of_entries() != 0)
{
// first print the subsection header
- switch (style)
+ switch (style)
{
case Text:
case Description:
enter_subsection (ptrss->first);
print_parameters_section (out, style, indent_level+1);
leave_subsection ();
- switch (style)
+ switch (style)
{
case Text:
// write end of
out << std::setw(indent_level*2) << ""
<< "end" << std::endl
<< std::endl;
-
+
// if this is a toplevel
// subsection, then have two
// newlines
if (indent_level == 0)
out << std::endl;
-
+
break;
case Description:
break;
std::string SecName = line;
Section* pc = get_present_changed_subsection ();
// check whether subsection exists
- if (pc->subsections.find(SecName) == pc->subsections.end())
+ if (pc->subsections.find(SecName) == pc->subsections.end())
{
std::cerr << "Line " << lineno
<< ": There is no such subsection to be entered:" << std::endl;
subsection_path.push_back (SecName);
return true;
};
-
+
// exit subsection
if ((line.find ("END") == 0) ||
(line.find ("end") == 0))
{
- if (subsection_path.size() == 0)
+ if (subsection_path.size() == 0)
{
std::cerr << "Line " << lineno
<< ": There is no subsection to leave here!" << std::endl;
else
return leave_subsection ();
}
-
+
// regular entry
if ((line.find ("SET ") == 0) ||
- (line.find ("set ") == 0))
+ (line.find ("set ") == 0))
{
// erase "set" statement and eliminate
// spaces around the '='
Section* pd = get_present_defaults_subsection ();
// check whether entry was declared
- if (pd->entries.find(entry_name) == pd->entries.end())
+ if (pd->entries.find(entry_name) == pd->entries.end())
{
std::cerr << "Line " << lineno
<< ": No such entry was declared:" << std::endl
<< std::endl;
return false;
};
-
+
Section* pc = get_present_changed_subsection ();
// the following lines declare
// this entry if not yet
{
Section* sec = &defaults;
std::vector<std::string>::const_iterator SecName = subsection_path.begin();
-
- while (SecName != subsection_path.end())
+
+ while (SecName != subsection_path.end())
{
sec = sec->subsections[*SecName];
++SecName;
Section* sec = const_cast<Section*>(&defaults); // not nice, but needs to be and
// after all: we do not change @p{sec}
std::vector<std::string>::const_iterator SecName = subsection_path.begin();
-
- while (SecName != subsection_path.end())
+
+ while (SecName != subsection_path.end())
{
sec = sec->subsections[*SecName];
++SecName;
{
Section* sec = &changed_entries;
std::vector<std::string>::iterator SecName = subsection_path.begin();
-
- while (SecName != subsection_path.end())
+
+ while (SecName != subsection_path.end())
{
sec = sec->subsections[*SecName];
++SecName;
{
Section* sec = const_cast<Section*>(&changed_entries); // same as in get_present_default_s...
std::vector<std::string>::const_iterator SecName = subsection_path.begin();
-
- while (SecName != subsection_path.end())
+
+ while (SecName != subsection_path.end())
{
sec = sec->subsections[*SecName];
++SecName;
-unsigned int
+unsigned int
ParameterHandler::memory_consumption () const
{
return (MemoryConsumption::memory_consumption (subsection_path) +
-ParameterHandler::Section::~Section ()
+ParameterHandler::Section::~Section ()
{
// first release the memory pointed
// to by the second component of
-unsigned int
+unsigned int
ParameterHandler::Section::memory_consumption () const
{
unsigned int mem = 0;
void MultipleParameterLoop::loop (MultipleParameterLoop::UserClass &uc)
{
- for (unsigned int run_no=0; run_no<n_branches; ++run_no)
+ for (unsigned int run_no=0; run_no<n_branches; ++run_no)
{
// give create_new one-based numbers
uc.create_new (run_no+1);
void MultipleParameterLoop::init_branches ()
{
multiple_choices.clear ();
-
+
ParameterHandler::Section *sec;
// first check the defaults entries whether it
// contains multiple choices
// split up different values
for (unsigned int i=0; i<multiple_choices.size(); ++i)
multiple_choices[i].split_different_values ();
-
+
// check whether we have included a
// multiple choice entry from the defaults
// section which has only one single value
// check for the conformance with the regexp
// (afterwards, this will be lost in the whole
// other output)
- for (unsigned int i=0; i<n_branches; ++i)
+ for (unsigned int i=0; i<n_branches; ++i)
fill_entry_values (i);
}
// check all entries in the present subsection
// whether it is a multiple entry
Section::EntryType::const_iterator e;
- for (e = sec.entries.begin(); e != sec.entries.end(); ++e)
- if (e->second.value.find('{') != std::string::npos)
+ for (e = sec.entries.begin(); e != sec.entries.end(); ++e)
+ if (e->second.value.find('{') != std::string::npos)
multiple_choices.push_back (Entry(subsection_path,
e->first,
e->second.value));
// transverse subsections
std::map<std::string, Section*>::const_iterator s;
- for (s = sec.subsections.begin(); s != sec.subsections.end(); ++s)
+ for (s = sec.subsections.begin(); s != sec.subsections.end(); ++s)
{
enter_subsection (s->first);
init_branches_section (*s->second);
void MultipleParameterLoop::fill_entry_values (const unsigned int run_no)
{
int possibilities = 1;
-
+
std::vector<Entry>::iterator choice;
for (choice = multiple_choices.begin();
choice != multiple_choices.end();
- ++choice)
+ ++choice)
{
// temporarily enter the subsection tree
// of this multiple entry
std::string entry_value;
if (choice->type == Entry::variant)
entry_value = choice->different_values[selection];
- else
+ else
{
- if (run_no>=choice->different_values.size())
+ if (run_no>=choice->different_values.size())
{
std::cerr << "The given array for entry <"
<< choice->entry_name
else
entry_value = choice->different_values[run_no];
};
-
+
// check conformance with regex
if (!pd->entries[choice->entry_name].pattern->match(entry_value))
{
<< " " << pd->entries[choice->entry_name].pattern->description() << std::endl
<< " Taking default value" << std::endl
<< " " << pd->entries[choice->entry_name].value << std::endl;
-
+
// select default instead
entry_value = pd->entries[choice->entry_name].value;
};
// in the defaults section)
pc->entries[choice->entry_name].value = entry_value;
pc->entries[choice->entry_name].pattern = 0;
-
+
// get out of subsection again
subsection_path.swap (choice->subsection_path);
if (choice->type == Entry::variant)
possibilities *= choice->different_values.size();
};
-
+
}
-unsigned int
+unsigned int
MultipleParameterLoop::memory_consumption () const
{
unsigned int mem = ParameterHandler::memory_consumption ();
for (unsigned int i=0; i<multiple_choices.size(); ++i)
mem += multiple_choices[i].memory_consumption ();
-
+
return mem;
}
const std::string &Name,
const std::string &Value)
:
- subsection_path (ssp), entry_name(Name), entry_value(Value)
+ subsection_path (ssp), entry_name(Name), entry_value(Value), type (Entry::array)
{}
// in multiple
while (std::isspace (multiple[0])) multiple.erase (0,1);
while (std::isspace (multiple[multiple.size()-1])) multiple.erase (multiple.size()-1,1);
-
+
// delete spaces around '|'
while (multiple.find(" |") != std::string::npos)
multiple.replace (multiple.find(" |"), 2, "|");
while (multiple.find("| ") != std::string::npos)
multiple.replace (multiple.find("| "), 2, "|");
- while (multiple.find('|') != std::string::npos)
+ while (multiple.find('|') != std::string::npos)
{
different_values.push_back (prefix +
std::string(multiple, 0, multiple.find('|'))+
}
-unsigned int
+unsigned int
MultipleParameterLoop::Entry::memory_consumption () const
{
return (MemoryConsumption::memory_consumption (subsection_path) +