2009-07-30 02:27:20 +04:00
|
|
|
#ifndef EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
|
|
|
#define EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
|
|
|
|
2011-09-06 09:16:03 +04:00
|
|
|
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
2011-03-02 09:11:41 +03:00
|
|
|
#pragma once
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-07-30 02:27:20 +04:00
|
|
|
|
2011-03-03 11:11:14 +03:00
|
|
|
#include "ptr_stack.h"
|
2009-05-23 01:52:31 +04:00
|
|
|
#include "setting.h"
|
2010-10-18 11:05:53 +04:00
|
|
|
#include "yaml-cpp/emittermanip.h"
|
2009-05-23 01:52:31 +04:00
|
|
|
#include <cassert>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <stack>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace YAML
|
|
|
|
|
{
|
2012-05-22 00:05:17 +04:00
|
|
|
struct FmtScope { enum value { Local, Global }; };
|
|
|
|
|
struct GroupType { enum value { None, Seq, Map }; };
|
|
|
|
|
struct FlowType { enum value { None, Flow, Block }; };
|
|
|
|
|
|
2009-05-23 01:52:31 +04:00
|
|
|
class EmitterState
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
EmitterState();
|
|
|
|
|
~EmitterState();
|
|
|
|
|
|
|
|
|
|
// basic state checking
|
|
|
|
|
bool good() const { return m_isGood; }
|
|
|
|
|
const std::string GetLastError() const { return m_lastError; }
|
|
|
|
|
void SetError(const std::string& error) { m_isGood = false; m_lastError = error; }
|
|
|
|
|
|
|
|
|
|
// group handling
|
2012-05-22 00:05:17 +04:00
|
|
|
void BeginGroup(GroupType::value type);
|
|
|
|
|
void EndGroup(GroupType::value type);
|
2009-05-23 01:52:31 +04:00
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
GroupType::value GetCurGroupType() const;
|
|
|
|
|
FlowType::value GetCurGroupFlowType() const;
|
2009-05-23 01:52:31 +04:00
|
|
|
int GetCurIndent() const { return m_curIndent; }
|
|
|
|
|
|
|
|
|
|
void ClearModifiedSettings();
|
|
|
|
|
|
|
|
|
|
// formatters
|
2012-05-22 01:31:07 +04:00
|
|
|
void SetLocalValue(EMITTER_MANIP value);
|
|
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope);
|
2009-10-20 03:31:11 +04:00
|
|
|
EMITTER_MANIP GetOutputCharset() const { return m_charset.get(); }
|
|
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetStringFormat(EMITTER_MANIP value, FmtScope::value scope);
|
2009-05-23 01:52:31 +04:00
|
|
|
EMITTER_MANIP GetStringFormat() const { return m_strFmt.get(); }
|
|
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope);
|
2009-05-23 01:52:31 +04:00
|
|
|
EMITTER_MANIP GetBoolFormat() const { return m_boolFmt.get(); }
|
|
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope);
|
2009-05-23 01:52:31 +04:00
|
|
|
EMITTER_MANIP GetBoolLengthFormat() const { return m_boolLengthFmt.get(); }
|
|
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope);
|
2009-05-23 01:52:31 +04:00
|
|
|
EMITTER_MANIP GetBoolCaseFormat() const { return m_boolCaseFmt.get(); }
|
|
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetIntFormat(EMITTER_MANIP value, FmtScope::value scope);
|
2009-05-23 01:52:31 +04:00
|
|
|
EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); }
|
|
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetIndent(unsigned value, FmtScope::value scope);
|
2009-05-23 01:52:31 +04:00
|
|
|
int GetIndent() const { return m_indent.get(); }
|
|
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetPreCommentIndent(unsigned value, FmtScope::value scope);
|
2009-05-23 01:52:31 +04:00
|
|
|
int GetPreCommentIndent() const { return m_preCommentIndent.get(); }
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetPostCommentIndent(unsigned value, FmtScope::value scope);
|
2009-05-23 01:52:31 +04:00
|
|
|
int GetPostCommentIndent() const { return m_postCommentIndent.get(); }
|
|
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value, FmtScope::value scope);
|
|
|
|
|
EMITTER_MANIP GetFlowType(GroupType::value groupType) const;
|
2009-05-23 01:52:31 +04:00
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope);
|
2009-05-23 01:52:31 +04:00
|
|
|
EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); }
|
2012-01-12 00:34:04 +04:00
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetFloatPrecision(int value, FmtScope::value scope);
|
2012-01-12 00:34:04 +04:00
|
|
|
unsigned GetFloatPrecision() const { return m_floatPrecision.get(); }
|
2012-05-22 00:05:17 +04:00
|
|
|
bool SetDoublePrecision(int value, FmtScope::value scope);
|
2012-01-12 00:34:04 +04:00
|
|
|
unsigned GetDoublePrecision() const { return m_doublePrecision.get(); }
|
2009-05-23 01:52:31 +04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
template <typename T>
|
2012-05-22 00:05:17 +04:00
|
|
|
void _Set(Setting<T>& fmt, T value, FmtScope::value scope);
|
2009-05-23 01:52:31 +04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// basic state ok?
|
|
|
|
|
bool m_isGood;
|
|
|
|
|
std::string m_lastError;
|
|
|
|
|
|
|
|
|
|
// other state
|
2011-03-03 11:11:14 +03:00
|
|
|
Setting<EMITTER_MANIP> m_charset;
|
|
|
|
|
Setting<EMITTER_MANIP> m_strFmt;
|
|
|
|
|
Setting<EMITTER_MANIP> m_boolFmt;
|
|
|
|
|
Setting<EMITTER_MANIP> m_boolLengthFmt;
|
|
|
|
|
Setting<EMITTER_MANIP> m_boolCaseFmt;
|
|
|
|
|
Setting<EMITTER_MANIP> m_intFmt;
|
|
|
|
|
Setting<unsigned> m_indent;
|
|
|
|
|
Setting<unsigned> m_preCommentIndent, m_postCommentIndent;
|
|
|
|
|
Setting<EMITTER_MANIP> m_seqFmt;
|
|
|
|
|
Setting<EMITTER_MANIP> m_mapFmt;
|
|
|
|
|
Setting<EMITTER_MANIP> m_mapKeyFmt;
|
2012-01-12 02:50:06 +04:00
|
|
|
Setting<int> m_floatPrecision;
|
|
|
|
|
Setting<int> m_doublePrecision;
|
2009-05-23 01:52:31 +04:00
|
|
|
|
|
|
|
|
SettingChanges m_modifiedSettings;
|
|
|
|
|
SettingChanges m_globalModifiedSettings;
|
|
|
|
|
|
|
|
|
|
struct Group {
|
2012-05-22 01:31:07 +04:00
|
|
|
Group(GroupType::value type_): type(type_), indent(0) {}
|
2009-05-23 01:52:31 +04:00
|
|
|
|
2012-05-22 00:05:17 +04:00
|
|
|
GroupType::value type;
|
2009-05-23 01:52:31 +04:00
|
|
|
EMITTER_MANIP flow;
|
|
|
|
|
int indent;
|
|
|
|
|
|
|
|
|
|
SettingChanges modifiedSettings;
|
|
|
|
|
};
|
2011-03-03 11:11:14 +03:00
|
|
|
|
|
|
|
|
ptr_stack<Group> m_groups;
|
2009-05-23 01:52:31 +04:00
|
|
|
unsigned m_curIndent;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2012-05-22 00:05:17 +04:00
|
|
|
void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
|
2009-05-23 01:52:31 +04:00
|
|
|
switch(scope) {
|
2012-05-22 00:05:17 +04:00
|
|
|
case FmtScope::Local:
|
2009-05-23 01:52:31 +04:00
|
|
|
m_modifiedSettings.push(fmt.set(value));
|
|
|
|
|
break;
|
2012-05-22 00:05:17 +04:00
|
|
|
case FmtScope::Global:
|
2009-05-23 01:52:31 +04:00
|
|
|
fmt.set(value);
|
|
|
|
|
m_globalModifiedSettings.push(fmt.set(value)); // this pushes an identity set, so when we restore,
|
|
|
|
|
// it restores to the value here, and not the previous one
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-30 02:27:20 +04:00
|
|
|
|
|
|
|
|
#endif // EMITTERSTATE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|