Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement growing message sequences for [] syntax #47

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public String lookForComments(TokenStream tokenStream, Token token, int lookback
String comments = tokenStream.get(tokenIndex).getText().trim();
if (!comments.isEmpty())
{
comments = comments.replaceAll("(\n|\r\n|\r) {1,5}\\*", "\n *");
comments = comments.replaceAll("\\R +", "\n").stripIndent();
return comments;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String getIdlTypename()
public String getMaxsize()
{
if(m_maxsize == null)
return "100";
return "-1";

return m_maxsize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String getIdlTypename()
public String getMaxsize()
{
if(m_maxsize == null)
return "100";
return "-1";

return m_maxsize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public String getMaxsize()
{
return null;
}

public boolean getUnbounded()
{
return getMaxsize() != null && getMaxsize().equals("-1");
}

/*!
* @brief This function returns the size of the datatype. By default is null string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ $endif$
$struct.members : { member |
$if(member.typecode.isType_e)$
$if(member.typecode.ContentTypeCode.isType_c)$
$member.name$_ = new $member.typecode.javaTypename$($member.typecode.Maxsize$, $member.typecode.ContentTypeCode.javaTypename$.class, $member.typecode.ContentTypeCode.javaTypename$.values);$\n$
$member.name$_ = new $member.typecode.javaTypename$($if(member.typecode.Unbounded)$$member.typecode.Maxsize$, $endif$$member.typecode.ContentTypeCode.javaTypename$.class, $member.typecode.ContentTypeCode.javaTypename$.values);$\n$
$elseif(member.typecode.ContentTypeCode.primitive)$
$member.name$_ = new $member.typecode.javaTypename$($member.typecode.Maxsize$, "$member.typecode.ContentTypeCode.stType$");$\n$
$member.name$_ = new $member.typecode.javaTypename$($if(member.typecode.Unbounded)$$member.typecode.Maxsize$, $endif$"$member.typecode.ContentTypeCode.stType$");$\n$
$elseif(member.typecode.ContentTypeCode.isType_d)$
$member.name$_ = new $member.typecode.javaTypename$($member.typecode.Maxsize$, "$member.typecode.ContentTypeCode.stType$");$\n$
$member.name$_ = new $member.typecode.javaTypename$($if(member.typecode.Unbounded)$$member.typecode.Maxsize$, $endif$"$member.typecode.ContentTypeCode.stType$");$\n$
$else$
$member.name$_ = new $member.typecode.javaTypename$($member.typecode.Maxsize$, new $member.typecode.ContentTypeCode.pubsubTypename$());$\n$
$member.name$_ = new $member.typecode.javaTypename$($if(member.typecode.Unbounded)$$member.typecode.Maxsize$, $endif$new $member.typecode.ContentTypeCode.pubsubTypename$());$\n$
$endif$
$elseif(member.typecode.isType_f)$
$member.name$_ = new $member.typecode.ContentTypeCode.JavaTypename$[$member.typecode.Dimensions;separator="]["$];$\n$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class GenerateTestMessages
{
/**
* Must be run from ihmc-pub-sub-group/ihmc-pub-sub-generator/src/test folder.
* Must be run from ihmc-ros2-library/ihmc-pub-sub-generator/src/test folder.
*/
public static void main(String[] args) throws IOException
{
Expand Down
2 changes: 1 addition & 1 deletion ihmc-pub-sub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ The code will not compile until this is run once.

This will also clone the git submodules.
```
ihmc-pub-sub-group $ gradle compositeTask -PtaskName=compileJava
ihmc-ros2-library $ gradle compositeTask -PtaskName=compileJava
```

### Native compilation
Expand Down
2 changes: 1 addition & 1 deletion ihmc-pub-sub/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<author email="[email protected]">Jesper Smith</author>
<maintainer email="[email protected]">Jesper Smith</maintainer>

<url type="website">https://github.com/ihmcrobotics/ihmc-pub-sub-group</url>
<url type="website">https://github.com/ihmcrobotics/ihmc-ros2-library</url>

<license>Apache 2.0</license>

Expand Down
133 changes: 126 additions & 7 deletions ihmc-pub-sub/src/main/java/us/ihmc/idl/IDLSequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ public static class Boolean extends TByteArrayList implements IDLSequence
public static final byte True = 1;
public static final byte False = 0;
private final int maxSize;


public Boolean(String typeCode)
{
if (!typeCode.equals("type_7"))
{
throw new NotImplementedException(typeCode + " is not implemented for Sequence");
}
this.maxSize = java.lang.Integer.MAX_VALUE;
}

public Boolean(int maxSize, String typeCode)
{
super(maxSize);
Expand Down Expand Up @@ -118,6 +127,8 @@ public int capacity()

public static class Byte implements IDLSequence
{
private static final int DEFAULT_MAX_SIZE_BYTES = 4096;

/**
* The backing buffer as a heap array.
* We only use the position and capacity. We do not use the limit or mark.
Expand All @@ -126,6 +137,15 @@ public static class Byte implements IDLSequence
*/
private final ByteBuffer buffer;

public Byte(String typeCode)
{
if (!typeCode.equals("type_9"))
{
throw new NotImplementedException(typeCode + " is not implemented for Sequence");
}
buffer = ByteBuffer.allocate(DEFAULT_MAX_SIZE_BYTES);
}

public Byte(int maxSize, String typeCode)
{
if (!typeCode.equals("type_9"))
Expand Down Expand Up @@ -271,6 +291,23 @@ public static class Char extends TCharArrayList implements IDLSequence
{
private final int type;
private final int maxSize;

public Char(String typeCode)
{
switch (typeCode)
{
case "type_8":
type = 8;
break;
case "type_14":
type = 14;
break;
default:
throw new NotImplementedException(typeCode + " is not implemented for Sequence");
}
this.maxSize = java.lang.Integer.MAX_VALUE;
}

public Char(int maxSize, String typeCode)
{
super(maxSize);
Expand Down Expand Up @@ -352,6 +389,16 @@ public int capacity()
public static class Short extends TShortArrayList implements IDLSequence
{
private final int maxSize;

public Short(String typeCode)
{
if (!typeCode.equals("type_1"))
{
throw new NotImplementedException(typeCode + " is not implemented for Sequence");
}
this.maxSize = java.lang.Integer.MAX_VALUE;
}

public Short(int maxSize, String typeCode)
{
super(maxSize);
Expand Down Expand Up @@ -412,6 +459,22 @@ public static class Integer extends TIntArrayList implements IDLSequence
private final int type;
private final int maxSize;

public Integer(String typeCode)
{
switch (typeCode)
{
case "type_2":
type = 2;
break;
case "type_3":
type = 3;
break;
default:
throw new NotImplementedException(typeCode + " is not implemented for Sequence");
}
this.maxSize = java.lang.Integer.MAX_VALUE;
}

public Integer(int maxSize, String typeCode)
{
super(maxSize);
Expand Down Expand Up @@ -494,6 +557,26 @@ public static class Long extends TLongArrayList implements IDLSequence
{
private final int type;
private final int maxSize;

public Long(String typeCode)
{
switch (typeCode)
{
case "type_11":
type = 11;
break;
case "type_12":
type = 12;
break;
case "type_4":
type = 4;
break;
default:
throw new NotImplementedException(typeCode + " is not implemented for Sequence");
}
this.maxSize = java.lang.Integer.MAX_VALUE;
}

public Long(int maxSize, String typeCode)
{
super(maxSize);
Expand Down Expand Up @@ -584,6 +667,16 @@ public int capacity()
public static class Float extends TFloatArrayList implements IDLSequence
{
private final int maxSize;

public Float(String typeCode)
{
if (!typeCode.equals("type_5"))
{
throw new NotImplementedException(typeCode + " is not implemented for Sequence");
}
this.maxSize = java.lang.Integer.MAX_VALUE;
}

public Float(int maxSize, String typeCode)
{
super(maxSize);
Expand Down Expand Up @@ -642,6 +735,16 @@ public int capacity()
public static class Double extends TDoubleArrayList implements IDLSequence
{
private final int maxSize;

public Double(String typeCode)
{
if (!typeCode.equals("type_6"))
{
throw new NotImplementedException(typeCode + " is not implemented for Sequence");
}
maxSize = java.lang.Integer.MAX_VALUE;
}

public Double(int maxSize, String typeCode)
{
super(maxSize);
Expand Down Expand Up @@ -701,6 +804,25 @@ public static class StringBuilderHolder extends RecyclingArrayList<StringBuilder
{
private final int type;

/**
* @param typeCode Can be "type_d" (idl type string) or "type_15" (idl type wstring)
*/
public StringBuilderHolder(String typeCode)
{
super(StringBuilder::new);
switch (typeCode)
{
case "type_d":
type = 0xd;
break;
case "type_15":
type = 0x15;
break;
default:
throw new NotImplementedException(typeCode + " is not implemented for Sequence");
}
}

/**
* @param maxSize Preallocate elements
* @param typeCode Can be "type_d" (idl type string) or "type_15" (idl type wstring)
Expand Down Expand Up @@ -936,15 +1058,12 @@ public static class Object<T> extends RecyclingArrayList<T> implements IDLSequen
private final TopicDataType<T> topicDataType;

/**
* @deprecated Use {@link IDLSequence(int, TopicDataType)} instead.
*
* @param maxSize Maximum size of this sequence
* @param clazz Class to store
* @param topicDataType TopicDataType to preallocate data if desired
*/
public Object(int maxSize, Class<T> clazz, TopicDataType<T> topicDataType)
public Object(TopicDataType<T> topicDataType)
{
this(maxSize, topicDataType);
super(topicDataType::createData);
this.topicDataType = topicDataType;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import java.util.ArrayList;
import java.util.List;

/**
* To be used in Gradle scripts to generate ROS 2 messages.
*/
public class ROS2MessageGenerator extends DefaultTask
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BigNumSequence extends Packet<BigNumSequence> implements Settable<B

public BigNumSequence()
{
large_sequence_ = new us.ihmc.idl.IDLSequence.Object<ros_msgs.msg.dds.Num> (10000, new ros_msgs.msg.dds.NumPubSubType());
large_sequence_ = new us.ihmc.idl.IDLSequence.Object<ros_msgs.msg.dds.Num> (new ros_msgs.msg.dds.NumPubSubType());

}

Expand Down
Loading
Loading