• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonwindowsphpgamebathyscapheguic翻訳omegattwitterframeworkbtronvb.net計画中(planning stage)testdomarduinodirectxpreviewerゲームエンジン

超漢字アプリケーション開発用のProtocol Buffersコンパイラの開発


Commit MetaInfo

Revisão1169b6e4d090d3df0d5df150815be3a4cd1271a5 (tree)
Hora2015-03-05 01:25:09
Autorornse01 <ornse01@user...>
Commiterornse01

Mensagem de Log

change default value to getting from ruby object.

Mudança Sumário

Diff

--- a/src/protobuf/cgenerator.rb
+++ b/src/protobuf/cgenerator.rb
@@ -65,6 +65,41 @@ class Protobuf::CGenerator::Field
6565 end
6666 end
6767
68+ def c_default_value
69+ case @field_node.type
70+ when :double
71+ "0.0"
72+ when :float
73+ "0.0"
74+ when :int32
75+ "0"
76+ when :int64
77+ "0"
78+ when :uint32
79+ "0"
80+ when :uint64
81+ "0"
82+ when :sint32
83+ "0"
84+ when :sint64
85+ "0"
86+ when :fixed32
87+ "0"
88+ when :fixed64
89+ "0"
90+ when :sfixed32
91+ "0"
92+ when :sfixed64
93+ "0"
94+ when :bool
95+ "False"
96+ when :string
97+ ""
98+ when :bytes
99+ ""
100+ end
101+ end
102+
68103 def is_singular_numeric?
69104 ((@field_node.rule == :required)||(@field_node.rule == :optional))&&(@field_node.type.is_a? Symbol)&&(@field_node.type != :string)&&(@field_node.type != :bytes)
70105 end
--- a/src/protobuf/template.c.erb
+++ b/src/protobuf/template.c.erb
@@ -31,7 +31,7 @@ LOCAL VOID <%= m.name %>__initialize(<%= m.name %> *m)
3131 <%- m.each_field do |f| -%>
3232 <%- if f.is_singular_numeric? -%>
3333 m-><%= f.name %>_exist = False;
34- m-><%= f.name %> = 0;
34+ m-><%= f.name %> = <%= f.c_default_value %>;
3535 <%- end -%>
3636 <%- if f.is_singular_string? -%>
3737 m-><%= f.name %> = NULL;
@@ -92,7 +92,7 @@ EXPORT VOID <%= m.name %>__set_<%= f.name %>(<%= m.name %> *m, <%= f.to_c_type %
9292 EXPORT VOID <%= m.name %>__clear_<%= f.name %>(<%= m.name %> *m)
9393 {
9494 m-><%= f.name %>_exist = False;
95- m-><%= f.name %> = 0;
95+ m-><%= f.name %> = <%= f.c_default_value %>;
9696 }
9797
9898 <%- end -%>