ldrarrays.h
1 /***************************************************************************
2  ldrarrays.h - description
3  -------------------
4  begin : Mon Jul 5 2004
5  copyright : (C) 2000-2015 by Thies H. Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef LDRARRAYS_H
19 #define LDRARRAYS_H
20 
21 #include <tjutils/tjarray.h>
22 #include <odinpara/ldrbase.h>
23 #include <odinpara/ldrnumbers.h>
24 #include <odinpara/ldrtypes.h>
25 
26 
27 #define COMPRESSION_THRESHOLD_SIZE 256
28 
29 
41 template<class A,class J>
42 class LDRarray : public A, public virtual LDRbase {
43 
44  public:
45 
49  LDRarray () : A() {common_init();}
50 
56  LDRarray (const A& a, const STD_string& name="");
57 
61 // LDRarray (const J& jv) {common_init(); A::operator = (jv);}
62 
66  LDRarray (const LDRarray<A,J>& ja) {common_init(); LDRarray<A,J>::operator = (ja);}
67 
71  LDRarray<A,J>& operator = (const A& a);
72 
76  LDRarray<A,J>& operator = (const J& jv) {A::operator = (jv); return *this;}
77 
82 
83 
84  // overwriting virtual functions from LDRbase
85  STD_ostream& print2stream(STD_ostream& os, const LDRserBase& serializer) const;
86  STD_string printvalstring(const LDRserBase* ser=0) const;
87  bool parsevalstring(const STD_string& parstring, const LDRserBase* ser=0);
88  STD_string get_parx_code(parxCodeType type) const;
89  GuiProps get_gui_props() const {return guiprops;}
90  LDRbase& set_gui_props(const GuiProps& gp) {guiprops=gp; return *this;}
91  STD_string get_typeInfo(bool parx_equivtype=false) const;
92  LDRbase* create_copy() const {return new LDRarray<A,J>(*this);}
93  A* cast(A*) {return this;}
94 
95 
96  // final overrider
97  friend STD_ostream& operator << (STD_ostream& s,const LDRarray<A,J>& ja) { return ja.print2stream(s,LDRserJDX());}
98  int write(const STD_string& filename, const LDRserBase& serializer=LDRserJDX()) const {return LDRbase::write(filename,serializer);}
99  int load(const STD_string &filename, const LDRserBase& serializer=LDRserJDX()) {return LDRbase::load(filename,serializer);}
100 
101 
102  private:
103  void common_init();
104  STD_string get_dim_str(const LDRserBase* ser) const;
105 
106  bool encode(STD_string* ostring, STD_ostream* ostream) const;
107 
108  bool use_compression() const {return (get_filemode()==compressed)&&(A::total()>COMPRESSION_THRESHOLD_SIZE);}
109 
110  GuiProps guiprops;
111 
112  mutable STD_string typeInfo_cache;
113 
114 };
115 
117 //
118 // Aliases:
119 //
120 
125 
130 
135 
140 
145 
146 
147 
149 // Specialised array classes:
150 
151 
155 class LDRtriple : public LDRfloatArr {
156 
157  public:
158 
162  LDRtriple () : LDRfloatArr(farray(3)) {}
163 
171  LDRtriple (float xpos, float ypos, float zpos, const STD_string& name="");
172 
177 
183  return *this;
184  }
185 
186  // overwriting virtual functions from LDRbase
187  STD_string get_typeInfo(bool parx_equivtype=false) const {return "triple";}
188  LDRbase* create_copy() const {return new LDRtriple(*this);}
189  LDRtriple* cast(LDRtriple*) {return this;}
190  farray* cast(farray*) {return 0;} // disable casting to base class
191 
192 };
193 
197 #endif
198 
LDRarray< carray, LDRcomplex > LDRcomplexArr
Definition: ldrarrays.h:144
LDRtriple & operator=(const LDRtriple &pos)
Definition: ldrarrays.h:181
parxCodeType
Definition: ldrbase.h:216
STD_string get_typeInfo(bool parx_equivtype=false) const
LDRtriple(const LDRtriple &pos)
Definition: ldrarrays.h:176
LDRarray()
Definition: ldrarrays.h:49
LDRbase * create_copy() const
Definition: ldrarrays.h:92
virtual fileMode get_filemode() const
Definition: ldrbase.h:420
virtual int load(const STD_string &filename, const LDRserBase &serializer=LDRserJDX())
LDRarray(const LDRarray< A, J > &ja)
Definition: ldrarrays.h:66
LDRarray< farray, LDRfloat > LDRfloatArr
Definition: ldrarrays.h:134
int load(const STD_string &filename, const LDRserBase &serializer=LDRserJDX())
Definition: ldrarrays.h:99
int write(const STD_string &filename, const LDRserBase &serializer=LDRserJDX()) const
Definition: ldrarrays.h:98
LDRarray< sarray, LDRstring > LDRstringArr
Definition: ldrarrays.h:124
STD_string printvalstring(const LDRserBase *ser=0) const
STD_string get_parx_code(parxCodeType type) const
STD_string get_typeInfo(bool parx_equivtype=false) const
Definition: ldrarrays.h:187
bool parsevalstring(const STD_string &parstring, const LDRserBase *ser=0)
LDRarray< darray, LDRdouble > LDRdoubleArr
Definition: ldrarrays.h:139
LDRarray< iarray, LDRint > LDRintArr
Definition: ldrarrays.h:129
STD_ostream & print2stream(STD_ostream &os, const LDRserBase &serializer) const
LDRbase & set_gui_props(const GuiProps &gp)
Definition: ldrarrays.h:90
GuiProps get_gui_props() const
Definition: ldrarrays.h:89
LDRbase * create_copy() const
Definition: ldrarrays.h:188
LDRarray< A, J > & operator=(const A &a)
virtual int write(const STD_string &filename, const LDRserBase &serializer=LDRserJDX()) const