1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  
     | 
    
      # configuration.tcl --
#
#	Generic configuration management, for use by import and export
#	managers.
#
# Copyright (c) 2009 Andreas Kupries <andreas_kupries@sourceforge.net>
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# 
# RCS: @(#) $Id: configuration.tcl,v 1.1 2010/03/26 05:07:24 andreas_kupries Exp $
# Each object manages a set of configuration variables.
# ### ### ### ######### ######### #########
## Requisites
package require Tcl 8.5
package require snit
# ### ### ### ######### ######### #########
## API
snit::type ::configuration {
    # ### ### ### ######### ######### #########
    ## Options :: None
    # ### ### ### ######### ######### #########
    ## Creating, destruction
    # Default constructor.
    # Default destructor.
    # ### ### ### ######### ######### #########
    ## Public methods. Reading and writing the configuration.
    method names {} {
	return [array names myconfiguration]
    }
    method get {} {
	return [array get myconfiguration]
    }
    method set {name {value {}}} {
	# 7 instead of 3 in the condition below, because of the 4
	# implicit arguments snit is providing to each method.
	if {[llength [info level 0]] == 7} {
	    set myconfiguration($name) $value
	} elseif {![info exists myconfiguration($name)]} {
	    return -code error "can't read \"$name\": no such variable"
	}
	return $myconfiguration($name)
    }
    method unset {args} {
	if {![llength $args]} { lappend args * }
	foreach pattern $args {
	    array unset myconfiguration $pattern
	}
	return
    }
    # ### ### ### ######### ######### #########
    ## Internal methods :: None.
    # ### ### ### ######### ######### #########
    ## State :: Configuration data, Tcl array
    variable myconfiguration -array {}
    ##
    # ### ### ### ######### ######### #########
}
# ### ### ### ######### ######### #########
## Ready
package provide configuration 1
return
 
     |