Imported Upstream version 0.1
[debian/configureit.git] / int.go
1 // int.go
2 //
3 // Integer Type
4
5 package configureit
6
7 import (
8         "strings"
9         "strconv"
10         "os"
11         "fmt"
12 )
13
14 type IntOption struct { 
15         defaultvalue    int
16         isset           bool
17         Value           int
18 }
19
20 func NewIntOption(defaultValue int) ConfigNode {
21         opt := new(IntOption)
22
23         opt.defaultvalue = defaultValue
24         opt.Reset()
25
26         return opt
27 }
28
29 func (opt *IntOption) String() string {
30         return fmt.Sprintf("%d", opt.Value)
31 }
32
33 func (opt *IntOption) Parse(newValue string) os.Error {
34         nativenv, err := strconv.Atoi(strings.TrimSpace(newValue))
35         if err != nil {
36                 return err
37         }
38         opt.Value = nativenv
39         opt.isset = true
40
41         return nil
42 }
43
44 func (opt *IntOption) IsDefault() bool {
45         return !opt.isset
46 }
47
48 func (opt *IntOption) Reset() {
49         opt.Value = opt.defaultvalue
50         opt.isset = false
51 }