Page MenuHomec4science

iohelper_common.hh
No OneTemporary

File Metadata

Created
Tue, Jun 11, 15:12

iohelper_common.hh

/*
Copyright 2008 Guillaume ANCIAUX (guillaume.anciaux@epfl.ch)
This file is part of ParaViewHelper.
ParaViewHelper is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ParaViewHelper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ParaViewHelper. If not, see <http://www.gnu.org/licenses/>.
*/
/* -------------------------------------------------------------------------- */
#ifndef __IOHELPER_COMMON_H__
#define __IOHELPER_COMMON_H__
/* -------------------------------------------------------------------------- */
#define USING_ZLIB
#include <iostream>
#include <string>
#include <sstream>
#define __BEGIN_IOHELPER__ namespace iohelper {
#define __END_IOHELPER__ }
#include <string.h>
#include <stdlib.h>
/* -------------------------------------------------------------------------- */
__BEGIN_IOHELPER__
typedef unsigned int UInt;
typedef int Int;
typedef double Real;
/* -------------------------------------------------------------------------- */
enum IndexingMode{
C_MODE = 0,
FORTRAN_MODE = 1
};
/* -------------------------------------------------------------------------- */
enum ElemType{
TRIANGLE1 ,
TRIANGLE2 ,
TETRA1 ,
TETRA2 ,
POINT_SET ,
LINE1 ,
LINE2 ,
QUAD1 ,
QUAD2 ,
HEX1 ,
BEAM2 ,
MAX_ELEM_TYPE
};
/* -------------------------------------------------------------------------- */
enum FileStorageMode{
TEXT = 0,
BASE64 = 1,
COMPRESSED = 2
};
/* -------------------------------------------------------------------------- */
static UInt paraview_code_type[MAX_ELEM_TYPE] __attribute__((unused)) = {
5, // TRIANGLE1
22, // TRIANGLE2
10, // TETRA1
24, // TETRA2
2, // POINT_SET
3, // LINE1
21, // LINE2
9, // QUAD1
23, // QUAD2
12, // HEX1
3 // BEAM2
};
/* -------------------------------------------------------------------------- */
static UInt nb_node_per_elem[MAX_ELEM_TYPE] __attribute__((unused)) = {
3, // TRIANGLE1
6, // TRIANGLE2
4, // TETRA1
10, // TETRA2
1, // POINT_SET
2, // LINE1
3, // LINE2
4, // QUAD1
8, // QUAD2
8, // HEX1
2 // BEAM2
};
/* -------------------------------------------------------------------------- */
static UInt nb_quad_points[MAX_ELEM_TYPE] __attribute__((unused)) = {
1, // TRIANGLE1
3, // TRIANGLE2
1, // TETRA1
4, // TETRA2
0, // POINT_SET
1, // LINE1
2, // LINE2
4, // QUAD1
9, // QUAD2
1, // HEX1
2 // BEAM2
};
/* -------------------------------------------------------------------------- */
template <typename T>
class IOHelperVector {
public:
inline IOHelperVector(T * ptr, UInt size){
this->ptr = ptr;
this->_size = size;
};
inline UInt size() const {return _size;};
inline const T & operator[] (UInt i) const {
return ptr[i];
};
inline const T * getPtr() const {
return ptr;
};
private:
T* ptr;
UInt _size;
};
/* -------------------------------------------------------------------------- */
/* Iterator interface */
/* -------------------------------------------------------------------------- */
template< typename T, class daughter, class ret_cont = IOHelperVector<T> > class iterator {
public:
virtual bool operator!=(const daughter & it) const = 0;
virtual daughter & operator++() = 0;
virtual ret_cont operator*() = 0;
};
/* -------------------------------------------------------------------------- */
class IOHelperException : public std::exception {
public:
enum ErrorType {
_et_non_homogeneous_data,
_et_unknown_visitor_stage,
_et_file_error,
_et_missing_field
};
public:
IOHelperException(const std::string & message, const ErrorType & type) throw() {
this->message = message;
this->type = type;
};
~IOHelperException() throw(){};
virtual const char* what() const throw(){
return message.c_str();
};
private:
std::string message;
ErrorType type;
};
/* -------------------------------------------------------------------------- */
#define IOHELPER_THROW(x,type) { \
std::stringstream sstr; \
sstr << __FILE__ << ":" << __LINE__ << ":" \
<< __PRETTY_FUNCTION__ << ": " << x; \
throw ::iohelper::IOHelperException(sstr.str(), ::iohelper::IOHelperException::type); \
}
/* -------------------------------------------------------------------------- */
__END_IOHELPER__
#endif /* __IOHELPER_COMMON_H__ */

Event Timeline