66
77class Compartment :
88 """
9- Compartments in ngcsimlib are container objects for storing the stateful values of components. Compartments are
10- tracked globaly and are automatically linked to components and methods during compiling to allow for stateful
11- mechanics to be run without the need for the class object. Compartments also provide an entry and exit point for
12- values inside of components allowing for cables to be connected for sending and receiving values.
9+ Compartments in ngcsimlib are container objects for storing the stateful
10+ values of components. Compartments are
11+ tracked globaly and are automatically linked to components and methods
12+ during compiling to allow for stateful
13+ mechanics to be run without the need for the class object. Compartments
14+ also provide an entry and exit point for
15+ values inside of components allowing for cables to be connected for
16+ sending and receiving values.
1317 """
1418
1519 @classmethod
1620 def is_compartment (cls , obj ):
1721 """
18- A method for verifying if a provided object is a compartment. All compartments have `_is_compartment` set to
22+ A method for verifying if a provided object is a compartment. All
23+ compartments have `_is_compartment` set to
1924 true by default and this is
2025
2126 Args:
@@ -26,14 +31,18 @@ def is_compartment(cls, obj):
2631 """
2732 return hasattr (obj , "_is_compartment" )
2833
29- def __init__ (self , initial_value = None , static = False ):
34+ def __init__ (self , initial_value = None , static = False , is_input = False ):
3035 """
31- Builds a compartment to be used inside a component. It is important to note that building compartments
32- outside of components may cause unexpected behavior as components interact with their compartments during
36+ Builds a compartment to be used inside a component. It is important
37+ to note that building compartments
38+ outside of components may cause unexpected behavior as components
39+ interact with their compartments during
3340 construction to finish initializing them.
3441 Args:
35- initial_value: The initial value of the compartment. As a general practice it is a good idea to
36- provide a value that is similar to the values that will normally be stored here, such as an array of
42+ initial_value: The initial value of the compartment. As a general
43+ practice it is a good idea to
44+ provide a value that is similar to the values that will
45+ normally be stored here, such as an array of
3746 zeros of the correct length. (default: None)
3847
3948 static: a flag to lock a compartment to be static (default: False)
@@ -45,11 +54,14 @@ def __init__(self, initial_value=None, static=False):
4554 self ._uid = uuid .uuid4 ()
4655 self .name = None
4756 self .path = None
57+ self .is_input = is_input
58+ self ._is_destination = False
4859
4960 def _setup (self , current_component , key ):
5061 """
51- Finishes initializing the compartment, called by the component that builds the compartment
52- (Handel automatically)
62+ Finishes initializing the compartment, called by the component that
63+ builds the compartment
64+ (Handled automatically)
5365 """
5466 self .__add_connection = current_component .add_connection
5567 self .name = current_component .name + "/" + key
@@ -58,7 +70,8 @@ def _setup(self, current_component, key):
5870
5971 def set (self , value ):
6072 """
61- Sets the value of the compartment if it not static (Raises a runtime error)
73+ Sets the value of the compartment if it not static (Raises a runtime
74+ error)
6275 Args:
6376 value: the new value to be set
6477 """
@@ -89,8 +102,10 @@ def __str__(self):
89102
90103 def __lshift__ (self , other ) -> None :
91104 """
92- Overrides the left shift operation to be used for wiring compartments into one another
93- if other is not an Operation it will create an overwrite operation with other as the argument,
105+ Overrides the left shift operation to be used for wiring compartments
106+ into one another
107+ if other is not an Operation it will create an overwrite operation
108+ with other as the argument,
94109 otherwise it will use the provided operation
95110
96111 Args:
@@ -103,3 +118,16 @@ def __lshift__(self, other) -> None:
103118 op = overwrite (other )
104119 op .set_destination (self )
105120 self .__add_connection (op )
121+
122+ self ._is_destination = True
123+
124+ def is_wired (self ):
125+ """
126+ Returns: if this compartment not marked as an input, or is marked and
127+ has an input
128+
129+ """
130+ if not self .is_input :
131+ return True
132+
133+ return self ._is_destination
0 commit comments