Skip to content

Commit dda356b

Browse files
committed
Replace macro hack with CRT pattern
IDEs don't understand the macro thing and it keeps annoying me.
1 parent 78ac3f1 commit dda356b

8 files changed

Lines changed: 203 additions & 151 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,13 @@ set(IO_ADIOS1_SEQUENTIAL_SOURCE
426426
src/Error.cpp
427427
src/auxiliary/Filesystem.cpp
428428
src/ChunkInfo.cpp
429+
src/IO/ADIOS/CommonADIOS1IOHandler.cpp
429430
src/IO/ADIOS/ADIOS1IOHandler.cpp)
430431
set(IO_ADIOS1_SOURCE
431432
src/Error.cpp
432433
src/auxiliary/Filesystem.cpp
433434
src/ChunkInfo.cpp
435+
src/IO/ADIOS/CommonADIOS1IOHandler.cpp
434436
src/IO/ADIOS/ParallelADIOS1IOHandler.cpp)
435437

436438
# library

include/openPMD/IO/ADIOS/ADIOS1IOHandlerImpl.hpp

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
#include "openPMD/IO/AbstractIOHandler.hpp"
2626

2727
#if openPMD_HAVE_ADIOS1
28-
# include "openPMD/IO/AbstractIOHandlerImpl.hpp"
29-
# include <adios_read.h>
28+
# include "openPMD/IO/ADIOS/CommonADIOS1IOHandler.hpp"
3029
#endif
3130

3231
#include <future>
@@ -41,8 +40,11 @@
4140
namespace openPMD
4241
{
4342
#if openPMD_HAVE_ADIOS1
44-
class OPENPMDAPI_EXPORT ADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
43+
class OPENPMDAPI_EXPORT ADIOS1IOHandlerImpl
44+
: public CommonADIOS1IOHandlerImpl< ADIOS1IOHandlerImpl >
4545
{
46+
private:
47+
using Base_t = CommonADIOS1IOHandlerImpl< ADIOS1IOHandlerImpl >;
4648
public:
4749
ADIOS1IOHandlerImpl(AbstractIOHandler*);
4850
virtual ~ADIOS1IOHandlerImpl();
@@ -51,48 +53,9 @@ namespace openPMD
5153

5254
std::future< void > flush() override;
5355

54-
void createFile(Writable*, Parameter< Operation::CREATE_FILE > const&) override;
55-
void createPath(Writable*, Parameter< Operation::CREATE_PATH > const&) override;
56-
void createDataset(Writable*, Parameter< Operation::CREATE_DATASET > const&) override;
57-
void extendDataset(Writable*, Parameter< Operation::EXTEND_DATASET > const&) override;
58-
void openFile(Writable*, Parameter< Operation::OPEN_FILE > const&) override;
59-
void closeFile(Writable*, Parameter< Operation::CLOSE_FILE > const&) override;
60-
void availableChunks(Writable*, Parameter< Operation::AVAILABLE_CHUNKS > &) override;
61-
void openPath(Writable*, Parameter< Operation::OPEN_PATH > const&) override;
62-
void openDataset(Writable*, Parameter< Operation::OPEN_DATASET > &) override;
63-
void deleteFile(Writable*, Parameter< Operation::DELETE_FILE > const&) override;
64-
void deletePath(Writable*, Parameter< Operation::DELETE_PATH > const&) override;
65-
void deleteDataset(Writable*, Parameter< Operation::DELETE_DATASET > const&) override;
66-
void deleteAttribute(Writable*, Parameter< Operation::DELETE_ATT > const&) override;
67-
void writeDataset(Writable*, Parameter< Operation::WRITE_DATASET > const&) override;
68-
void writeAttribute(Writable*, Parameter< Operation::WRITE_ATT > const&) override;
69-
void readDataset(Writable*, Parameter< Operation::READ_DATASET > &) override;
70-
void readAttribute(Writable*, Parameter< Operation::READ_ATT > &) override;
71-
void listPaths(Writable*, Parameter< Operation::LIST_PATHS > &) override;
72-
void listDatasets(Writable*, Parameter< Operation::LIST_DATASETS > &) override;
73-
void listAttributes(Writable*, Parameter< Operation::LIST_ATTS > &) override;
74-
7556
virtual int64_t open_write(Writable *);
7657
virtual ADIOS_FILE* open_read(std::string const & name);
77-
void close(int64_t);
78-
void close(ADIOS_FILE*);
7958
int64_t initialize_group(std::string const& name);
80-
void flush_attribute(int64_t group, std::string const& name, Attribute const&);
81-
82-
protected:
83-
ADIOS_READ_METHOD m_readMethod;
84-
std::unordered_map< Writable*, std::shared_ptr< std::string > > m_filePaths;
85-
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_groups;
86-
std::unordered_map< std::shared_ptr< std::string >, bool > m_existsOnDisk;
87-
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_openWriteFileHandles;
88-
std::unordered_map< std::shared_ptr< std::string >, ADIOS_FILE* > m_openReadFileHandles;
89-
std::unordered_map< ADIOS_FILE*, std::vector< ADIOS_SELECTION* > > m_scheduledReads;
90-
std::unordered_map< int64_t, std::unordered_map< std::string, Attribute > > m_attributeWrites;
91-
/**
92-
* Call this function to get adios file id for a Writable. Will create one if does not exist
93-
* @return returns an adios file id.
94-
*/
95-
int64_t GetFileHandle(Writable*);
9659
}; // ADIOS1IOHandlerImpl
9760
#else
9861
class OPENPMDAPI_EXPORT ADIOS1IOHandlerImpl
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/* Copyright 2017-2021 Fabian Koller and Franz Poeschel
2+
*
3+
* This file is part of openPMD-api.
4+
*
5+
* openPMD-api is free software: you can redistribute it and/or modify
6+
* it under the terms of of either the GNU General Public License or
7+
* the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* openPMD-api is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License and the GNU Lesser General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* and the GNU Lesser General Public License along with openPMD-api.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
#pragma once
22+
23+
#include "openPMD/config.hpp"
24+
25+
#if openPMD_HAVE_ADIOS1
26+
27+
#include "openPMD/IO/AbstractIOHandler.hpp"
28+
#include "openPMD/auxiliary/Filesystem.hpp"
29+
#include "openPMD/auxiliary/DerefDynamicCast.hpp"
30+
#include "openPMD/auxiliary/Memory.hpp"
31+
#include "openPMD/auxiliary/StringManip.hpp"
32+
#include "openPMD/IO/AbstractIOHandlerImpl.hpp"
33+
#include "openPMD/IO/ADIOS/ADIOS1Auxiliary.hpp"
34+
#include "openPMD/IO/ADIOS/ADIOS1FilePosition.hpp"
35+
36+
#include <adios.h>
37+
#include <adios_read.h>
38+
39+
#include <future>
40+
#include <memory>
41+
#include <string>
42+
#include <utility>
43+
#include <unordered_map>
44+
#include <unordered_set>
45+
46+
namespace openPMD
47+
{
48+
template< typename ChildClass > // CRT pattern
49+
class CommonADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
50+
{
51+
public:
52+
53+
void createFile(Writable*, Parameter< Operation::CREATE_FILE > const&) override;
54+
void createPath(Writable*, Parameter< Operation::CREATE_PATH > const&) override;
55+
void createDataset(Writable*, Parameter< Operation::CREATE_DATASET > const&) override;
56+
void extendDataset(Writable*, Parameter< Operation::EXTEND_DATASET > const&) override;
57+
void openFile(Writable*, Parameter< Operation::OPEN_FILE > const&) override;
58+
void closeFile(Writable*, Parameter< Operation::CLOSE_FILE > const&) override;
59+
void availableChunks(Writable*, Parameter< Operation::AVAILABLE_CHUNKS > &) override;
60+
void openPath(Writable*, Parameter< Operation::OPEN_PATH > const&) override;
61+
void openDataset(Writable*, Parameter< Operation::OPEN_DATASET > &) override;
62+
void deleteFile(Writable*, Parameter< Operation::DELETE_FILE > const&) override;
63+
void deletePath(Writable*, Parameter< Operation::DELETE_PATH > const&) override;
64+
void deleteDataset(Writable*, Parameter< Operation::DELETE_DATASET > const&) override;
65+
void deleteAttribute(Writable*, Parameter< Operation::DELETE_ATT > const&) override;
66+
void writeDataset(Writable*, Parameter< Operation::WRITE_DATASET > const&) override;
67+
void writeAttribute(Writable*, Parameter< Operation::WRITE_ATT > const&) override;
68+
void readDataset(Writable*, Parameter< Operation::READ_DATASET > &) override;
69+
void readAttribute(Writable*, Parameter< Operation::READ_ATT > &) override;
70+
void listPaths(Writable*, Parameter< Operation::LIST_PATHS > &) override;
71+
void listDatasets(Writable*, Parameter< Operation::LIST_DATASETS > &) override;
72+
void listAttributes(Writable*, Parameter< Operation::LIST_ATTS > &) override;
73+
74+
void close(int64_t);
75+
void close(ADIOS_FILE*);
76+
void flush_attribute(int64_t group, std::string const& name, Attribute const&);
77+
78+
protected:
79+
template< typename... Args >
80+
CommonADIOS1IOHandlerImpl( Args &&... args)
81+
: AbstractIOHandlerImpl{ std::forward< Args >( args )... }
82+
{}
83+
84+
ADIOS_READ_METHOD m_readMethod;
85+
std::unordered_map< Writable*, std::shared_ptr< std::string > > m_filePaths;
86+
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_groups;
87+
std::unordered_map< std::shared_ptr< std::string >, bool > m_existsOnDisk;
88+
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_openWriteFileHandles;
89+
std::unordered_map< std::shared_ptr< std::string >, ADIOS_FILE* > m_openReadFileHandles;
90+
std::unordered_map< ADIOS_FILE*, std::vector< ADIOS_SELECTION* > > m_scheduledReads;
91+
std::unordered_map< int64_t, std::unordered_map< std::string, Attribute > > m_attributeWrites;
92+
/**
93+
* Call this function to get adios file id for a Writable. Will create one if does not exist
94+
* @return returns an adios file id.
95+
*/
96+
int64_t GetFileHandle(Writable*);
97+
}; // ParallelADIOS1IOHandlerImpl
98+
} // openPMD
99+
100+
#endif

include/openPMD/IO/ADIOS/ParallelADIOS1IOHandlerImpl.hpp

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#include "openPMD/IO/AbstractIOHandler.hpp"
2626

2727
#if openPMD_HAVE_ADIOS1 && openPMD_HAVE_MPI
28-
# include "openPMD/IO/AbstractIOHandlerImpl.hpp"
29-
# include <adios.h>
30-
# include <adios_read.h>
28+
# include "openPMD/IO/ADIOS/CommonADIOS1IOHandler.hpp"
3129
#endif
3230

3331
#include <future>
@@ -42,8 +40,11 @@
4240
namespace openPMD
4341
{
4442
#if openPMD_HAVE_ADIOS1 && openPMD_HAVE_MPI
45-
class OPENPMDAPI_EXPORT ParallelADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
43+
class OPENPMDAPI_EXPORT ParallelADIOS1IOHandlerImpl
44+
: public CommonADIOS1IOHandlerImpl< ParallelADIOS1IOHandlerImpl >
4645
{
46+
private:
47+
using Base_t = CommonADIOS1IOHandlerImpl< ParallelADIOS1IOHandlerImpl >;
4748
public:
4849
ParallelADIOS1IOHandlerImpl(AbstractIOHandler*, MPI_Comm);
4950
virtual ~ParallelADIOS1IOHandlerImpl();
@@ -52,48 +53,11 @@ namespace openPMD
5253

5354
std::future< void > flush() override;
5455

55-
void createFile(Writable*, Parameter< Operation::CREATE_FILE > const&) override;
56-
void createPath(Writable*, Parameter< Operation::CREATE_PATH > const&) override;
57-
void createDataset(Writable*, Parameter< Operation::CREATE_DATASET > const&) override;
58-
void extendDataset(Writable*, Parameter< Operation::EXTEND_DATASET > const&) override;
59-
void openFile(Writable*, Parameter< Operation::OPEN_FILE > const&) override;
60-
void closeFile(Writable*, Parameter< Operation::CLOSE_FILE > const&) override;
61-
void availableChunks(Writable*, Parameter< Operation::AVAILABLE_CHUNKS > &) override;
62-
void openPath(Writable*, Parameter< Operation::OPEN_PATH > const&) override;
63-
void openDataset(Writable*, Parameter< Operation::OPEN_DATASET > &) override;
64-
void deleteFile(Writable*, Parameter< Operation::DELETE_FILE > const&) override;
65-
void deletePath(Writable*, Parameter< Operation::DELETE_PATH > const&) override;
66-
void deleteDataset(Writable*, Parameter< Operation::DELETE_DATASET > const&) override;
67-
void deleteAttribute(Writable*, Parameter< Operation::DELETE_ATT > const&) override;
68-
void writeDataset(Writable*, Parameter< Operation::WRITE_DATASET > const&) override;
69-
void writeAttribute(Writable*, Parameter< Operation::WRITE_ATT > const&) override;
70-
void readDataset(Writable*, Parameter< Operation::READ_DATASET > &) override;
71-
void readAttribute(Writable*, Parameter< Operation::READ_ATT > &) override;
72-
void listPaths(Writable*, Parameter< Operation::LIST_PATHS > &) override;
73-
void listDatasets(Writable*, Parameter< Operation::LIST_DATASETS > &) override;
74-
void listAttributes(Writable*, Parameter< Operation::LIST_ATTS > &) override;
75-
7656
virtual int64_t open_write(Writable *);
7757
virtual ADIOS_FILE* open_read(std::string const & name);
78-
void close(int64_t);
79-
void close(ADIOS_FILE*);
8058
int64_t initialize_group(std::string const& name);
81-
void flush_attribute(int64_t group, std::string const& name, Attribute const&);
8259

8360
protected:
84-
ADIOS_READ_METHOD m_readMethod;
85-
std::unordered_map< Writable*, std::shared_ptr< std::string > > m_filePaths;
86-
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_groups;
87-
std::unordered_map< std::shared_ptr< std::string >, bool > m_existsOnDisk;
88-
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_openWriteFileHandles;
89-
std::unordered_map< std::shared_ptr< std::string >, ADIOS_FILE* > m_openReadFileHandles;
90-
std::unordered_map< ADIOS_FILE*, std::vector< ADIOS_SELECTION* > > m_scheduledReads;
91-
std::unordered_map< int64_t, std::unordered_map< std::string, Attribute > > m_attributeWrites;
92-
/**
93-
* Call this function to get adios file id for a Writable. Will create one if does not exist
94-
* @return returns an adios file id.
95-
*/
96-
int64_t GetFileHandle(Writable*);
9761
MPI_Comm m_mpiComm;
9862
MPI_Info m_mpiInfo;
9963
}; // ParallelADIOS1IOHandlerImpl

include/openPMD/backend/Writable.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Writable final
7878
friend class ParticleSpecies;
7979
friend class SeriesInterface;
8080
friend class Record;
81+
template< typename > friend class CommonADIOS1IOHandlerImpl;
8182
friend class ADIOS1IOHandlerImpl;
8283
friend class ParallelADIOS1IOHandlerImpl;
8384
friend class ADIOS2IOHandlerImpl;

src/IO/ADIOS/ADIOS1IOHandler.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,16 @@
2222
#include "openPMD/IO/ADIOS/ADIOS1IOHandlerImpl.hpp"
2323

2424
#if openPMD_HAVE_ADIOS1
25-
# include "openPMD/auxiliary/Filesystem.hpp"
26-
# include "openPMD/auxiliary/DerefDynamicCast.hpp"
27-
# include "openPMD/auxiliary/Memory.hpp"
28-
# include "openPMD/auxiliary/StringManip.hpp"
2925
# include "openPMD/IO/AbstractIOHandlerImpl.hpp"
30-
# include "openPMD/IO/ADIOS/ADIOS1Auxiliary.hpp"
31-
# include "openPMD/IO/ADIOS/ADIOS1FilePosition.hpp"
26+
3227
# include "openPMD/IO/IOTask.hpp"
3328
# include <adios.h>
29+
# include <cstring>
3430
# include <iostream>
31+
# include <map>
3532
# include <memory>
33+
# include <string>
3634
#endif
37-
#include <utility>
3835

3936

4037
namespace openPMD
@@ -47,7 +44,7 @@ namespace openPMD
4744
# endif
4845

4946
ADIOS1IOHandlerImpl::ADIOS1IOHandlerImpl(AbstractIOHandler* handler)
50-
: AbstractIOHandlerImpl(handler)
47+
: Base_t(handler)
5148
{ }
5249

5350
ADIOS1IOHandlerImpl::~ADIOS1IOHandlerImpl()
@@ -319,17 +316,6 @@ ADIOS1IOHandlerImpl::initialize_group(std::string const &name)
319316
return group;
320317
}
321318

322-
} // namespace openPMD
323-
324-
#ifndef DOXYGEN_SHOULD_SKIP_THIS
325-
#define CommonADIOS1IOHandlerImpl ADIOS1IOHandlerImpl
326-
#include "CommonADIOS1IOHandler.cpp"
327-
#undef CommonADIOS1IOHandlerImpl
328-
#endif
329-
330-
namespace openPMD
331-
{
332-
333319
#else
334320
ADIOS1IOHandler::ADIOS1IOHandler(std::string path, Access at)
335321
: AbstractIOHandler(std::move(path), at)

0 commit comments

Comments
 (0)