| 373 | } |
| 374 | |
| 375 | func (self *cppPrinter) Run(g *Globals) *Stream { |
| 376 | |
| 377 | tpl, err := template.New("cpp").Parse(cppTemplate) |
| 378 | if err != nil { |
| 379 | log.Errorln(err) |
| 380 | return nil |
| 381 | } |
| 382 | |
| 383 | var m cppFileModel |
| 384 | |
| 385 | m.Namespace = g.FileDescriptor.Pragma.GetString("Package") |
| 386 | m.ToolVersion = g.Version |
| 387 | |
| 388 | // combinestruct的全局索引 |
| 389 | for _, ti := range g.GlobalIndexes { |
| 390 | |
| 391 | // 索引也限制 |
| 392 | if !ti.Index.Parent.File.MatchTag(".cpp") { |
| 393 | continue |
| 394 | } |
| 395 | |
| 396 | m.Indexes = append(m.Indexes, cppIndexField{TableIndex: ti}) |
| 397 | } |
| 398 | |
| 399 | // 遍历所有类型 |
| 400 | for _, d := range g.FileDescriptor.Descriptors { |
| 401 | |
| 402 | // 这给被限制输出 |
| 403 | if !d.File.MatchTag(".cpp") { |
| 404 | log.Infof("%s: %s", i18n.String(i18n.Printer_IgnoredByOutputTag), d.Name) |
| 405 | continue |
| 406 | } |
| 407 | |
| 408 | var sm cppStructModel |
| 409 | sm.Descriptor = d |
| 410 | |
| 411 | switch d.Kind { |
| 412 | case model.DescriptorKind_Struct: |
| 413 | m.Classes = append(m.Classes, &sm) |
| 414 | case model.DescriptorKind_Enum: |
| 415 | m.Enums = append(m.Enums, &sm) |
| 416 | } |
| 417 | |
| 418 | // 遍历字段 |
| 419 | for _, fd := range d.Fields { |
| 420 | |
| 421 | // 对CombineStruct的XXDefine对应的字段 |
| 422 | if d.Usage == model.DescriptorUsage_CombineStruct { |
| 423 | |
| 424 | // 这个字段被限制输出 |
| 425 | if fd.Complex != nil && !fd.Complex.File.MatchTag(".cpp") { |
| 426 | continue |
| 427 | } |
| 428 | |
| 429 | // 这个结构有索引才创建 |
| 430 | if fd.Complex != nil && len(fd.Complex.Indexes) > 0 { |
| 431 | |
| 432 | // 被索引的结构 |