Browse code

A complete refactor/rewrite of the original seqbias code. This should behave more or less identically, but is much more coherent.

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/seqbias@57223 bc3139a8-67e5-0310-9ffc-ced21a209358

Daniel Jones authored on 04/08/2011 07:36:48
Showing1 changed files
... ...
@@ -1,12 +1,16 @@
1
-#pragma once
2
-
3 1
 #ifndef EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4 2
 #define EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
5 3
 
4
+#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
5
+#pragma once
6
+#endif
7
+
6 8
 
7
-#include "emittermanip.h"
8
-#include "ostream.h"
9
-#include "null.h"
9
+#include "yaml-cpp/dll.h"
10
+#include "yaml-cpp/emittermanip.h"
11
+#include "yaml-cpp/ostream.h"
12
+#include "yaml-cpp/noncopyable.h"
13
+#include "yaml-cpp/null.h"
10 14
 #include <memory>
11 15
 #include <string>
12 16
 #include <sstream>
... ...
@@ -15,7 +19,7 @@ namespace YAML
15 19
 {
16 20
 	class EmitterState;
17 21
 	
18
-	class Emitter
22
+	class YAML_CPP_API Emitter: private noncopyable
19 23
 	{
20 24
 	public:
21 25
 		Emitter();
... ...
@@ -52,6 +56,7 @@ namespace YAML
52 56
 		Emitter& Write(const _Tag& tag);
53 57
 		Emitter& Write(const _Comment& comment);
54 58
 		Emitter& Write(const _Null& null);
59
+		Emitter& Write(const _Binary& binary);
55 60
 		
56 61
 		template <typename T>
57 62
 		Emitter& WriteIntegralType(T value);
... ...
@@ -61,7 +66,9 @@ namespace YAML
61 66
 
62 67
 	private:
63 68
 		void PreWriteIntegralType(std::stringstream& str);
69
+		void PreWriteStreamable(std::stringstream& str);
64 70
 		void PostWriteIntegralType(const std::stringstream& str);
71
+		void PostWriteStreamable(const std::stringstream& str);
65 72
 	
66 73
 	private:
67 74
 		enum ATOMIC_TYPE { AT_SCALAR, AT_SEQ, AT_BLOCK_SEQ, AT_FLOW_SEQ, AT_MAP, AT_BLOCK_MAP, AT_FLOW_MAP };
... ...
@@ -71,12 +78,20 @@ namespace YAML
71 78
 		void PostAtomicWrite();
72 79
 		void EmitSeparationIfNecessary();
73 80
 		
81
+		void EmitBeginDoc();
82
+		void EmitEndDoc();
74 83
 		void EmitBeginSeq();
75 84
 		void EmitEndSeq();
76 85
 		void EmitBeginMap();
77 86
 		void EmitEndMap();
78 87
 		void EmitKey();
79 88
 		void EmitValue();
89
+		void EmitNewline();
90
+		void EmitKindTag();
91
+		void EmitTag(bool verbatim, const _Tag& tag);
92
+		
93
+		const char *ComputeFullBoolName(bool b) const;
94
+		bool CanEmitNewline() const;
80 95
 		
81 96
 	private:
82 97
 		ostream m_stream;
... ...
@@ -102,14 +117,10 @@ namespace YAML
102 117
 		if(!good())
103 118
 			return *this;
104 119
 		
105
-		PreAtomicWrite();
106
-		EmitSeparationIfNecessary();
107
-		
108 120
 		std::stringstream str;
121
+		PreWriteStreamable(str);
109 122
 		str << value;
110
-		m_stream << str.str();
111
-		
112
-		PostAtomicWrite();
123
+		PostWriteStreamable(str);
113 124
 		return *this;
114 125
 	}
115 126
 	
... ...
@@ -121,6 +132,7 @@ namespace YAML
121 132
 	inline Emitter& operator << (Emitter& emitter, const _Tag& v) { return emitter.Write(v); }
122 133
 	inline Emitter& operator << (Emitter& emitter, const _Comment& v) { return emitter.Write(v); }
123 134
 	inline Emitter& operator << (Emitter& emitter, const _Null& v) { return emitter.Write(v); }
135
+	inline Emitter& operator << (Emitter& emitter, const _Binary& b) { return emitter.Write(b); }
124 136
 
125 137
 	inline Emitter& operator << (Emitter& emitter, const char *v) { return emitter.Write(std::string(v)); }
126 138
 
... ...
@@ -130,6 +142,8 @@ namespace YAML
130 142
 	inline Emitter& operator << (Emitter& emitter, unsigned short v) { return emitter.WriteIntegralType(v); }
131 143
 	inline Emitter& operator << (Emitter& emitter, long v) { return emitter.WriteIntegralType(v); }
132 144
 	inline Emitter& operator << (Emitter& emitter, unsigned long v) { return emitter.WriteIntegralType(v); }
145
+	inline Emitter& operator << (Emitter& emitter, long long v) { return emitter.WriteIntegralType(v); }
146
+	inline Emitter& operator << (Emitter& emitter, unsigned long long v) { return emitter.WriteIntegralType(v); }
133 147
 
134 148
 	inline Emitter& operator << (Emitter& emitter, float v) { return emitter.WriteStreamable(v); }
135 149
 	inline Emitter& operator << (Emitter& emitter, double v) { return emitter.WriteStreamable(v); }
Browse code

Added the seqbias package to the repository.

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/seqbias@52013 bc3139a8-67e5-0310-9ffc-ced21a209358

Chao-Jen Wong authored on 22/01/2011 00:26:36
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,146 @@
1
+#pragma once
2
+
3
+#ifndef EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4
+#define EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
5
+
6
+
7
+#include "emittermanip.h"
8
+#include "ostream.h"
9
+#include "null.h"
10
+#include <memory>
11
+#include <string>
12
+#include <sstream>
13
+
14
+namespace YAML
15
+{
16
+	class EmitterState;
17
+	
18
+	class Emitter
19
+	{
20
+	public:
21
+		Emitter();
22
+		~Emitter();
23
+		
24
+		// output
25
+		const char *c_str() const;
26
+		unsigned size() const;
27
+		
28
+		// state checking
29
+		bool good() const;
30
+		const std::string GetLastError() const;
31
+		
32
+		// global setters
33
+		bool SetOutputCharset(EMITTER_MANIP value);
34
+		bool SetStringFormat(EMITTER_MANIP value);
35
+		bool SetBoolFormat(EMITTER_MANIP value);
36
+		bool SetIntBase(EMITTER_MANIP value);
37
+		bool SetSeqFormat(EMITTER_MANIP value);
38
+		bool SetMapFormat(EMITTER_MANIP value);
39
+		bool SetIndent(unsigned n);
40
+		bool SetPreCommentIndent(unsigned n);
41
+		bool SetPostCommentIndent(unsigned n);
42
+		
43
+		// local setters
44
+		Emitter& SetLocalValue(EMITTER_MANIP value);
45
+		Emitter& SetLocalIndent(const _Indent& indent);
46
+		
47
+		// overloads of write
48
+		Emitter& Write(const std::string& str);
49
+		Emitter& Write(bool b);
50
+		Emitter& Write(const _Alias& alias);
51
+		Emitter& Write(const _Anchor& anchor);
52
+		Emitter& Write(const _Tag& tag);
53
+		Emitter& Write(const _Comment& comment);
54
+		Emitter& Write(const _Null& null);
55
+		
56
+		template <typename T>
57
+		Emitter& WriteIntegralType(T value);
58
+		
59
+		template <typename T>
60
+		Emitter& WriteStreamable(T value);
61
+
62
+	private:
63
+		void PreWriteIntegralType(std::stringstream& str);
64
+		void PostWriteIntegralType(const std::stringstream& str);
65
+	
66
+	private:
67
+		enum ATOMIC_TYPE { AT_SCALAR, AT_SEQ, AT_BLOCK_SEQ, AT_FLOW_SEQ, AT_MAP, AT_BLOCK_MAP, AT_FLOW_MAP };
68
+		
69
+		void PreAtomicWrite();
70
+		bool GotoNextPreAtomicState();
71
+		void PostAtomicWrite();
72
+		void EmitSeparationIfNecessary();
73
+		
74
+		void EmitBeginSeq();
75
+		void EmitEndSeq();
76
+		void EmitBeginMap();
77
+		void EmitEndMap();
78
+		void EmitKey();
79
+		void EmitValue();
80
+		
81
+	private:
82
+		ostream m_stream;
83
+		std::auto_ptr <EmitterState> m_pState;
84
+	};
85
+	
86
+	template <typename T>
87
+	inline Emitter& Emitter::WriteIntegralType(T value)
88
+	{
89
+		if(!good())
90
+			return *this;
91
+		
92
+		std::stringstream str;
93
+		PreWriteIntegralType(str);
94
+		str << value;
95
+		PostWriteIntegralType(str);
96
+		return *this;
97
+	}
98
+
99
+	template <typename T>
100
+	inline Emitter& Emitter::WriteStreamable(T value)
101
+	{
102
+		if(!good())
103
+			return *this;
104
+		
105
+		PreAtomicWrite();
106
+		EmitSeparationIfNecessary();
107
+		
108
+		std::stringstream str;
109
+		str << value;
110
+		m_stream << str.str();
111
+		
112
+		PostAtomicWrite();
113
+		return *this;
114
+	}
115
+	
116
+	// overloads of insertion
117
+	inline Emitter& operator << (Emitter& emitter, const std::string& v) { return emitter.Write(v); }
118
+	inline Emitter& operator << (Emitter& emitter, bool v) { return emitter.Write(v); }
119
+	inline Emitter& operator << (Emitter& emitter, const _Alias& v) { return emitter.Write(v); }
120
+	inline Emitter& operator << (Emitter& emitter, const _Anchor& v) { return emitter.Write(v); }
121
+	inline Emitter& operator << (Emitter& emitter, const _Tag& v) { return emitter.Write(v); }
122
+	inline Emitter& operator << (Emitter& emitter, const _Comment& v) { return emitter.Write(v); }
123
+	inline Emitter& operator << (Emitter& emitter, const _Null& v) { return emitter.Write(v); }
124
+
125
+	inline Emitter& operator << (Emitter& emitter, const char *v) { return emitter.Write(std::string(v)); }
126
+
127
+	inline Emitter& operator << (Emitter& emitter, int v) { return emitter.WriteIntegralType(v); }
128
+	inline Emitter& operator << (Emitter& emitter, unsigned int v) { return emitter.WriteIntegralType(v); }
129
+	inline Emitter& operator << (Emitter& emitter, short v) { return emitter.WriteIntegralType(v); }
130
+	inline Emitter& operator << (Emitter& emitter, unsigned short v) { return emitter.WriteIntegralType(v); }
131
+	inline Emitter& operator << (Emitter& emitter, long v) { return emitter.WriteIntegralType(v); }
132
+	inline Emitter& operator << (Emitter& emitter, unsigned long v) { return emitter.WriteIntegralType(v); }
133
+
134
+	inline Emitter& operator << (Emitter& emitter, float v) { return emitter.WriteStreamable(v); }
135
+	inline Emitter& operator << (Emitter& emitter, double v) { return emitter.WriteStreamable(v); }
136
+
137
+	inline Emitter& operator << (Emitter& emitter, EMITTER_MANIP value) {
138
+		return emitter.SetLocalValue(value);
139
+	}
140
+	
141
+	inline Emitter& operator << (Emitter& emitter, _Indent indent) {
142
+		return emitter.SetLocalIndent(indent);
143
+	}
144
+}
145
+
146
+#endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66