本文整理汇总了Golang中github.com/kpmy/ot/otm.Object类的典型用法代码示例。如果您正苦于以下问题:Golang Object类的具体用法?Golang Object怎么用?Golang Object使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Object类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NameOf
func NameOf(o otm.Object) (ret string) {
if x, ok := o.Child(0); ok {
if s, ok := x.(string); ok {
ret = s
}
}
return
}
开发者ID:kpmy,项目名称:ot,代码行数:8,代码来源:load.go
示例2: ResolveContext
func ResolveContext(o otm.Object, resolver ResolverFunc, data map[string]interface{}) (err error) {
assert.For(!fn.IsNil(o), 20)
switch tpl := o.Qualident().Template; tpl {
case Core.TemplateName:
err = resolveContext(o.(*object), resolver, data)
default:
err = errors.New("nothing to resolve")
}
return
}
开发者ID:kpmy,项目名称:ot,代码行数:11,代码来源:imp.go
示例3: Resolve
func Resolve(o otm.Object) (err error) {
assert.For(!fn.IsNil(o), 20)
switch tpl := o.Qualident().Template; tpl {
case Core.TemplateName:
err = resolve(Core, o)
default:
err = errors.New("nothing to resolve")
}
return
}
开发者ID:kpmy,项目名称:ot,代码行数:11,代码来源:imp.go
示例4: prettyPrintObject
func prettyPrintObject(o otm.Object, log *testing.T) {
parent := ""
for x := o.Parent(); !fn.IsNil(x); x = x.Parent() {
parent = fmt.Sprint(x.Qualident(), "<-", parent)
}
log.Log(parent, o.Qualident())
if o.ChildrenCount() > 0 {
log.Log(":")
for _x := range o.Children() {
switch x := _x.(type) {
case otm.Object:
prettyPrintObject(x, log)
case otm.Link:
log.Log("@", x.Object().Qualident())
case string, float64, int64, rune, tri.Trit:
log.Log(_x)
case []uint8:
s := zbase32.EncodeToString(x)
log.Log("zbase32(", s, ")", x)
default:
halt.As(100, reflect.TypeOf(x))
}
}
log.Log(";")
}
}
开发者ID:kpmy,项目名称:ot,代码行数:26,代码来源:ot_test_stuff.go
示例5: object
func (f *fm) object(o otm.Object) {
q := o.Qualident()
if q.Template != "" {
f.Ident(q.Template)
f.Char('~')
}
f.Ident(q.Class)
if q.Identifier != "" {
f.Char('(')
f.Ident(q.Identifier)
f.Char(')')
}
if o.ChildrenCount() > 0 {
f.Char(':')
for _x := range o.Children() {
f.Char(' ')
switch x := _x.(type) {
case otm.Object:
f.object(x)
case string:
f.stringValue(x)
case int64:
i := strconv.Itoa(int(x))
f.RawString(i)
case float64:
if math.IsInf(x, 1) {
f.RawString("inf")
} else if math.IsInf(x, -1) {
f.RawString("-inf")
} else {
f_ := strconv.FormatFloat(x, 'f', 8, 64)
f.RawString(f_)
}
case rune:
r := strconv.FormatUint(uint64(x), 16)
f.RawString("0" + r + "U")
case tri.Trit:
f.Trinary(x)
case []uint8:
f.RawString(zbase32.EncodeToString(x))
default:
halt.As(100, reflect.TypeOf(x))
}
}
f.Char(';')
} else {
f.Char(' ')
}
}
开发者ID:kpmy,项目名称:ot,代码行数:49,代码来源:g.go
示例6: renderHtml
func renderHtml(o otm.Object, log *testing.T) {
buf := bytes.NewBufferString("<!DOCTYPE HTML>")
e := xml.NewEncoder(buf)
var obj func(otm.Object)
obj = func(o otm.Object) {
clazz := o.InstanceOf().Qualident()
if clazz.Template == "html" {
start := xml.StartElement{}
start.Name.Local = clazz.Class
if id := o.Qualident().Identifier; id != "" {
attr := xml.Attr{}
attr.Name.Local = "id"
attr.Value = id
start.Attr = append(start.Attr, attr)
}
e.EncodeToken(start)
for _x := range o.Children() {
switch x := _x.(type) {
case otm.Object:
obj(x)
case string:
e.EncodeToken(xml.CharData([]byte(x)))
default:
halt.As(100, reflect.TypeOf(x))
}
}
e.EncodeToken(start.End())
}
}
for x := range o.ChildrenObjects() {
if x.InstanceOf().Qualident().Template == "html" && x.InstanceOf().Qualident().Class == "html" {
obj(x)
}
}
e.Flush()
log.Log(buf.String())
}
开发者ID:kpmy,项目名称:ot,代码行数:38,代码来源:ot_test_stuff.go
示例7: resolve
func resolve(t *ForeignTemplate, o otm.Object) (err error) {
assert.For(!fn.IsNil(o), 20)
var processList []pfunc
var upd func(t *ForeignTemplate, o otm.Object)
upd = func(t *ForeignTemplate, o otm.Object) {
if clazz, ok := t.Classes[o.Qualident().Class]; ok && (o.Qualident().Template == t.TemplateName || o.Qualident().Template == "") {
inst := clazz.copyOf()
o.InstanceOf(inst)
if fn := inst.apply(o); fn != nil {
processList = append(processList, fn)
}
//log.Println("class updated for", o.Qualident(), " set ", clazz.Qualident())
}
for x := range o.ChildrenObjects() {
upd(t, x)
}
}
upd(t, o)
for tmp := processList; len(tmp) > 0; {
var _tmp []pfunc
for _, f := range tmp {
var p pfunc
if p, err = f(); err == nil && p != nil {
_tmp = append(_tmp, p)
} else if err != nil {
_tmp = nil
break
}
}
tmp = _tmp
}
return
}
开发者ID:kpmy,项目名称:ot,代码行数:36,代码来源:imp.go
示例8: forEach
func (w *Walker) forEach(o otm.Object, do func(w *Walker, o otm.Object)) {
for v := range o.ChildrenObjects() {
do(w, v)
}
}
开发者ID:kpmy,项目名称:ot,代码行数:5,代码来源:load.go
示例9: traverse
func (w *Walker) traverse(o otm.Object) {
var (
this schema.Guide
skip *bool
skipped = func() {
s := true
skip = &s
}
important = func() {
s := false
skip = &s
}
)
switch o.Qualident().Class {
//structure elements
case "grammar":
skipped()
if start := o.FindByQualident(otm.Qualident{Template: "ng", Class: "start"}); start != nil {
w.forEach(start[0], traverseWrap())
}
case "ref":
skipped()
panic(0)
/* if ref := w.root.FindByName(n.Name); ref != nil {
if cached := w.cache[n.Name]; cached == nil {
this = Construct(n.XMLName)
{
std.NameAttr(this, n.Name)
//std.RefAttr(this, cached.root)
}
w.cache[n.Name] = &Cached{node: ref, root: this}
w.GrowDown(this)
w.forEach(ref, traverseWrap())
w.Up()
} else {
w.Grow(cached.root)
}
} else {
halt.As(100, "ref not found", n.Name)
}
*/
//content elements
case "element", "attribute", "data", "text", "value", "name", "param":
fallthrough
//constraint elements
case "choice", "interleave", "optional", "zeroOrMore", "oneOrMore", "group", "list", "mixed", "except", "anyName", "nsName", "empty", "externalRef":
important()
this = Construct(o.Qualident())
{
std.NameAttr(this, NameOf(o))
/*std.CharDataAttr(this, n.Data())
std.TypeAttr(this, n.Type)
std.NSAttr(this, n.NS)
std.DataTypeAttr(this, n.DataType)
std.CombineAttr(this, n.Combine)
std.HrefAttr(this, n.Href)
*/
}
w.GrowDown(this)
w.forEach(o, traverseWrap())
w.Up()
//skipped elements
case "description": //descriprion do nothing
default:
halt.As(100, o.Qualident())
}
if skip != nil {
assert.For(*skip || this != nil, 60, "no result for ", o.Qualident())
} else if this == nil {
log.Println("unhandled", o.Qualident())
}
}
开发者ID:kpmy,项目名称:ot,代码行数:73,代码来源:load.go
示例10: copyOf
func copyOf(o otm.Object) otm.Producer {
return func(...otm.Modifier) otm.Object {
return o.CopyOf(otm.DEEP)
}
}
开发者ID:kpmy,项目名称:ot,代码行数:5,代码来源:i2m.go
注:本文中的github.com/kpmy/ot/otm.Object类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论