Use std::string instead of C string in exception handling and yorick I/O
This commit is contained in:
parent
7bd2ccbee4
commit
6d410dc129
@ -1,6 +1,7 @@
|
|||||||
#ifndef __COSMOTOOL_CONFIG_HPP
|
#ifndef __COSMOTOOL_CONFIG_HPP
|
||||||
#define __COSMOTOOL_CONFIG_HPP
|
#define __COSMOTOOL_CONFIG_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -50,14 +51,19 @@ namespace CosmoTool
|
|||||||
class Exception : public std::exception
|
class Exception : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Exception(const char *mess = 0)
|
Exception(const std::string& mess)
|
||||||
: msg(mess) {}
|
: msg(mess), msgok(true) {}
|
||||||
|
Exception()
|
||||||
|
: msgok(false) {}
|
||||||
|
|
||||||
const char *getMessage() const { return msg != 0 ? msg : "No message"; };
|
virtual ~Exception() throw () {}
|
||||||
virtual const char *what() const throw () { return msg != 0 ? msg : "What 'what' ?"; };
|
|
||||||
|
const char *getMessage() const { return msgok ? msg.c_str() : "No message"; };
|
||||||
|
virtual const char *what() const throw () { return msgok ? msg.c_str() : "What 'what' ?"; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *msg;
|
std::string msg;
|
||||||
|
bool msgok;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,8 +73,10 @@ namespace CosmoTool
|
|||||||
class InvalidArgumentException : public Exception
|
class InvalidArgumentException : public Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InvalidArgumentException(const char *mess = 0)
|
InvalidArgumentException(const std::string& mess)
|
||||||
: Exception(mess) {}
|
: Exception(mess) {}
|
||||||
|
InvalidArgumentException()
|
||||||
|
: Exception() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,8 +84,10 @@ namespace CosmoTool
|
|||||||
class InvalidRangeException : public Exception
|
class InvalidRangeException : public Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InvalidRangeException(const char *mess = 0)
|
InvalidRangeException(const std::string& mess)
|
||||||
: Exception(mess) {}
|
: Exception(mess) {}
|
||||||
|
InvalidRangeException()
|
||||||
|
: Exception() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,8 +95,10 @@ namespace CosmoTool
|
|||||||
class NoSuchFileException : public Exception
|
class NoSuchFileException : public Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NoSuchFileException(const char *mess = 0)
|
NoSuchFileException(const std::string& mess)
|
||||||
: Exception(mess) {}
|
: Exception(mess) {}
|
||||||
|
NoSuchFileException()
|
||||||
|
: Exception() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,22 +106,28 @@ namespace CosmoTool
|
|||||||
class InvalidFileFormatException : public Exception
|
class InvalidFileFormatException : public Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InvalidFileFormatException(const char *mess = 0)
|
InvalidFileFormatException(const std::string& mess)
|
||||||
: Exception(mess) {}
|
: Exception(mess) {}
|
||||||
|
InvalidFileFormatException()
|
||||||
|
: Exception() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class EndOfFileException: public Exception
|
class EndOfFileException: public Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EndOfFileException(const char *mess = 0)
|
EndOfFileException(const std::string& mess)
|
||||||
: Exception(mess) {}
|
: Exception(mess) {}
|
||||||
|
EndOfFileException()
|
||||||
|
: Exception() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FilesystemFullException: public Exception
|
class FilesystemFullException: public Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FilesystemFullException(const char *mess = 0)
|
FilesystemFullException(const std::string& mess)
|
||||||
: Exception(mess) {}
|
: Exception(mess) {}
|
||||||
|
FilesystemFullException()
|
||||||
|
: Exception() {}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ using namespace std;
|
|||||||
#define POWER_BDM 7
|
#define POWER_BDM 7
|
||||||
#define POWER_TEST 8
|
#define POWER_TEST 8
|
||||||
|
|
||||||
#define POWER_SPECTRUM POWER_EFSTATHIOU
|
#define POWER_SPECTRUM HU_WIGGLES
|
||||||
|
|
||||||
namespace Cosmology {
|
namespace Cosmology {
|
||||||
|
|
||||||
|
@ -142,10 +142,10 @@ public:
|
|||||||
namespace CosmoTool {
|
namespace CosmoTool {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ProgressiveOutput<T>
|
ProgressiveOutput<T>
|
||||||
ProgressiveOutput<T>::saveArrayProgressive(const char *fname, uint32_t *dimList,
|
ProgressiveOutput<T>::saveArrayProgressive(const std::string& fname, uint32_t *dimList,
|
||||||
uint32_t rank)
|
uint32_t rank)
|
||||||
{
|
{
|
||||||
NcFile *f = new NcFile(fname, NcFile::Replace);
|
NcFile *f = new NcFile(fname.c_str(), NcFile::Replace);
|
||||||
|
|
||||||
assert(f->is_valid());
|
assert(f->is_valid());
|
||||||
|
|
||||||
@ -171,10 +171,10 @@ namespace CosmoTool {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ProgressiveInput<T>
|
ProgressiveInput<T>
|
||||||
ProgressiveInput<T>::loadArrayProgressive(const char *fname, uint32_t *&dimList,
|
ProgressiveInput<T>::loadArrayProgressive(const std::string& fname, uint32_t *&dimList,
|
||||||
uint32_t& rank)
|
uint32_t& rank)
|
||||||
{
|
{
|
||||||
NcFile *f = new NcFile(fname, NcFile::ReadOnly);
|
NcFile *f = new NcFile(fname.c_str(), NcFile::ReadOnly);
|
||||||
|
|
||||||
assert(f->is_valid());
|
assert(f->is_valid());
|
||||||
|
|
||||||
@ -193,10 +193,10 @@ namespace CosmoTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void saveArray(const char *fname,
|
void saveArray(const std::string& fname,
|
||||||
T *array, uint32_t *dimList, uint32_t rank)
|
T *array, uint32_t *dimList, uint32_t rank)
|
||||||
{
|
{
|
||||||
NcFile f(fname, NcFile::Replace);
|
NcFile f(fname.c_str(), NcFile::Replace);
|
||||||
|
|
||||||
assert(f.is_valid());
|
assert(f.is_valid());
|
||||||
|
|
||||||
@ -217,11 +217,11 @@ namespace CosmoTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void loadArray(const char *fname,
|
void loadArray(const std::string& fname,
|
||||||
T*&array, uint32_t *&dimList, uint32_t& rank)
|
T*&array, uint32_t *&dimList, uint32_t& rank)
|
||||||
throw (NoSuchFileException)
|
throw (NoSuchFileException)
|
||||||
{
|
{
|
||||||
NcFile f(fname, NcFile::ReadOnly);
|
NcFile f(fname.c_str(), NcFile::ReadOnly);
|
||||||
|
|
||||||
if (!f.is_valid())
|
if (!f.is_valid())
|
||||||
throw NoSuchFileException(fname);
|
throw NoSuchFileException(fname);
|
||||||
@ -251,18 +251,18 @@ namespace CosmoTool {
|
|||||||
template class ProgressiveOutput<float>;
|
template class ProgressiveOutput<float>;
|
||||||
template class ProgressiveOutput<double>;
|
template class ProgressiveOutput<double>;
|
||||||
|
|
||||||
template void loadArray<int>(const char *fname,
|
template void loadArray<int>(const std::string& fname,
|
||||||
int*& array, uint32_t *&dimList, uint32_t& rank);
|
int*& array, uint32_t *&dimList, uint32_t& rank);
|
||||||
template void loadArray<float>(const char *fname,
|
template void loadArray<float>(const std::string& fname,
|
||||||
float*& array, uint32_t *&dimList, uint32_t& rank);
|
float*& array, uint32_t *&dimList, uint32_t& rank);
|
||||||
template void loadArray<double>(const char *fname,
|
template void loadArray<double>(const std::string& fname,
|
||||||
double*& array, uint32_t *&dimList, uint32_t& rank);
|
double*& array, uint32_t *&dimList, uint32_t& rank);
|
||||||
|
|
||||||
template void saveArray<int>(const char *fname,
|
template void saveArray<int>(const std::string& fname,
|
||||||
int *array, uint32_t *dimList, uint32_t rank);
|
int *array, uint32_t *dimList, uint32_t rank);
|
||||||
template void saveArray<float>(const char *fname,
|
template void saveArray<float>(const std::string& fname,
|
||||||
float *array, uint32_t *dimList, uint32_t rank);
|
float *array, uint32_t *dimList, uint32_t rank);
|
||||||
template void saveArray<double>(const char *fname,
|
template void saveArray<double>(const std::string& fname,
|
||||||
double *array, uint32_t *dimList, uint32_t rank);
|
double *array, uint32_t *dimList, uint32_t rank);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
namespace CosmoTool
|
namespace CosmoTool
|
||||||
@ -77,8 +78,8 @@ namespace CosmoTool
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static ProgressiveInput<T>
|
static ProgressiveInput<T>
|
||||||
loadArrayProgressive(const char *fname, uint32_t *&dimList,
|
loadArrayProgressive(const std::string& fname, uint32_t *&dimList,
|
||||||
uint32_t& rank);
|
uint32_t& rank);
|
||||||
|
|
||||||
ProgressiveInput() {
|
ProgressiveInput() {
|
||||||
impl = 0;
|
impl = 0;
|
||||||
@ -143,8 +144,8 @@ namespace CosmoTool
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static ProgressiveOutput<T>
|
static ProgressiveOutput<T>
|
||||||
saveArrayProgressive(const char *fname, uint32_t *dimList,
|
saveArrayProgressive(const std::string& fname, uint32_t *dimList,
|
||||||
uint32_t rank);
|
uint32_t rank);
|
||||||
|
|
||||||
ProgressiveOutput() {
|
ProgressiveOutput() {
|
||||||
impl = 0;
|
impl = 0;
|
||||||
@ -181,11 +182,11 @@ namespace CosmoTool
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void saveArray(const char *fname,
|
void saveArray(const std::string& fname,
|
||||||
T *array, uint32_t *dimList, uint32_t rank);
|
T *array, uint32_t *dimList, uint32_t rank);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void loadArray(const char *fname,
|
void loadArray(const std::string& fname,
|
||||||
T*& array, uint32_t *& dimList, uint32_t& rank)
|
T*& array, uint32_t *& dimList, uint32_t& rank)
|
||||||
throw (NoSuchFileException);
|
throw (NoSuchFileException);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user