示例#1
0
        public static ConstantDescriptor Create(RosTypeInfo typeInfo, string identifier, object value)
        {
            if (typeInfo == null)
            {
                throw new ArgumentNullException(nameof(typeInfo));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (typeInfo.IsArray || !typeInfo.IsBuiltInType)
            {
                throw new InvalidOperationException($"Type {typeInfo} is not supported for constant declaration");
            }

            var typeMapping = BuiltInTypeMapping.Create(typeInfo);

            if (typeMapping.Type != value.GetType())
            {
                // Fix value type
                var converter = System.ComponentModel.TypeDescriptor.GetConverter(value.GetType());

                if (converter.CanConvertTo(typeMapping.Type))
                {
                    value = converter.ConvertTo(value, typeMapping.Type);
                }
                else
                {
                    throw new InvalidOperationException($"Cannot convert from {value.GetType()} to {typeMapping.Type}");
                }
            }

            return(new ConstantDescriptor(typeInfo, identifier, value));
        }
示例#2
0
        public override object VisitRos_type(RosMessageParser.Ros_typeContext context)
        {
            string packageName = null;
            string typeName    = null;

            if (context.ChildCount == 1)
            {
                typeName = context.GetChild(0).GetText();

                if (typeName == "Header")
                {
                    packageName = "std_msgs";
                }
            }
            else
            {
                packageName = context.GetChild(0).GetText();
                typeName    = context.GetChild(2).GetText();
            }

            var typeInfo = RosTypeInfo.CreateRosType(packageName, typeName);

            _listener.OnVisitRosType(typeInfo);

            return(typeInfo);
        }
 public void OnVisitBuiltInType(RosTypeInfo typeInfo)
 {
     foreach (var listener in _listeners)
     {
         listener.OnVisitBuiltInType(typeInfo);
     }
 }
示例#4
0
        private RosTypeInfo VisitBuiltInType(ParserRuleContext context)
        {
            var rosType  = context.GetText();
            var typeInfo = RosTypeInfo.CreateBuiltIn(rosType);

            _listener.OnVisitBuiltInType(typeInfo);
            return(typeInfo);
        }
示例#5
0
        public override object VisitVariable_array_type(RosMessageParser.Variable_array_typeContext context)
        {
            var type      = (RosTypeInfo)Visit(context.GetChild(0));
            var arrayType = RosTypeInfo.CreateVariableArray(type);

            _listener.OnVisitArrayType(arrayType);
            return(arrayType);
        }
示例#6
0
        public override object VisitFixed_array_type(RosMessageParser.Fixed_array_typeContext context)
        {
            var type      = (RosTypeInfo)Visit(context.GetChild(0));
            var size      = int.Parse(context.GetChild(2).GetText());
            var arrayType = RosTypeInfo.CreateFixedSizeArray(type, size);

            _listener.OnVisitArrayType(arrayType);
            return(arrayType);
        }
示例#7
0
        public static RosTypeInfo CreateVariableArray(RosTypeInfo type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            return(new RosTypeInfo(type.PackageName, type.TypeName, type.IsBuiltInType, true, 0));
        }
示例#8
0
        public static RosTypeInfo CreateFixedSizeArray(RosTypeInfo type, int size)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (size <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(size));
            }

            return(new RosTypeInfo(type.PackageName, type.TypeName, type.IsBuiltInType, true, size));
        }
        public NestedTypeDescriptor(RosTypeInfo typeInfo, MessageDescriptor messageDefinition)
        {
            if (typeInfo == null)
            {
                throw new ArgumentNullException(nameof(typeInfo));
            }
            if (messageDefinition == null)
            {
                throw new ArgumentNullException(nameof(messageDefinition));
            }

            TypeInfo          = typeInfo;
            MessageDefinition = messageDefinition;
        }
        public FieldDescriptor(RosTypeInfo typeInfo, string identifier)
        {
            if (typeInfo == null)
            {
                throw new ArgumentNullException(nameof(typeInfo));
            }
            if (identifier == null)
            {
                throw new ArgumentNullException(nameof(identifier));
            }

            TypeInfo   = typeInfo;
            Identifier = identifier;
        }
示例#11
0
        public static BuiltInTypeMapping Create(RosTypeInfo primitiveRosType)
        {
            if (primitiveRosType == null)
            {
                throw new ArgumentNullException(nameof(primitiveRosType));
            }

            if (!primitiveRosType.IsBuiltInType)
            {
                throw new InvalidOperationException($"ROS type {primitiveRosType} is no primitive type.");
            }

            return(Create(primitiveRosType.TypeName));
        }
示例#12
0
        protected ConstantDescriptor(RosTypeInfo typeInfo, string identifier, object value)
        {
            if (typeInfo == null)
            {
                throw new ArgumentNullException(nameof(typeInfo));
            }
            if (identifier == null)
            {
                throw new ArgumentNullException(nameof(identifier));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            TypeInfo   = typeInfo;
            Identifier = identifier;
            Value      = value;
        }
示例#13
0
 protected bool Equals(RosTypeInfo other)
 {
     return(PackageName == other.PackageName && TypeName == other.TypeName && IsBuiltInType == other.IsBuiltInType && IsArray == other.IsArray && ArraySize == other.ArraySize);
 }