Class ::nx::serializer::Serializer

::nx::serializer::Serializer[i] create ... \
           [ -ignoreVarsRE ignoreVarsRE ]

Class Relations

  • class: ::nx::Class[i]
  • superclass: ::nx::Object[i]
::nx::Class create ::nx::serializer::Serializer \
     -superclass ::nx::Object

Methods (to be applied on the object)

  • addPattern (scripted)

    set :ignorePattern($p) 1
  • all (scripted)

    catch ::xo::at_cleanup
    
    # don't filter anything during serialization
    set filterstate [::nsf::configure filter off]
    set s [:new -childof [::nsf::current object]]
    if {[info exists ignoreVarsRE]} {$s ignoreVarsRE set $ignoreVarsRE}
    if {[info exists ignore]} {$s ignore $ignore}
    
    set r [subst {
      set ::nsf::__filterstate \[::nsf::configure filter off\]
      #::nx::Slot mixin add ::nx::Slot::Nocheck
      ::nsf::exithandler set [list [::nsf::exithandler get]]
    }]
    foreach option {debug softrecreate keepcmds checkresults checkarguments} {
      append r \t [list ::nsf::configure $option [::nsf::configure $option]] \n
    }
    :resetPattern
    
    #
    # export all nsf_procs
    #
    append r [:export_nsfprocs ::]
    
    #
    # export objects and classes
    #
    set instances [list]
    foreach oss [ObjectSystemSerializer info instances] {
      append r [$oss serialize-all-start $s]
      lappend instances {*}[$oss instances $s]
    }
    
    # provide error messages for invalid exports
    :checkExportedMethods
    
    # export the objects and classes
    #$s warn "export objects = [array names :exportObjects]"
    #$s warn "export objects = [array names :exportMethods]"
    
    append r [$s serialize-objects $instances 0]
    
    foreach oss [ObjectSystemSerializer info instances] {
      append r [$oss serialize-all-end $s]
    }
    $s destroy
    
    append r {
      #::nx::Slot mixin delete ::nx::Slot::Nocheck
      ::nsf::configure filter $::nsf::__filterstate
      unset ::nsf::__filterstate
    }
    ::nsf::configure filter $filterstate
    
    return $r
  • allChildren (scripted)

    set set [::nsf::directdispatch $o -frame method ::nsf::current]
    foreach c [::nsf::directdispatch $o ::nsf::methods::object::info::children] {
      lappend set {*}[:allChildren $c]
    }
    return $set
  • application_namespaces (scripted)

    set :namespaces ""
    :add_child_namespaces $ns
    return ${:namespaces}
  • deepSerialize (scripted)

    :resetPattern
    set s [:new -childof [::nsf::current object]]
    if {[info exists ignoreVarsRE]} {$s ignoreVarsRE set $ignoreVarsRE}
    if {[info exists ignore]} {$s ignore $ignore}
    if {[info exists objmap]} {$s objmap $objmap}
    foreach o $args {
      append r [$s deepSerialize [::nsf::directdispatch $o -frame method ::nsf::current]]
    }
    $s destroy
    if {[info exists map]} {return [string map $map $r]}
    return $r
  • exportMethods (scripted)

    foreach {o p m} $list {set :exportMethods([list $o $p $m]) 1}
  • exportObjects (scripted)

    foreach o $list {set :exportObjects($o) 1}
  • export_nsfprocs (scripted)

    set result ""
    foreach n [:application_namespaces $ns] {
      foreach p [:info methods -type nsfproc ${n}::*] {
        append result [::nsf::cmd::info definition $p] \n
      }
    }
    return $result
  • exportedMethods (scripted)

    array names :exportMethods
  • exportedObjects (scripted)

    array names :exportObjects
  • finalize_application_classes (scripted)

    set objs [$oss list_instances]
    #puts stderr "///// we have [llength $objs] $objs"
    #set objs [$Object info instances -closure]
    #
    # Delete first object but no classes, such that the destroy
    # methods can be executed in most cases.
    #
    foreach o $objs {
      if {![nsf::is object $o] || [nsf::is class $o]} {
        continue
      }
      catch {rename $o ""} errorMsg
    }
    
    #
    # Delete the surving classes.
    #
    set objs [$oss list_instances]
    #puts stderr "///// we have [llength $objs] $objs"
    foreach o $objs {
      set ns [namespace qualifiers $o]
      #puts stderr "DELETE class $o ns <$ns>"
      if {![nsf::is class $o] || [nsf::is metaclass $o] } {
        continue
      }
      catch {rename $o ""} errorMsg
    }
    #
    # Delete the metaclasses at the end.
    #
    set objs [$oss list_instances]
    #puts stderr "///// we have [llength $objs] $objs"
    foreach o $objs {
      set ns [namespace qualifiers $o]
      #puts stderr "DELETE class $o ns <$ns>"
      if {![nsf::is metaclass $o]} {
        continue
      }
      catch {rename $o ""} errorMsg
    }
  • methodSerialize (scripted)

    foreach oss [ObjectSystemSerializer info instances] {
      if {[$oss responsibleSerializer $object]} {
        set result [$oss serializeExportedMethod $object $prefix $method [self]]
        break
      }
    }
    return $result
  • resetPattern (scripted)

    array unset :ignorePattern

Methods (to be applied on instances)

  • addPostCmd (scripted)

    if {$cmd ne ""} {append :post_cmds $cmd "\n"}
  • deepSerialize (scripted)

    set instances [Serializer allChildren $o]
    foreach oss [ObjectSystemSerializer info instances] {
      $oss registerSerializer [::nsf::current object] $instances
    }
    :serialize-objects $instances 1
  • getTargetName (scripted)

    if {![string match ::* $sourceName]} {
      set sourceName ::$sourceName
    }
    set targetName $sourceName
    if {[array exists :objmap]} {
      foreach {source target} [array get :objmap] {
        #puts "[list regsub ^$source $targetName $target targetName]"
        regsub ^$source $targetName $target targetName
      }
    }
    
    #puts stderr "targetName of <$sourceName> = <$targetName>"
    
    return $targetName
  • ignore (scripted)

    foreach element $args {
      foreach o [Serializer allChildren $element] {
        set :skip($o) 1
      }
    }
  • ignoreVarsRE (forward)

  • isExportedObject (scripted)

    set oo $o
    while {1} {
      if {[::nsf::var::exists [::nsf::current class] exportObjects($o)]} {
        return 1
      }
      # we do this for object trees without object-less namespaces
      if {![::nsf::object::exists $o]} {
        return 0
      }
      set o [::nsf::dispatch $o ::nsf::methods::object::info::parent]
    }
  • needsOneOf (scripted)

    foreach e $list {if {[info exists :s($e)]} {return 1}}
    return 0
  • objmap (scripted)

    array set :objmap $map
  • serialize-objects (scripted)

    set :post_cmds ""
    
    :topoSort $list $all
    #foreach i [lsort [array names :level]] { :warn "$i: [set :level($i)]"}
    set result ""
    foreach l [lsort -integer [array names :level]] {
      foreach i [set :level($l)] {
        #:warn "serialize $i"
        #append result "# Stratum $l\n"
        set oss [set :serializer($i)]
        append result [$oss serialize $i [::nsf::current object]] \n
      }
    }
    foreach e $list {
      set namespace($e) 1
      set namespace([namespace qualifiers $e]) 1
    }
    
    # Handling of variable traces: traces might require a
    # different topological sort, which is hard to handle.
    # Similar as with filters, we deactivate the variable
    # traces during initialization. This happens by
    # (1) replacing the next's trace method by a no-op
    # (2) collecting variable traces through collect-var-traces
    # (3) re-activating the traces after variable initialization
    
    set exports ""
    set pre_cmds ""
    
    # delete ::ns from the namespace list, if it exists...
    catch {unset namespace(::ns)}
    
    foreach ns [array name namespace] {
      if {![namespace exists $ns]} continue
      if {![::nsf::object::exists $ns]} {
        append pre_cmds "namespace eval $ns {}\n"
      } elseif {$ns ne [namespace origin $ns] } {
        append pre_cmds "namespace eval $ns {}\n"
      }
      set exp [namespace eval $ns {::namespace export}]
      if {$exp ne ""} {
        append exports "namespace eval $ns {::namespace export $exp}" \n
      }
    }
    return $pre_cmds$result${:post_cmds}$exports
  • setObjectSystemSerializer (scripted)

    set :serializer($o$serializer