forked from quickfix/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratorRuby.rb
More file actions
188 lines (167 loc) Β· 4.39 KB
/
GeneratorRuby.rb
File metadata and controls
188 lines (167 loc) Β· 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
class GeneratorRuby
def initialize(type, major, minor, sp, verid, dir)
@type = type
@major = major
@minor = minor
@sp = sp
@beginstring = type + "." + major + "." + minor
if @type == "FIX" && major >= "5"
@beginstring = "FIXT.1.1"
end
@depth = 0;
@dir = dir + "/"
if( sp != "0" )
@f = createFile( "quick" + type.downcase + major + minor + "sp#{sp}" + ".rb" )
else
@f = createFile( "quick" + type.downcase + major + minor + ".rb" )
end
@verid = verid
@messageStarted = false
end
def createFile(name)
attr = File::CREAT|File::TRUNC|File::RDWR
return File.new(@dir + name, attr, 0644)
end
def tabs
count = 0
result = ""
while (count != @depth)
result += "\t"
count += 1
end
return result
end
def front
@f.puts "require 'quickfix'"
if( @sp == "0" )
@f.puts "module Quickfix#{@major}#{@minor}"
else
@f.puts "module Quickfix#{@major}#{@minor}Sp#{@sp}"
end
end
def field(name, number)
end
def headerStart
end
def headerEnd
end
def trailerStart
end
def trailerEnd
end
def baseMessageStart
@f.puts tabs + "class Message < Quickfix::Message"
@depth += 1
@f.puts tabs + "def initialize"
@depth += 1
@f.puts tabs + "super"
@f.puts tabs + "getHeader().setField( Quickfix::BeginString.new(" + "\"" + @beginstring + "\"" + ") )"
if( @verid != "0" )
@f.puts tabs + "getHeader().setField( Quickfix::ApplVerID.new(" + "\"" + @verid + "\"" + ") )"
end
@depth -= 1
@f.puts tabs + "end"
@depth -= 1
end
def baseMessageEnd
@f.puts tabs + "end"
end
def groupStart(name, number, delim, order)
return if @messageStarted == false
@f.puts
@depth += 1
@f.puts tabs + "class " + name + " < Quickfix::Group"
@depth += 1
@f.puts tabs + "def initialize"
@depth += 1
@f.puts tabs + "order = Quickfix::IntArray.new(#{order.size+1})"
order.each_index { |i| @f.puts tabs + "order[#{i}] = #{order[i]}" }
@f.puts tabs + "order[#{order.size}] = 0"
@f.puts tabs + "super(#{number}, #{delim}, order)"
@depth -= 1
@f.puts tabs + "end"
@depth -= 1
end
def groupEnd
return if @messageStarted == false
@f.puts tabs + "end"
@depth -= 1
end
def messageStart(name, msgtype, required)
@messageStarted = true
@f.puts
@f.puts tabs + "class " + name + " < Message"
@depth += 1
@f.puts tabs + "def initialize"
@depth += 1
@f.puts tabs + "super"
@f.puts tabs + "getHeader().setField( Quickfix::MsgType.new(" + "\"" + msgtype + "\") )"
@depth -= 1
@f.puts tabs + "end"
@depth -= 1
end
def messageEnd
@messageStarted = false
@f.puts tabs + "end"
end
def fieldsStart
@f = createFile("quickfix_fields.rb")
@f.puts tabs + "module Quickfix"
@depth += 1
end
def fieldType( name, type )
return "CheckSum" if name == "CheckSum"
return "Char" if type == "CHAR"
return "Double" if type == "PRICE"
return "Int" if type == "INT"
return "Double" if type == "AMT"
return "Double" if type == "QTY"
return "UtcTimeStamp" if type == "UTCTIMESTAMP"
return "Bool" if type == "BOOLEAN"
return "Double" if type == "FLOAT"
return "Double" if type == "PRICEOFFSET"
return "UtcDate" if type == "UTCDATE"
return "UtcDate" if type == "UTCDATEONLY"
return "UtcTimeOnly" if type == "UTCTIMEONLY"
return "Int" if type == "NUMINGROUP"
return "Double" if type == "PERCENTAGE"
return "Int" if type == "SEQNUM"
return "Int" if type == "LENGTH"
return "String"
end
def fields(name, number, type, values)
@f.puts tabs + "class #{name} < Quickfix::#{fieldType(name, type)}Field"
@depth += 1
@f.puts tabs + "def #{name}.field"
@depth += 1
@f.puts tabs + "return #{number}"
@depth -= 1
@f.puts tabs + "end"
@depth -= 1
@depth += 1
@f.puts tabs + "def initialize(data = nil)"
@depth += 1
@f.puts tabs + "if( data == nil )"
@depth += 1
@f.puts tabs + "super(#{number})"
@depth -= 1
@f.puts tabs + "else"
@depth += 1
@f.puts tabs + "super(#{number}, data)"
@depth -= 1
@f.puts tabs + "end"
@depth -= 1
@f.puts tabs + "end"
@depth -= 1
@f.puts tabs + "end"
@f.puts
end
def fieldsEnd
@depth -= 1
@f.puts tabs + "end"
@f.close
end
def back
@f.puts tabs + "end"
end
end