aslABDFormat.h
Go to the documentation of this file.
/*
* Advanced Simulation Library <http://asl.org.il>
*
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
*
*
* This file is part of Advanced Simulation Library (ASL).
*
* ASL is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* ASL 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ASLABDFORMAT_H
#define ASLABDFORMAT_H
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <memory>
#include <data/aslDataWrapper.h>
using namespace std;
namespace asl {
class ABDFileIn: public std::ifstream{
public:
inline ABDFileIn();
inline ABDFileIn(string name);
};
class ABDFileOut: public std::ofstream{
public:
inline ABDFileOut();
inline ABDFileOut(string name);
};
/* /// \relates ABDFileOut
template <typename T> inline ABDFileOut & operator <<(ABDFileOut & f, const T & a);
template <typename T> inline ABDFileIn & operator >>(ABDFileIn & f,T & a);
*/
inline ABDFileOut & operator <<(ABDFileOut & f, const int a);
inline ABDFileIn & operator >>(ABDFileIn & f,int & a);
inline ABDFileOut & operator <<(ABDFileOut & f, const unsigned int a);
inline ABDFileIn & operator >>(ABDFileIn & f, unsigned int & a);
inline ABDFileOut & operator <<(ABDFileOut & f, const float a);
inline ABDFileIn & operator >>(ABDFileIn & f,float & a);
inline ABDFileOut & operator <<(ABDFileOut & f, const double a);
inline ABDFileIn & operator >>(ABDFileIn & f,double & a);
template <typename T> inline ABDFileOut & operator <<(ABDFileOut & f,pair<T*, unsigned int> a);
template <typename T> inline ABDFileIn & operator >>(ABDFileIn & f,pair<T*, unsigned int> a);
inline ABDFileOut & operator <<(ABDFileOut & f, const string &a);
inline ABDFileIn & operator >>(ABDFileIn & f,string &a);
template <typename T> inline ABDFileOut & operator <<(ABDFileOut & f, const AVec<T> & a);
template <typename T> inline ABDFileIn & operator >>(ABDFileIn & f,AVec<T> & a);
class Block;
ABDFileOut & operator <<(ABDFileOut & f, const Block &a);
ABDFileIn & operator >>(ABDFileIn & f, Block &a);
class AbstractData;
ABDFileOut & operator <<(ABDFileOut & f, const AbstractData &a);
ABDFileIn & operator >>(ABDFileIn & f, AbstractData &a);
ABDFileIn & get(ABDFileIn & f, AbstractData &a, std::shared_ptr<double> d);
void writeABD(const string &fileName, const AbstractData & data, const string & name);
//------------------------IMPLEMENTATION------------------------------
ABDFileIn::ABDFileIn():ifstream()
{};
ABDFileIn::ABDFileIn(string name):
ifstream(name,ios::in | ios::binary)
{}
ABDFileOut::ABDFileOut():ofstream()
{}
ABDFileOut::ABDFileOut(string name):
ofstream(name,ios::out | ios::binary)
{}
inline ABDFileOut & operator <<(ABDFileOut & f, const int a)
{
f.write((char*)&a,sizeof(int));
return f;
}
inline ABDFileIn & operator >>(ABDFileIn & f,int & a)
{
f.read((char*)&a,sizeof(int));
return f;
}
inline ABDFileOut & operator <<(ABDFileOut & f, const unsigned int a)
{
f.write((char*)&a,sizeof(unsigned int));
return f;
}
inline ABDFileIn & operator >>(ABDFileIn & f, unsigned int & a)
{
f.read((char*)&a,sizeof(unsigned int));
return f;
}
inline ABDFileOut & operator <<(ABDFileOut & f, const float a)
{
f.write((char*)&a,sizeof(float));
return f;
}
inline ABDFileIn & operator >>(ABDFileIn & f,float & a)
{
f.read((char*)&a,sizeof(float));
return f;
}
inline ABDFileOut & operator <<(ABDFileOut & f, const double a)
{
f.write((char*)&a,sizeof(double));
return f;
}
inline ABDFileIn & operator >>(ABDFileIn & f,double & a)
{
f.read((char*)&a,sizeof(double));
return f;
}
template <typename T> inline ABDFileOut & operator <<(ABDFileOut & f,pair<T*, unsigned int> a)
{
f.write((char*)a.first,sizeof(T)*a.second);
return f;
}
template <typename T> inline ABDFileIn & operator >>(ABDFileIn & f,pair<T*, unsigned int> a)
{
f.read((char*)a.first,sizeof(T)*a.second);
return f;
}
inline ABDFileOut & operator <<(ABDFileOut & f, const string &a){
unsigned int n=a.size();
f<<n<<make_pair(&a[0],n);
return f;
}
inline ABDFileIn & operator >>(ABDFileIn & f,string &a){
unsigned int n;
f>>n; a.resize(n);
f>>make_pair(a.data(),n);
return f;
}
template <typename T> inline ABDFileOut & operator <<(ABDFileOut & f, const AVec<T> & a)
{
unsigned int n(a.getSize());
f<<n<<make_pair(&(a[0]),n);
return f;
}
template <typename T> inline ABDFileIn & operator >>(ABDFileIn & f,AVec<T> & a)
{
unsigned int n(0);
f>>n;
a.resize(n);
f>>make_pair(&(a[0]),n);
return f;
}
}// asl
#endif //ASLVTKFORMAT_H
asl::ABDFileIn
ABD (ASL Binary Dump) file, input.
Definition: aslABDFormat.h:49
asl::ABDFileIn::ABDFileIn
ABDFileIn()
Definition: aslABDFormat.h:142
asl::ABDFileIn::get
ABDFileIn & get(ABDFileIn &f, AbstractData &a, std::shared_ptr< double > d)
reads data. It is assumed that the class has the propper size
asl::ABDFileOut
ABD (ASL Binary Dump) file, output.
Definition: aslABDFormat.h:59
asl::ABDFileOut::ABDFileOut
ABDFileOut()
Definition: aslABDFormat.h:148
asl::AVec
Definition: aslVectorsDynamicLength.h:40
asl::AVec::getSize
const unsigned int & getSize() const
Definition: aslVectorsDynamicLength.h:171
asl::AVec::resize
void resize(unsigned int newSize)
Definition: aslVectorsDynamicLength.h:223
asl::AbstractData
Definition: aslDataWrapper.h:53
asl::Block
Definition: aslBlocks.h:57
asl::writeABD
void writeABD(const string &fileName, const AbstractData &data, const string &name)
writes data in a file with ABD (ASL Binary Dump) format
asl
Advanced Simulation Library.
Definition: aslDataInc.h:31
asl::in
bool in(const T &xx, const T &x1, const T &x2)
Checks the belonging to a closed interval [x1,x2], .
Definition: aslUtilities.h:84
asl::operator<<
std::ostream & operator<<(std::ostream &output, const std::vector< T > &vector)
Prints elements of the vector separated by space.
Definition: aslUtilities.h:173
asl::operator>>
ABDFileIn & operator>>(ABDFileIn &f, int &a)
Definition: aslABDFormat.h:160
asl::operator<<
ABDFileOut & operator<<(ABDFileOut &f, const AVec< T > &a)
Definition: aslABDFormat.h:227
asl::operator>>
ABDFileIn & operator>>(ABDFileIn &f, AVec< T > &a)
Definition: aslABDFormat.h:234