Skip to content

Commit 59d5688

Browse files
committed
fix win include and export
1 parent 738d462 commit 59d5688

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+280
-113
lines changed

src/diffpy/Attributes.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <stdexcept>
2727
#include <boost/shared_ptr.hpp>
2828

29+
#include <diffpy/Export.hpp>
30+
2931
namespace diffpy {
3032
namespace attributes {
3133

@@ -46,7 +48,7 @@ class DoubleAttributeError : public std::runtime_error
4648
/// @class BaseDoubleAttribute
4749
/// @brief abstract base class for accessing a particular double attribute
4850

49-
class BaseDoubleAttribute
51+
class DLL_EXPORT BaseDoubleAttribute
5052
{
5153
public:
5254

@@ -75,7 +77,7 @@ class BaseAttributesVisitor
7577
/// should derive from Attributes and register their setter and
7678
/// getter methods in their constructors.
7779

78-
class Attributes
80+
class DLL_EXPORT Attributes
7981
{
8082
public:
8183

@@ -98,7 +100,7 @@ class Attributes
98100

99101
protected:
100102

101-
friend void registerBaseDoubleAttribute(Attributes*,
103+
friend DLL_EXPORT void registerBaseDoubleAttribute(Attributes*,
102104
const std::string&, attributes::BaseDoubleAttribute* pa);
103105
template <class T, class Getter>
104106
void registerDoubleAttribute(const std::string& name, T* obj, Getter);
@@ -186,10 +188,10 @@ class Attributes
186188

187189
// non-member helpers
188190

189-
void registerBaseDoubleAttribute(Attributes* obj,
191+
DLL_EXPORT void registerBaseDoubleAttribute(Attributes* obj,
190192
const std::string& name, BaseDoubleAttribute* pa);
191193

192-
void throwDoubleAttributeReadOnly();
194+
DLL_EXPORT void throwDoubleAttributeReadOnly();
193195

194196
} // namespace attributes
195197
} // namespace diffpy

src/diffpy/EventTicker.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
#include <boost/serialization/utility.hpp>
2727
#include <boost/serialization/split_member.hpp>
2828

29+
#include <diffpy/Export.hpp>
30+
2931
namespace diffpy {
3032
namespace eventticker {
3133

32-
class EventTicker
34+
class DLL_EXPORT EventTicker
3335
{
3436
public:
3537

src/diffpy/Export.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#if defined(_WIN32)
4+
#if defined(BUILD_DLL)
5+
#define DLL_EXPORT __declspec(dllexport)
6+
#else
7+
#define DLL_EXPORT __declspec(dllimport)
8+
#endif
9+
#else
10+
#define DLL_EXPORT
11+
#endif

src/diffpy/mathutils.ipp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ inline double remainder(double x, double y)
3434
fmod(x, y) : (fmod(x, y) + y);
3535
}
3636

37-
38-
inline double log2(double x)
39-
{
40-
return log(x) / log(2.0);
41-
}
42-
4337
#endif // _MSC_VER
4438

4539
namespace diffpy {

src/diffpy/runtimepath.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,57 @@
2323
#include <sstream>
2424
#include <stdexcept>
2525
#include <sys/stat.h>
26-
#include <dlfcn.h>
26+
#include <dlfcn.h> // not available on Windows, conda install dlfcn-win32
27+
28+
// libgen.h is not available on Windows
29+
#ifdef _WIN32
30+
#include <string>
31+
#include <algorithm>
32+
33+
// A simple replacement for dirname() on Windows.
34+
inline std::string win_dirname(const std::string& path)
35+
{
36+
// Find the last occurrence of either '\' or '/'
37+
size_t pos = path.find_last_of("\\/");
38+
if (pos == std::string::npos)
39+
return "."; // No directory found, return current directory
40+
return path.substr(0, pos);
41+
}
42+
43+
// Overload to match the expected C-style interface if needed:
44+
inline char* dirname(char* path)
45+
{
46+
static std::string dir;
47+
dir = win_dirname(std::string(path));
48+
return const_cast<char*>(dir.c_str());
49+
}
50+
#else
2751
#include <libgen.h>
52+
#endif
53+
54+
// S_ISDIR, PATH_MAX, realpath, etc.
55+
#ifdef _WIN32
56+
#include <windows.h>
57+
#include <stdlib.h> // for _fullpath
58+
#include <sys/stat.h> // for _stat
59+
#include <direct.h> // for _getcwd, etc.
60+
61+
// Define S_ISDIR using the Windows _S_IFDIR flag from sys/stat.h.
62+
#ifndef S_ISDIR
63+
#define S_ISDIR(mode) (((mode) & _S_IFDIR) == _S_IFDIR)
64+
#endif
65+
66+
// Use MAX_PATH from <windows.h> as PATH_MAX if not defined.
67+
#ifndef PATH_MAX
68+
#define PATH_MAX MAX_PATH
69+
#endif
70+
71+
// Define realpath in terms of _fullpath.
72+
// _fullpath returns a pointer to the resolved path in the buffer you provide.
73+
// The usage should be nearly equivalent.
74+
#define realpath(N, R) _fullpath((R), (N), PATH_MAX)
75+
#endif
76+
2877

2978
#include <diffpy/version.hpp>
3079
#include <diffpy/runtimepath.hpp>

src/diffpy/serialization.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
namespace diffpy {
3333

3434
template <typename T>
35-
std::string serialization_tostring(const T& tobj);
35+
std::string serialization_tostring(const T& tobj);
36+
3637
template <typename T>
37-
void serialization_fromstring(T& tobj, const std::string& s);
38+
void serialization_fromstring(T& tobj, const std::string& s);
3839

3940
namespace serialization {
4041

@@ -44,4 +45,7 @@ typedef ::boost::archive::binary_oarchive oarchive;
4445
} // namespace serialization
4546
} // namespace diffpy
4647

48+
// Pull in the inline definitions and macro logic
49+
#include "serialization.ipp"
50+
4751
#endif // SERIALIZATION_HPP_INCLUDED

src/diffpy/serialization.ipp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,30 @@ void serialization_fromstring(T& tobj, const std::string& s)
5454
ia >> tobj;
5555
}
5656

57-
} // namespace diffpy
58-
5957
// Macros --------------------------------------------------------------------
58+
// Macros for explicit instantiation:
59+
// - On Windows (_WIN32), make them no-ops to avoid dllimport/dllexport issues.
60+
// - On other platforms, keep them as they were.
61+
#ifdef _WIN32
62+
63+
#define DIFFPY_INSTANTIATE_SERIALIZATION(C) /* no-op */
64+
#define DIFFPY_INSTANTIATE_PTR_SERIALIZATION(C) /* no-op */
6065

61-
/// Insert explicit instantiations for serialization_tostring and
62-
/// serialization_fromstring for class C.
66+
#else
6367

64-
#define DIFFPY_INSTANTIATE_SERIALIZATION(C) \
65-
template \
66-
std::string \
67-
diffpy::serialization_tostring<C>(const C&); \
68-
template \
69-
void \
70-
diffpy::serialization_fromstring<C>(C&, const std::string&); \
68+
/// Insert explicit instantiations for serialization_tostring and
69+
/// serialization_fromstring for class C.
70+
#define DIFFPY_INSTANTIATE_SERIALIZATION(C) \
71+
template std::string diffpy::serialization_tostring<C>(const C&); \
72+
template void diffpy::serialization_fromstring<C>(C&, const std::string&);
7173

72-
/// Insert explicit instantiations for serialization_tostring and
73-
/// serialization_fromstring for type boost::shared_ptr<C>.
74+
/// Insert explicit instantiations for serialization_tostring and
75+
/// serialization_fromstring for type boost::shared_ptr<C>.
76+
#define DIFFPY_INSTANTIATE_PTR_SERIALIZATION(C) \
77+
DIFFPY_INSTANTIATE_SERIALIZATION(boost::shared_ptr<C>)
7478

75-
#define DIFFPY_INSTANTIATE_PTR_SERIALIZATION(C) \
76-
DIFFPY_INSTANTIATE_SERIALIZATION(boost::shared_ptr<C>)
79+
#endif
80+
81+
} // namespace diffpy
7782

7883
#endif // SERIALIZATION_IPP_INCLUDED

src/diffpy/srreal/AtomRadiiTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
namespace diffpy {
3030

3131
// Unique instantiation of the template registry base class.
32-
template class HasClassRegistry<srreal::AtomRadiiTable>;
32+
template class DLL_EXPORT HasClassRegistry<srreal::AtomRadiiTable>;
3333

3434
namespace srreal {
3535

src/diffpy/srreal/AtomRadiiTable.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232

3333
#include <diffpy/HasClassRegistry.hpp>
3434

35+
#include <diffpy/Export.hpp>
36+
3537
namespace diffpy {
3638
namespace srreal {
3739

38-
class AtomRadiiTable :
40+
class DLL_EXPORT AtomRadiiTable :
3941
public diffpy::HasClassRegistry<AtomRadiiTable>
4042
{
4143
public:

src/diffpy/srreal/AtomicStructureAdapter.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424

2525
#include <diffpy/srreal/StructureAdapter.hpp>
2626

27+
#include <diffpy/Export.hpp>
28+
2729
namespace diffpy {
2830
namespace srreal {
2931

30-
class Atom
32+
class DLL_EXPORT Atom
3133
{
3234
public:
3335

@@ -64,17 +66,17 @@ class Atom
6466

6567
// Functions related to class Atom
6668

67-
bool operator<(const Atom&, const Atom&);
69+
DLL_EXPORT bool operator<(const Atom&, const Atom&);
6870
inline bool operator>(const Atom& a0, const Atom& a1) { return a1 < a0; }
6971
inline bool operator<=(const Atom& a0, const Atom& a1) { return !(a1 < a0); }
7072
inline bool operator>=(const Atom& a0, const Atom& a1) { return !(a0 < a1); }
7173

72-
bool operator==(const Atom&, const Atom&);
73-
bool operator!=(const Atom&, const Atom&);
74-
size_t hash_value(const Atom&);
74+
DLL_EXPORT bool operator==(const Atom&, const Atom&);
75+
DLL_EXPORT bool operator!=(const Atom&, const Atom&);
76+
DLL_EXPORT size_t hash_value(const Atom&);
7577

7678

77-
class AtomicStructureAdapter : public StructureAdapter
79+
class DLL_EXPORT AtomicStructureAdapter : public StructureAdapter
7880
{
7981
public:
8082

0 commit comments

Comments
 (0)