Commit d59e81d0 authored by Bernardo Quaresma Dias's avatar Bernardo Quaresma Dias
Browse files

Inclusão de versão de lib state com classes de gerenciamento de estado

INSTMPA-1284
parent 1d87fb1c
MPA_5_0 = true
DisabledDiagrams = {
}
Diagrams = {
{
id = "STATE {Atualizar}",
name = "STATE {Atualizar}",
kind = "Flow",
description = nil,
isApplication = false,
globals = {
{
name = "estado",
type = "indicador",
list = false,
value = nil,
comment = nil,
is_arg = true,
is_ret = false,
},
{
name = "desejado",
type = "INTEGER",
list = false,
value = nil,
comment = nil,
is_arg = true,
is_ret = false,
},
{
name = "registro",
type = "registro",
list = false,
value = nil,
comment = nil,
is_arg = true,
is_ret = false,
},
{
name = "prefixo",
type = "STRING",
list = false,
value = nil,
comment = nil,
is_arg = true,
is_ret = false,
},
{
name = "alterou",
type = "BOOLEAN",
list = false,
value = "false",
comment = nil,
is_arg = false,
is_ret = true,
},
},
errorFunction = nil,
haltDiagram = nil,
Nodes = {
{
type = "Command",
description = "informa\n$result\n($object)",
action = {
_switch = "OBJECTCALL",
beforemsg = nil,
aftermsg = nil,
expressions = {},
variables = {"atual",},
classid = "indicador",
objname = "estado",
member = "variavel",
operation = "read",
},
xmin = 4600,
ymin = 5220,
xmax = 4800,
ymax = 5340,
},
{
type = "Choice",
description = "$expressions?",
action = {
_switch = "EXPRESSION",
beforemsg = nil,
aftermsg = nil,
expressions = {"atual\n~= desejado\n",},
variables = {},
types = {"BOOLEAN",},
islist = {false,},
},
xmin = 4600,
ymin = 5020,
xmax = 4800,
ymax = 5140,
},
{
type = "Command",
description = "escreve\n$parameter_1\n($object)",
action = {
_switch = "OBJECTCALL",
beforemsg = nil,
aftermsg = nil,
expressions = {"desejado",},
variables = {},
classid = "indicador",
objname = "estado",
member = "variavel",
operation = "write",
},
xmin = 4600,
ymin = 4620,
xmax = 4800,
ymax = 4740,
},
{
type = "Choice",
description = nil,
action = {
_switch = "EXPRESSION",
beforemsg = nil,
aftermsg = nil,
expressions = {"registro\n~= nil",},
variables = {},
types = {"BOOLEAN",},
islist = {false,},
},
xmin = 4600,
ymin = 4420,
xmax = 4800,
ymax = 4540,
},
{
type = "Command",
description = "$name\nestado\n($object)",
action = {
_switch = "OBJECTCALL",
beforemsg = nil,
aftermsg = nil,
expressions = {"msg",},
variables = {},
classid = "registro",
objname = "registro",
member = "registrar",
operation = "call",
},
xmin = 4600,
ymin = 3820,
xmax = 4800,
ymax = 3940,
},
{
type = "Command",
description = nil,
action = {
_switch = "EXPRESSION",
beforemsg = nil,
aftermsg = nil,
expressions = {"true",},
variables = {"alterou",},
types = {"BOOLEAN",},
islist = {false,},
},
xmin = 4600,
ymin = 4820,
xmax = 4800,
ymax = 4940,
},
{
type = "Command",
description = "define\n$variables",
action = {
_switch = "EXPRESSION",
beforemsg = nil,
aftermsg = nil,
expressions = {"string.format(\"estado alterado de %d para %d\", atual,desejado)",},
variables = {"msg",},
types = {"STRING",},
islist = {false,},
},
xmin = 4600,
ymin = 4220,
xmax = 4800,
ymax = 4340,
},
{
type = "Choice",
description = "$expressions?",
action = {
_switch = "EXPRESSION",
beforemsg = nil,
aftermsg = nil,
expressions = {"prefixo\n~= nil",},
variables = {},
types = {"BOOLEAN",},
islist = {false,},
},
xmin = 4600,
ymin = 4020,
xmax = 4800,
ymax = 4140,
},
{
type = "Command",
description = "define\n$variables\ncom prefixo",
action = {
_switch = "EXPRESSION",
beforemsg = nil,
aftermsg = nil,
expressions = {"table.concat({prefixo, msg},\";\")",},
variables = {"msg",},
types = {"STRING",},
islist = {false,},
},
xmin = 4880,
ymin = 3820,
xmax = 5080,
ymax = 3940,
},
},
Links = {
{
type = "Link",
description = nil,
from = nil,
to = 1,
x = {4700,4700,},
y = {5420,5280,},
},
{
type = "Link",
description = nil,
from = 1,
to = 2,
x = {4700,4700,},
y = {5280,5080,},
},
{
type = "Link",
description = "V",
from = 2,
to = 6,
x = {4700,4700,},
y = {5080,4880,},
},
{
type = "Link",
description = nil,
from = 3,
to = 4,
x = {4700,4700,},
y = {4680,4480,},
},
{
type = "Link",
description = "V",
from = 4,
to = 7,
x = {4700,4700,},
y = {4480,4280,},
},
{
type = "Link",
description = nil,
from = 6,
to = 3,
x = {4700,4700,},
y = {4880,4680,},
},
{
type = "Link",
description = "V",
from = 8,
to = 9,
x = {4700,4980,4980,},
y = {4080,4080,3880,},
},
{
type = "Link",
description = nil,
from = 9,
to = 5,
x = {4980,4700,},
y = {3880,3880,},
},
{
type = "Link",
description = nil,
from = 7,
to = 8,
x = {4700,4700,},
y = {4280,4080,},
},
{
type = "Link",
description = "F",
from = 8,
to = 5,
x = {4700,4700,},
y = {4080,3880,},
},
},
Areas = {
},
Hidden = {
},
},
}
Dependencies = {"lib-painel-2_1.mpam",}
include 'lib-access-1_0.mpam'
class{ id = "state_base", name = "Estado Básico", group = "Gerenciamento de Estado",
bases = {},
description = [[
Modelagem de classe para atualização do estado do diagrama como um ponto inteiro.
]],
code = [===[
function _CLASS:init()
local labels = self.l_labels
if labels then
self._label_map = {}
for i, label in ipairs(labels) do
self._label_map[label] = i
end
end
end
]===],
attributes = {
{ id = "ind_state", name = "Estado", type = "INTEGER_POINT", access = "rw",
description = [[Indicação de estado atual.]],
},
{ id = "cfg_init_val", name = "Valor Inicial", type = "INTEGER", access = "",
description = [[
Valor inicial para estado.
Se não for configurado, será usado o valor -1.
]],
},
{ id = "l_labels", name = "Rótulos de Estado", type = "STRING[]", access = "",
description = [[Lista de rótulos de estados.]],
},
},
methods = {
{ id = "get", name = "Obter",
description = [[Informa o último valor definido do estado.]],
parameters = {
},
results = {
{ name = "Estado Atual", type = "INTEGER"}
},
code = [===[ function(self)
return self._cache
end ]===],
},
{ id = "set", name = "Definir",
description = [[
Ajusta o valor do estado atual para novo estado.
Se houver alteração no estado, retorna o estado anterior.
]],
parameters = {
{ name = "Novo Estado", type = "INTEGER"}
},
results = {
{ name = "Estado Anterior", type = "INTEGER"}
},
code = [===[ function(self, new)
local old = self._cache
local pt_state = getattribute(self, 'ind_state')
if new ~= old then
self._cache = new
pt_state:write(new)
return old
end
end ]===],
},
{ id = "reset", name = "Apagar",
description = [[Apaga o valor do estado para o valor inicial.]],
parameters = {
},
results = {
},
code = [===[ function(self)
local init_val = self.cfg_init_val or -1
self:set(init_val)
end ]===],
},
{ id = "set_label", name = "Definir Rótulo",
description = [[Ajusta o estado correspondente ao valor do rótulo.]],
parameters = {
{ name = "Rótulo", type = "STRING"}
},
results = {
},
code = [===[ function(self, label)
local label_map = self._label_map --[[ASSERT]] assert(label_map, "%s: Sem rótulos definidos.", tostring(self))
local idx = label_map[label]
self:set(idx)
end ]===],
},
},
}
class{ id = "state_comp", name = "Estado Composto", group = "Gerenciamento de Estado",
bases = {},
description = [[
Modelagem de classe para composição de múltiplos estados.
]],
code = [===[
]===],
attributes = {
{ id = "ind_state_comp", name = "Estado Composto", type = "STRING_POINT", access = "",
description = [[Indicação de estado atual.]],
},
{ id = "l_state", name = "Estados", type = "state_base[]", access = "",
description = [[Indicação de estado atual.]],
},
{ id = "cfg_init_val", name = "Valor Inicial", type = "STRING", access = "",
description = [[
Valor inicial para estado.
Se não for configurado, será usado o valor -1.
]],
},
},
methods = {
{ id = "reset", name = "Apagar",
description = [[Apaga o valor do estado para o valor inicial.]],
parameters = {
},
results = {
},
code = [===[ function(self)
for i, state in ipairs(self.l_state) do
state:reset()
end
local init_val = self.cfg_init_val or "---"
self.ind_state_comp:write(init_val)
end ]===],
},
{ id = "updt", name = "Atualizar",
description = [[Compoem o valor dos estados.]],
parameters = {
},
results = {
},
code = [===[ function(self)
local state_vals = {}
for i, state in ipairs(self.l_state) do
local state_val = state:get()
state_vals[#state_vals+1] = tostring(state_val)
end
local composed = table.concat(state_vals)
self.ind_state_comp:write(composed)
end ]===],
},
},
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment