Node structure
This commit is contained in:
parent
c900add842
commit
2dafc1ae4c
20
ld2dap/Filter.py
Normal file
20
ld2dap/Filter.py
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file Filter.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 03 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from Input import Input
|
||||
from Output import Output
|
||||
|
||||
class Filter(Input, Output):
|
||||
def __init__(self):
|
||||
super().__init__('Filter')
|
||||
|
||||
def _run(self):
|
||||
print('ima not virtual!')
|
||||
|
||||
22
ld2dap/Input.py
Normal file
22
ld2dap/Input.py
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file Input.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 03 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from Node import Node
|
||||
|
||||
class Input(Node):
|
||||
def __init__(self, name='__CHILD__'):
|
||||
super().__init__('Input:{}'.format(name))
|
||||
self.outputs = list()
|
||||
|
||||
def register(self, output):
|
||||
self.outputs.append(output)
|
||||
|
||||
def run(self):
|
||||
print('IMA INPUT N I RUNIN')
|
||||
23
ld2dap/Node.py
Normal file
23
ld2dap/Node.py
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file Node.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 03 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
|
||||
class Node:
|
||||
def __init__(self, name='A NODE HAS NO NAME'):
|
||||
self.name = name
|
||||
|
||||
def __str__(self):
|
||||
return ("Node:{}".format(self.name))
|
||||
|
||||
def _run(self):
|
||||
raise NotImplementedError('This method is virtual')
|
||||
|
||||
def run(self):
|
||||
return self._run()
|
||||
30
ld2dap/Output.py
Normal file
30
ld2dap/Output.py
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file Output.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 03 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from Node import Node
|
||||
from Input import Input
|
||||
|
||||
class Output(Node):
|
||||
def __init__(self, name='__CHILD__'):
|
||||
super().__init__('Output:{}'.format(name))
|
||||
self.__dict__['input'] = None
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name == 'input':
|
||||
self._input(value)
|
||||
else:
|
||||
self.__dict__[name] = value
|
||||
|
||||
def _input(self, inode):
|
||||
if not isinstance(inode, (Input)):
|
||||
raise NotImplementedError('{} is not an Input'.format(inode))
|
||||
self.__dict__['input'] = inode
|
||||
|
||||
|
||||
25
ld2dap/test.py
Normal file
25
ld2dap/test.py
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file test.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 03 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from Node import Node
|
||||
from Filter import Filter
|
||||
from Input import Input
|
||||
|
||||
def main():
|
||||
n = Filter()
|
||||
f = Filter()
|
||||
print(n)
|
||||
n.run()
|
||||
print(n.input)
|
||||
n.input = f
|
||||
print(n.input)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Reference in New Issue
Block a user