Skip to content
Snippets Groups Projects
Commit d9151bd5 authored by wfg's avatar wfg
Browse files

Figuring out best way to pass different Variable types.

Must use polymorphism of the CVariable class with Get and Set? 
Union should be avoided as it doesn't preserve actual memory size of
variable type (always returns the largest).
parent e95a4ddd
No related branches found
No related tags found
1 merge request!8Integrate groupless
......@@ -48,7 +48,7 @@ Text style for readability (Coding format setup in Eclipse with Window > Prefere
}
5) Brackets: use an extra space for brackets
5) Brackets: use an extra space for brackets. Only one line conditionals can skip having brackets.
Do:
if( number < 1 )
{
......@@ -61,10 +61,13 @@ Text style for readability (Coding format setup in Eclipse with Window > Prefere
number = 4; .....
.....}
It's ok to omit brackets in one line conditionals:
if( itMap == map.end() ) throw std::invalid_argument( "ERROR: not found in map\n" );
6) Prefer the keyword "using" over "typedef". Only rename complex types, do not rename standard types (int, double, std::vector)
Don't: typedef std::vector<std::vector<double>> Vector2D;
Do: using std::vector<std::vector<double>> = Vector2D;
6) Prefer the keyword "using" over "typedef". Only rename very complex custom types,
do not rename standard types (int, double, std::vector)
Don't: typedef std::vector<std::vector< std::map<std::string,double> >> MapIn2DVector;
Do: using std::vector<std::vector< std::map<std::string,double> >> = MapIn2DVector;
Documentation/Comments
......
......@@ -2,7 +2,7 @@
<adios-config host-language="C++">
<adios-group name="Vector">
<var name="Numbers" type="integer"/>
<var name="Numbers" type="Vinteger"/>
<attribute name="description" value="1 to 10"/>
</adios-group>
......
......@@ -16,7 +16,7 @@ int main( int argc, char* argv [] )
{
try
{
adios::ADIOS adios( "writer2Groups.xml" ); //testing with CPOSIXNoMPI
adios::ADIOS adios( "writer2Groups.xml", true ); //testing with CPOSIXNoMPI
adios.MonitorGroups( std::cout );
std::cout << "Finished initializing ADIOS\n";
}
......
......@@ -36,9 +36,13 @@ public:
* @param method zlib, bzip2, szip
* @param variable
*/
CTransform( const std::string method, const unsigned int compressionLevel, CVariable& variable );
CTransform( const std::string method, const unsigned int compressionLevel, CVariable& variable ):
m_Method( method ),
m_CompressionLevel( compressionLevel ),
m_Variable( variable )
{ }
virtual ~CTransform( );
virtual ~CTransform( ){ };
virtual void Compress( ) const = 0; ///< Compress m_Variable data m_Value
......
......@@ -28,10 +28,9 @@ public:
virtual ~CVariable( );
//template<class T> const T& Get( ) const;
template<class T> const T* Get( ) const;
template<class T> void Set( const void* values );
//protected: turned off for testing
bool m_IsGlobal = false;
std::string m_Type = "NONE"; ///< mandatory, double, float, unsigned integer, integer, etc.
......
......@@ -38,19 +38,22 @@ public:
const T* m_Value = nullptr; // pointer or no pointer?
//const T& Get() const { return m_Value; }
void Set( const void* values ){ m_Value = static_cast<T const*> (values); }
const T* Get() const { return m_Value; }
void Set( const void* values ){ m_Value = static_cast<const T*> (values); }
};
template<class T> const T* CVariable::Get( ) const
{
return dynamic_cast<CVariableTemplate<T>const & >(*this).Get( );
}
template<class T> void CVariable::Set( const void* values )
{
return dynamic_cast< CVariableTemplate<T>& >( *this ).Set( values );
}
} //end namespace
#endif /* CVARIABLETEMPLATE_H_ */
......@@ -121,6 +121,8 @@ private:
std::map< std::string, std::unique_ptr<CTransform> > m_Transforms;
/**
* @brief Maximum buffer size in ADIOS write() operation. From buffer max - size - MB in XML file
* Note, that if there are two ADIOS outputs going on at the same time,
......
......@@ -61,6 +61,10 @@ void CGroup::SetVariable( const std::string name, const bool isGlobal, const std
m_Variables[name] = std::make_shared< CVariableTemplate<float> >( isGlobal, type, dimensionsCSV, transform );
else if( type == "double")
m_Variables[name] = std::make_shared< CVariableTemplate<double> >( isGlobal, type, dimensionsCSV, transform );
else if( type == "Vinteger")
m_Variables[name] = std::make_shared< CVariableTemplate< std::vector<int> > >( isGlobal, type, dimensionsCSV, transform );
else
throw std::invalid_argument( "ERROR: type " + type + " for variable " + name + "not supported\n" );
};
//Function body start here
......@@ -131,6 +135,8 @@ void CGroup::Write( const std::string variableName, const void* values )
if( type == "double" ) variable->Set<double>( values );
else if( type == "integer" ) variable->Set<int>( values );
else if( type == "Vinteger" ) variable->Set<std::vector<int>>( values );
// else if( type == "unsigned integer" ) variable->Set<unsigned int>( values );
// else if( type == "float" ) variable->Set<float>( values );
......
......@@ -7,8 +7,7 @@
#include "core/CVariable.h"
#include "core/CVariableTemplate.h" //for dynamic_cast
#include "core/CVariableTemplate.h"
namespace adios
{
......
......@@ -8,6 +8,8 @@
#include <iostream>
#include "transport/CFStream.h"
#include "core/CVariableTemplate.h"
#include "core/CVariable.h"
namespace adios
......@@ -31,6 +33,17 @@ void CFStream::Write( const CVariable& variable )
std::cout << "Just saying Hello from CFStream Write from process " << rank << "/" << size << "\n";
std::cout << "My variable type is " << variable.m_Type << "\n";
auto var = variable.Get< std::vector<int> >();
// std::cout << "Var is empty: " << std::boolalpha << var.empty() << "\n";
std::cout << "var " << var->at(0) << "\n";
//pointer to vector
// for( unsigned int i = 0; i < 10; ++i )
// std::cout << "var[" << i << "] = " << var->at(i) << "\n";
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment