Class: Fairy::PoolDictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/fairy/share/pool-dictionary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePoolDictionary

Returns a new instance of PoolDictionary.



9
10
11
12
13
# File 'lib/fairy/share/pool-dictionary.rb', line 9

def initialize
  @pool = {}
  @pool_mutex = Mutex.new
  @pool_cv = ConditionVariable.new
end

Instance Attribute Details

#pool_cvObject (readonly)

Returns the value of attribute pool_cv.



16
17
18
# File 'lib/fairy/share/pool-dictionary.rb', line 16

def pool_cv
  @pool_cv
end

#pool_mutexObject (readonly)

Returns the value of attribute pool_mutex.



15
16
17
# File 'lib/fairy/share/pool-dictionary.rb', line 15

def pool_mutex
  @pool_mutex
end

Instance Method Details

#[](name) ⇒ Object



34
35
36
37
38
39
# File 'lib/fairy/share/pool-dictionary.rb', line 34

def [](name)
  @pool_mutex.synchronize do
	ERR::Raise NoAssignedVarriable, name unless @pool.key?(name)
	@pool[name]
  end
end

#[]=(name, value) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fairy/share/pool-dictionary.rb', line 41

def []=(name, value)
  @pool_mutex.synchronize do
	ERR::Raise NoAssignedVarriable, name unless @pool.key?(name)
	case value
	when DeepConnect::Reference
	  @pool[name] = value.dc_deep_copy
	else
	  @pool[name] = value
	end
  end
end

#def_variable(vname, value = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fairy/share/pool-dictionary.rb', line 18

def def_variable(vname, value = nil)
  @pool_mutex.synchronize do
	if @pool.key?(vname)
	  ERR::Raise ERR::AlreadyAssignedVarriable, vname
	end
	case value
	when DeepConnect::Reference
	  @pool[vname] = value.dc_deep_copy
	else
	  @pool[vname] = value
	end
	
	instance_eval "def #{vname}; self[:#{vname}]; end"
	instance_eval "def #{vname}=(v); self[:#{vname}]=v; end"
  end
end