forked from Xamla/ROS.NET
-
Notifications
You must be signed in to change notification settings - Fork 2
/
KnownStuff.cs
108 lines (99 loc) · 3.38 KB
/
KnownStuff.cs
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
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using YAMLParser;
namespace FauxMessages
{
public static class KnownStuff
{
private static char[] spliter = { ' ' };
/// <summary>
/// Message namespaces known to ALL messages (in their header's using lines)
/// </summary>
private const string STATIC_NAMESPACE_STRING = "using Messages.std_msgs;\nusing String=System.String;\nusing Messages.geometry_msgs;";
/// <summary>
/// Returns the namespaced type name (if neccessary)
/// </summary>
/// <param name="st">This thing's SingleType</param>
/// <param name="type">(optional) the type string</param>
/// <returns>duh</returns>
public static string GetNamespacedType(SingleType st, string type = null)
{
if (type == null)
type = st.Type;
if (st.Package != null && !KnownTypes.ContainsKey(st.rostype) && !type.Contains(st.Package))
return string.Format("Messages.{0}.{1}", st.Package, type);
return type;
}
public static bool IsPrimitiveType(SingleType st)
{
return st.Package == null && KnownTypes.ContainsKey(st.rostype) && st.rostype != "duration" && st.rostype != "time";
}
public static Dictionary<string, string> KnownTypes = new Dictionary<string, string>
{
{ "float64", "double" },
{ "float32", "Single" },
{ "uint64", "ulong" },
{ "uint32", "uint" },
{ "uint16", "ushort" },
{ "uint8", "byte" },
{ "int64", "long" },
{ "int32", "int" },
{ "int16", "short" },
{ "int8", "sbyte" },
{ "byte", "byte" },
{ "bool", "bool" },
{ "char", "char" },
{ "time", "Time" },
{ "string", "string" },
{ "duration", "Duration"}
};
public static string GetConstTypesAffix(string type)
{
switch (type.ToLower())
{
case "decimal":
return "M";
case "single":
case "float":
return "F";
case "long":
return "L";
case "ulong":
return "UL";
case "uint":
return "U";
default:
return "";
}
}
public static SingleType WhatItIs(MsgFile parent, string s, string extraindent)
{
string[] pieces = s.Split('/');
string package = null;
if (pieces.Length == 2)
{
package = pieces[0];
s = pieces[1];
}
SingleType st = new SingleType(package, s, extraindent);
parent.resolve(st);
WhatItIs(parent, st);
return st;
}
public static void WhatItIs(MsgFile parent, SingleType t)
{
if (t.IsPrimitve)
{
t.rostype = t.Type;
SingleType.Finalize(parent, t);
return;
}
t.Finalize(parent, t.input.Split(spliter, StringSplitOptions.RemoveEmptyEntries), false);
}
}
}