Marked Parser, Emitter, Node, Iterator, Mark, and Null for exporting to a DLL. It appears to work properly, although VS gives me lots of warning C4251 since I didn't export all data members of each of the above classes.

It seems that it's not necessary to export those members (as long as you can't access them), and most of them are STL instances, which apparently cause lots of problems for DLLs. (For example, you simply can't export instances of std::map; see http://support.microsoft.com/kb/168958.)
This commit is contained in:
Jesse Beder 2011-03-16 02:31:30 +00:00
parent 221d17b0c6
commit c67b41c966
10 changed files with 77 additions and 30 deletions

View File

@ -18,8 +18,8 @@ namespace YAML
return true;
}
bool Convert(const std::string& input, bool& output);
bool Convert(const std::string& input, _Null& output);
YAML_CPP_API bool Convert(const std::string& input, bool& output);
YAML_CPP_API bool Convert(const std::string& input, _Null& output);
template <typename T>
inline bool Convert(const std::string& input, T& output, typename enable_if<is_numeric<T> >::type * = 0) {

28
include/yaml-cpp/dll.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the yaml_cpp_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// YAML_CPP_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#undef YAML_CPP_API
#ifdef YAML_CPP_DLL // Using or Building YAML-CPP DLL (definition defined manually)
#ifdef yaml_cpp_EXPORTS // Building YAML-CPP DLL (definition created by CMake or defined manually)
// #pragma message( "Defining YAML_CPP_API for DLL export" )
#define YAML_CPP_API __declspec(dllexport)
#else // yaml_cpp_EXPORTS
// #pragma message( "Defining YAML_CPP_API for DLL import" )
#define YAML_CPP_API __declspec(dllimport)
#endif // yaml_cpp_EXPORTS
#else //YAML_CPP_DLL
#define YAML_CPP_API
#endif // YAML_CPP_DLL
#endif // DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@ -6,6 +6,7 @@
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/emittermanip.h"
#include "yaml-cpp/ostream.h"
#include "yaml-cpp/noncopyable.h"
@ -18,7 +19,7 @@ namespace YAML
{
class EmitterState;
class Emitter: private noncopyable
class YAML_CPP_API Emitter: private noncopyable
{
public:
Emitter();
@ -65,7 +66,9 @@ namespace YAML
private:
void PreWriteIntegralType(std::stringstream& str);
void PreWriteStreamable(std::stringstream& str);
void PostWriteIntegralType(const std::stringstream& str);
void PostWriteStreamable(const std::stringstream& str);
private:
enum ATOMIC_TYPE { AT_SCALAR, AT_SEQ, AT_BLOCK_SEQ, AT_FLOW_SEQ, AT_MAP, AT_BLOCK_MAP, AT_FLOW_MAP };
@ -114,15 +117,10 @@ namespace YAML
if(!good())
return *this;
PreAtomicWrite();
EmitSeparationIfNecessary();
std::stringstream str;
str.precision(15);
PreWriteStreamable(str);
str << value;
m_stream << str.str();
PostAtomicWrite();
PostWriteStreamable(str);
return *this;
}

View File

@ -5,6 +5,7 @@
#pragma once
#endif
#include "yaml-cpp/dll.h"
#include <memory>
namespace YAML
@ -12,7 +13,7 @@ namespace YAML
class Node;
struct IterPriv;
class Iterator
class YAML_CPP_API Iterator
{
public:
Iterator();
@ -28,8 +29,8 @@ namespace YAML
const Node& first() const;
const Node& second() const;
friend bool operator == (const Iterator& it, const Iterator& jt);
friend bool operator != (const Iterator& it, const Iterator& jt);
friend YAML_CPP_API bool operator == (const Iterator& it, const Iterator& jt);
friend YAML_CPP_API bool operator != (const Iterator& it, const Iterator& jt);
private:
std::auto_ptr<IterPriv> m_pData;

View File

@ -6,9 +6,11 @@
#endif
#include "yaml-cpp/dll.h"
namespace YAML
{
struct Mark {
struct YAML_CPP_API Mark {
Mark(): pos(0), line(0), column(0) {}
static const Mark null() { return Mark(-1, -1, -1); }

View File

@ -7,6 +7,7 @@
#include "yaml-cpp/conversion.h"
#include "yaml-cpp/dll.h"
#include "yaml-cpp/exceptions.h"
#include "yaml-cpp/iterator.h"
#include "yaml-cpp/ltnode.h"
@ -29,7 +30,7 @@ namespace YAML
struct NodeType { enum value { Null, Scalar, Sequence, Map }; };
class Node: private noncopyable
class YAML_CPP_API Node: private noncopyable
{
public:
friend class NodeOwnership;
@ -65,7 +66,7 @@ namespace YAML
const T to() const;
template <typename T>
friend void operator >> (const Node& node, T& value);
friend YAML_CPP_API void operator >> (const Node& node, T& value);
// retrieval for maps and sequences
template <typename T>
@ -82,7 +83,7 @@ namespace YAML
const std::string& Tag() const { return m_tag; }
// emitting
friend Emitter& operator << (Emitter& out, const Node& node);
friend YAML_CPP_API Emitter& operator << (Emitter& out, const Node& node);
// ordering
int Compare(const Node& rhs) const;

View File

@ -5,20 +5,21 @@
#pragma once
#endif
#include "yaml-cpp/dll.h"
namespace YAML
{
// this is basically boost::noncopyable
class noncopyable
{
protected:
noncopyable() {}
~noncopyable() {}
class YAML_CPP_API noncopyable
{
protected:
noncopyable() {}
~noncopyable() {}
private:
noncopyable(const noncopyable&);
const noncopyable& operator = (const noncopyable&);
};
private:
noncopyable(const noncopyable&);
const noncopyable& operator = (const noncopyable&);
};
}
#endif // NONCOPYABLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@ -6,17 +6,19 @@
#endif
#include "yaml-cpp/dll.h"
namespace YAML
{
class Node;
struct _Null {};
struct YAML_CPP_API _Null {};
inline bool operator == (const _Null&, const _Null&) { return true; }
inline bool operator != (const _Null&, const _Null&) { return false; }
bool IsNull(const Node& node);
YAML_CPP_API bool IsNull(const Node& node);
extern _Null Null;
extern YAML_CPP_API _Null Null;
}
#endif // NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@ -6,6 +6,7 @@
#endif
#include "yaml-cpp/dll.h"
#include "yaml-cpp/noncopyable.h"
#include <ios>
#include <memory>
@ -19,7 +20,7 @@ namespace YAML
class Node;
class Scanner;
class Parser: private noncopyable
class YAML_CPP_API Parser: private noncopyable
{
public:
Parser();

View File

@ -657,12 +657,25 @@ namespace YAML
}
}
void Emitter::PreWriteStreamable(std::stringstream& str)
{
PreAtomicWrite();
EmitSeparationIfNecessary();
str.precision(15);
}
void Emitter::PostWriteIntegralType(const std::stringstream& str)
{
m_stream << str.str();
PostAtomicWrite();
}
void Emitter::PostWriteStreamable(const std::stringstream& str)
{
m_stream << str.str();
PostAtomicWrite();
}
const char *Emitter::ComputeFullBoolName(bool b) const
{
const EMITTER_MANIP mainFmt = (m_pState->GetBoolLengthFormat() == ShortBool ? YesNoBool : m_pState->GetBoolFormat());