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.



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

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

Instance Attribute Details

#pool_cvObject (readonly)

Returns the value of attribute pool_cv.



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

def pool_cv
  @pool_cv
end

#pool_mutexObject (readonly)

Returns the value of attribute pool_mutex.



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

def pool_mutex
  @pool_mutex
end

Instance Method Details

#[](name) ⇒ Object



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

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

#[]=(name, value) ⇒ Object



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

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



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

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