Files
five/hbrdd/base.go
Charles KWON OhJun 59568f3301 Five v0.9 — Harbour + Go fusion language
- Compiler: PP → Lexer → Parser → Analyzer → Gengo pipeline
- Parser: 232/236 (98%) Harbour compatibility, registry-based dispatch
- RTL: 351 Harbour-compatible functions
- RDD: DBF/NTX/CDX engines with Rushmore bitmap optimization
- Go Interop: IMPORT + pkg.Func() + obj:Method() with FastPath (15M calls/sec)
- HB_FUNC API: Full Harbour C API compatible Go bridge
- Concurrency: SPAWN/LAUNCH/GOROUTINE, <-, WATCH, PARALLEL FOR, ASYNC/AWAIT
- Extensions: Multi-return, DEFER, Slice, f-string, Nil-safe ?:, CONST
- Macro Compiler: Runtime AST parsing and evaluation
- Debugger: TUI debugger with source display, breakpoints, stepping
- FRB: Native + Pcode dual mode runtime binary
- Tests: 13 packages ALL PASS

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 09:41:50 +09:00

123 lines
2.9 KiB
Go

// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com)
// All rights reserved.
// BaseArea provides default implementations for the Area interface.
// Harbour equivalent: WAAREA (workarea.c) — ~25 real + ~76 stub methods.
// Concrete drivers (DBFArea, etc.) embed BaseArea and override as needed.
package hbrdd
import "five/hbrt"
// BaseArea is the base workarea with default flag management.
// Harbour: struct _AREA in hbapirdd.h
type BaseArea struct {
driver Driver
alias string
fields []FieldInfo
fieldMap map[string]int // field name → index (0-based)
// Cursor state flags — Harbour: fBof, fEof, fFound, fTop, fBottom
FBof bool
FEof bool
FFound bool
FTop bool
FBottom bool
// Filter
filterExpr string
filterBlock func(*hbrt.Thread) bool
// Relations
relations []*Relation
}
// Relation holds a parent→child relationship.
type Relation struct {
Child Area
KeyExpr func(*hbrt.Thread) hbrt.Value
Scoped bool
}
// --- BaseArea default implementations ---
func (a *BaseArea) Driver() Driver { return a.driver }
func (a *BaseArea) Alias() string { return a.alias }
func (a *BaseArea) BOF() bool { return a.FBof }
func (a *BaseArea) EOF() bool { return a.FEof }
func (a *BaseArea) Found() bool { return a.FFound }
func (a *BaseArea) SetFound(b bool) { a.FFound = b }
func (a *BaseArea) FieldCount() int { return len(a.fields) }
func (a *BaseArea) GetFieldInfo(index int) FieldInfo {
if index >= 0 && index < len(a.fields) {
return a.fields[index]
}
return FieldInfo{}
}
// FieldIndex returns the 0-based field index by name, or -1 if not found.
func (a *BaseArea) FieldIndex(name string) int {
if a.fieldMap == nil {
return -1
}
if idx, ok := a.fieldMap[name]; ok {
return idx
}
return -1
}
// InitFields sets up the field array and name→index map.
func (a *BaseArea) InitFields(fields []FieldInfo) {
a.fields = fields
a.fieldMap = make(map[string]int, len(fields))
for i, f := range fields {
a.fieldMap[f.Name] = i
}
}
// Close provides the base close behavior (reset flags).
// Harbour: hb_waClose
func (a *BaseArea) Close() error {
a.FBof = true
a.FEof = true
a.FFound = false
a.fields = nil
a.fieldMap = nil
a.relations = nil
return nil
}
// --- Filter support ---
func (a *BaseArea) SetFilter(expr string, block func(*hbrt.Thread) bool) error {
a.filterExpr = expr
a.filterBlock = block
return nil
}
func (a *BaseArea) ClearFilter() error {
a.filterExpr = ""
a.filterBlock = nil
return nil
}
func (a *BaseArea) HasFilter() bool {
return a.filterBlock != nil
}
// --- Relation support ---
func (a *BaseArea) SetRelation(child Area, keyExpr func(*hbrt.Thread) hbrt.Value, scoped bool) error {
a.relations = append(a.relations, &Relation{
Child: child,
KeyExpr: keyExpr,
Scoped: scoped,
})
return nil
}
func (a *BaseArea) ClearRelation() error {
a.relations = nil
return nil
}