Skip to content

Commit

Permalink
move functions read_ccp4_map() and read_ccp4_mask() to the library
Browse files Browse the repository at this point in the history
for consistency, it was the last implementation guarded by macros
  • Loading branch information
wojdyr committed Aug 27, 2024
1 parent 1c93083 commit fb325eb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 42 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ add_library(gemmi_cpp
src/align.cpp src/assembly.cpp src/calculate.cpp src/crd.cpp
src/ddl.cpp src/eig3.cpp src/gz.cpp src/intensit.cpp src/json.cpp
src/mmcif.cpp src/mmread_gz.cpp src/mtz.cpp src/mtz2cif.cpp
src/pdb.cpp src/polyheur.cpp src/read_cif.cpp src/resinfo.cpp
src/riding_h.cpp src/sprintf.cpp src/to_mmcif.cpp
src/pdb.cpp src/polyheur.cpp src/read_cif.cpp src/read_map.cpp
src/resinfo.cpp src/riding_h.cpp src/sprintf.cpp src/to_mmcif.cpp
src/to_pdb.cpp src/monlib.cpp src/topo.cpp src/xds_ascii.cpp)
add_library(gemmi::gemmi_cpp ALIAS gemmi_cpp)
set_property(TARGET gemmi_cpp PROPERTY POSITION_INDEPENDENT_CODE ON)
Expand Down
1 change: 0 additions & 1 deletion fortran/gemmi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ splicer_code:
c:
CXX_definitions: |
// for read_ccp4_map() and read_ccp4_mask()
#define GEMMI_READ_MAP_IMPLEMENTATION
#include "gemmi/read_map.hpp"
declarations:
Expand Down
40 changes: 4 additions & 36 deletions include/gemmi/read_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,16 @@
//
// Functions for reading possibly gzipped CCP4 map files.
// Trivial wrappers that can make compilation faster.
//
// The definitions are guarded by #ifdef *_IMPLEMENTATION.
// If you use this header in your program, you need in exactly one file:
// #define GEMMI_READ_MAP_IMPLEMENTATION
// #include <gemmi/read_map.hpp>

#ifndef GEMMI_GZREAD_MAP_HPP_
#define GEMMI_GZREAD_MAP_HPP_
#ifndef GEMMI_READ_MAP_HPP_
#define GEMMI_READ_MAP_HPP_

#include "ccp4.hpp" // for Ccp4

namespace gemmi {

Ccp4<float> read_ccp4_map(const std::string& path, bool setup);
Ccp4<int8_t> read_ccp4_mask(const std::string& path, bool setup);

} // namespace gemmi

#endif


#ifdef GEMMI_READ_MAP_IMPLEMENTATION

#include "gz.hpp" // for MaybeGzipped

namespace gemmi {

Ccp4<float> read_ccp4_map(const std::string& path, bool setup) {
Ccp4<float> ccp4;
ccp4.read_ccp4(MaybeGzipped(path));
if (setup)
ccp4.setup(NAN);
return ccp4;
}

Ccp4<int8_t> read_ccp4_mask(const std::string& path, bool setup) {
Ccp4<int8_t> ccp4;
ccp4.read_ccp4(MaybeGzipped(path));
if (setup)
ccp4.setup(-1);
return ccp4;
}
GEMMI_DLL Ccp4<float> read_ccp4_map(const std::string& path, bool setup);
GEMMI_DLL Ccp4<int8_t> read_ccp4_mask(const std::string& path, bool setup);

} // namespace gemmi

Expand Down
5 changes: 2 additions & 3 deletions python/ccp4.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright 2018 Global Phasing Ltd.

#include "gemmi/ccp4.hpp"
#include "gemmi/util.hpp" // for cat
#include "gemmi/read_map.hpp" // for read_ccp4_map, read_ccp4_mask
#include "common.h"
#include <pybind11/stl.h>

#define GEMMI_READ_MAP_IMPLEMENTATION
#include "gemmi/read_map.hpp" // defines read_ccp4_map, read_ccp4_mask

namespace py = pybind11;
using namespace gemmi;

Expand Down
24 changes: 24 additions & 0 deletions src/read_map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2021 Global Phasing Ltd.

#include "gemmi/read_map.hpp"
#include "gemmi/gz.hpp" // for MaybeGzipped

namespace gemmi {

Ccp4<float> read_ccp4_map(const std::string& path, bool setup) {
Ccp4<float> ccp4;
ccp4.read_ccp4(MaybeGzipped(path));
if (setup)
ccp4.setup(NAN);
return ccp4;
}

Ccp4<int8_t> read_ccp4_mask(const std::string& path, bool setup) {
Ccp4<int8_t> ccp4;
ccp4.read_ccp4(MaybeGzipped(path));
if (setup)
ccp4.setup(-1);
return ccp4;
}

} // namespace gemmi

0 comments on commit fb325eb

Please sign in to comment.