Added: Overloaded getAttribute function returning a char.

Removed obsolete function printSyncronized.
This commit is contained in:
Knut Morten Okstad 2016-12-01 17:50:39 +01:00
parent e7601f9e3c
commit 4a5bafaa45
2 changed files with 21 additions and 27 deletions

View File

@ -17,10 +17,6 @@
#include <cstdlib>
#include <algorithm>
#ifdef HAVE_MPI
#include <mpi.h>
#endif
void utl::parseIntegers (std::vector<int>& values, const char* argv)
{
@ -155,6 +151,18 @@ bool utl::getAttribute (const TiXmlElement* xml, const char* att, int& val)
}
bool utl::getAttribute (const TiXmlElement* xml, const char* att, char& val,
bool useIntValue)
{
if (xml && xml->Attribute(att))
val = useIntValue ? atoi(xml->Attribute(att)) : xml->Attribute(att)[0];
else
return false;
return true;
}
bool utl::getAttribute (const TiXmlElement* xml, const char* att, size_t& val)
{
if (xml && xml->Attribute(att))
@ -356,18 +364,6 @@ size_t utl::find_closest (const std::vector<Real>& a, Real v)
}
void utl::printSyncronized (std::ostream& out, const std::stringstream& str,
int pid)
{
out << std::flush;
#ifdef HAVE_MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
if (pid == 0)
out << str.str();
}
std::string utl::adjustRight (size_t width, const std::string& s,
const std::string& suffix)
{

View File

@ -16,7 +16,6 @@
#include "matrix.h"
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <map>
@ -70,6 +69,15 @@ namespace utl
//! \return \e true if the attribute \a att is found in \a xml,
//! otherwise \e false
bool getAttribute(const TiXmlElement* xml, const char* att, int& val);
//! \brief Extracts a char attribute value from the specified XML-element.
//! \param[in] xml Pointer to XML-element to extract from
//! \param[in] att The attribute tag
//! \param[out] val The attribute value
//! \param[in] useIntValue If \e true, convert the value to an integer
//! \return \e true if the attribute \a att is found in \a xml,
//! otherwise \e false
bool getAttribute(const TiXmlElement* xml, const char* att, char& val,
bool useIntValue = true);
//! \brief Extracts a size_t attribute value from the specified XML-element.
//! \param[in] xml Pointer to XML-element to extract from
//! \param[in] att The attribute tag
@ -179,16 +187,6 @@ namespace utl
//! input. If this is not the case the method will deliver incorrect result.
size_t find_closest(const std::vector<Real>& a, Real v);
//! \brief Prints a string stream to an output stream.
//! \param out The output stream to print to
//! \param[in] str The string stream to print
//! \param[in] pid The PID of this process (only process 0 will print)
//!
//! \details This method makes sure to flush the output stream
//! across all processes up front.
void printSyncronized(std::ostream& out,
const std::stringstream& str, int pid);
//! \brief Right-justifies the input string to the given total \a width.
std::string adjustRight(size_t width, const std::string& s,
const std::string& suffix = " : ");