File: TargetDescription.h

package info (click to toggle)
aseba 1.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,300 kB
  • sloc: cpp: 44,647; ansic: 5,686; python: 1,455; java: 1,136; sh: 393; xml: 202; makefile: 10
file content (97 lines) | stat: -rw-r--r-- 3,297 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
	Aseba - an event-based framework for distributed robot control
	Copyright (C) 2007--2016:
		Stephane Magnenat <stephane at magnenat dot net>
		(http://stephane.magnenat.net)
		and other contributors, see authors.txt for details
	
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published
	by the Free Software Foundation, version 3 of the License.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ASEBA_TARGET_DESCRIPTION
#define ASEBA_TARGET_DESCRIPTION

#include <map>
#include <string>
#include <vector>

namespace Aseba
{
	/** \addtogroup msg */
	/*@{*/
	
	//! Lookup table for variables name => (pos, size))
	using VariablesMap = std::map<std::wstring, std::pair<unsigned, unsigned> >;
	
	//! Lookup table for functions (name => id in target description)
	using FunctionsMap = std::map<std::wstring, unsigned>;
	
	//! Description of target VM
	struct TargetDescription
	{
		//! Description of target VM named variable
		struct NamedVariable
		{
			NamedVariable(std::wstring name, unsigned size) : name(std::move(name)), size(size) {}
			NamedVariable() = default;
			
			std::wstring name; //!< name of the variable
			unsigned size = 0; //!< size of variable in words
		};
		
		//! Description of local event;
		struct LocalEvent
		{
			std::wstring name; //!< name of the event
			std::wstring description; //!< description (some short documentation) of the event
		};
		
		//! Typed parameter of native functions
		struct NativeFunctionParameter
		{
			NativeFunctionParameter(std::wstring name, int size) : name(std::move(name)), size(size) {}
			NativeFunctionParameter()  = default;
			
			std::wstring name; //!< name of the parameter
			int size = 0; //!< if > 0 size of the parameter, if < 0 template id, if 0 any size
		};
		
		//! Description of target VM native function
		struct NativeFunction
		{
			std::wstring name; //!< name of the function
			std::wstring description; //!< description (some short documentation) of the function
			std::vector<NativeFunctionParameter> parameters; //!< for each argument of the function, its size in words or, if negative, its template ID
		};
		
		std::wstring name; //!< node name
		unsigned protocolVersion{0}; //!< version of the aseba protocol
		
		unsigned bytecodeSize{0}; //!< total amount of bytecode space
		unsigned variablesSize{0}; //!< total amount of variables space
		unsigned stackSize{0}; //!< depth of execution stack
		
		std::vector<NamedVariable> namedVariables; //!< named variables
		std::vector<LocalEvent> localEvents; //!< events available locally on target
		std::vector<NativeFunction> nativeFunctions; //!< native functions
		
		TargetDescription()  = default;
		uint16_t crc() const;
		VariablesMap getVariablesMap(unsigned& freeVariableIndex) const;
		FunctionsMap getFunctionsMap() const;
	};
	
	/*@}*/
} // namespace Aseba

#endif // ASEBA_TARGET_DESCRIPTION