1 // (c) Bernhard Tittelbach, 2013
7 type informationtuple struct {
12 type informationretrievalpath struct {
14 returnpath chan interface{}
17 type hippocampus map[string]interface{}
20 storeTuple chan informationtuple
21 retrieveValue chan informationretrievalpath
27 b.storeTuple = make(chan informationtuple)
28 b.retrieveValue = make(chan informationretrievalpath)
33 func (b *Brain) runBrain() {
34 var h hippocampus = make(hippocampus)
37 case newtuple := <- b.storeTuple:
38 h[newtuple.name] = newtuple.value
40 case retrievvalue := <- b.retrieveValue:
41 v, e := h[retrievvalue.name]
43 retrievvalue.returnpath <- v
45 retrievvalue.returnpath <- nil
54 func (b *Brain) Shutdown() {
58 func (b *Brain) Oboite(name string, value interface{}) {
59 b.storeTuple <- informationtuple{name, value}
62 func (b *Brain) OmoiDashite(name string) (interface{}, error) {
63 rc := make(chan interface{})
64 b.retrieveValue <- informationretrievalpath{name, rc}
67 return v, errors.New("name not in brain")
72 func (b *Brain) OmoiDashiteBool(name string) (bool, error) {
73 v, e := b.OmoiDashite(name)
79 return false, errors.New(name + " does not have type bool")
84 func (b *Brain) OmoiDashiteInt(name string) (int, error) {
85 v, e := b.OmoiDashite(name)
91 return 0, errors.New(name + " does not have type int")
96 func (b *Brain) OmoiDashiteFloat(name string) (float64, error) {
97 v, e := b.OmoiDashite(name)
101 vc, ok := v.(float64)
103 return 0, errors.New(name + " does not have type float64")
108 func (b *Brain) OmoiDashiteString(name string) (string, error) {
109 v, e := b.OmoiDashite(name)
115 return "", errors.New(name + " does not have type string")