保存大量状态机信息的数据结构
我有一个 XML 文件,想要表示 ac# 数据结构中 XML 文件中描述的复杂有限状态机。我可以使用什么数据结构?一种状态的定义位于此处。状态机根据各种异步事件显示同步和异步转换以及操作。
I have a XML file and want to represent a complex finite state machine described in a XML file in a c# data-structure. What data structure can I use? Definition of one state is here. the state machine shows sync and async transitions and actions according to various async events.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能应该首先看看状态设计模式如何为您提供帮助。
您需要两件事
如果您的状态实例是预先创建的。
这些状态的内部表示,您可以将 XML 反序列化到其中。这将是一系列表示 XML 结构的类。
由于每个状态似乎都有一个 ID,并且您使用此 ID 转换到目标状态,因此您可以将状态对象(这些来自点 1)存储在字典中,其中键是 ID,值是状态对象。当您执行转换时,您只需在字典中查找目标状态并从那里获取实例。
如果要按需创建状态实例
字典将包含每个状态的元数据(可以是 XML 或从原始 XML 中提取的优化格式),然后当状态如果需要转换,您可以在字典中查找状态并从与状态 id 关联的元数据动态实例化状态。
You should probably start by taking a look at how the State Design Pattern could possibly help you.
You have two things that you need
If your state instances are pre-created.
The internal representation of those states, which you can deserialize the XML into. This would be a series of classes which represent the XML structure.
Since each state seems to have an ID and you use this ID to transition to the target state, you can store the state objects (these are from point 1) in a Dictionary where the key is the ID and the value is the state object. When you execute a transition, you just look-up the target state in the dictionary and get the instance from there.
If the state instances are to be created on demand
The dictionary will contain the meta-data for each state (this can be the XML or an optimized format that is hydrated from the original XML) then when a state transition is required, you look-up the state in the dictionary and dynamically instantiate the state from the meta-data associated with the state id.