[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] jcerti/src/hla/rti1516e/jlc HLAvariableArrayImp...
From: |
CERTI CVS commits |
Subject: |
[certi-cvs] jcerti/src/hla/rti1516e/jlc HLAvariableArrayImp... |
Date: |
Wed, 22 Feb 2012 18:51:24 +0000 |
CVSROOT: /sources/certi
Module name: jcerti
Changes by: Eric NOULARD <erk> 12/02/22 18:51:24
Modified files:
src/hla/rti1516e/jlc: HLAvariableArrayImpl.java
EncoderFactory.java
Added files:
src/hla/rti1516e/jlc: HLAfixedArrayImpl.java
HLAfixedRecordImpl.java
Log message:
Implement some missing encoders:
HLAfixedArray
HLAfixedRecord
HLAvariableArray
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/jcerti/src/hla/rti1516e/jlc/HLAvariableArrayImpl.java?cvsroot=certi&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/jcerti/src/hla/rti1516e/jlc/EncoderFactory.java?cvsroot=certi&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/jcerti/src/hla/rti1516e/jlc/HLAfixedArrayImpl.java?cvsroot=certi&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/jcerti/src/hla/rti1516e/jlc/HLAfixedRecordImpl.java?cvsroot=certi&rev=1.1
Patches:
Index: HLAvariableArrayImpl.java
===================================================================
RCS file: /sources/certi/jcerti/src/hla/rti1516e/jlc/HLAvariableArrayImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- HLAvariableArrayImpl.java 6 Jan 2012 14:04:39 -0000 1.1
+++ HLAvariableArrayImpl.java 22 Feb 2012 18:51:24 -0000 1.2
@@ -46,8 +46,14 @@
efactory = null;
}
- public HLAvariableArrayImpl(DataElementFactory<T> factory) {
- values = new ArrayList<T>(20);
+ public HLAvariableArrayImpl(DataElementFactory<T> factory, T[] elements) {
+ values = new ArrayList<T>(elements.length);
+ values.addAll(Arrays.asList(elements));
+ efactory = factory;
+ }
+
+ public HLAvariableArrayImpl(DataElementFactory<T> factory, int size) {
+ values = new ArrayList<T>(size);
efactory = factory;
}
Index: EncoderFactory.java
===================================================================
RCS file: /sources/certi/jcerti/src/hla/rti1516e/jlc/EncoderFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- EncoderFactory.java 6 Jan 2012 14:24:11 -0000 1.6
+++ EncoderFactory.java 22 Feb 2012 18:51:24 -0000 1.7
@@ -79,22 +79,21 @@
public HLAfixedRecord createHLAfixedRecord() {
- // TODO Auto-generated method stub
- return null;
+ return new HLAfixedRecordImpl();
}
public <T extends DataElement> HLAfixedArray<T> createHLAfixedArray(
DataElementFactory<T> factory, int size) {
- // TODO Auto-generated method stub
- return null;
+ return new HLAfixedArrayImpl<T>(factory,size);
}
public <T extends DataElement> HLAfixedArray<T> createHLAfixedArray(
T... elements) {
- // TODO Auto-generated method stub
- return null;
+ // FIXME check: is this supposed to work with vaargs elements?
+ // see:
http://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html
+ return new HLAfixedArrayImpl<T>(elements);
}
@@ -260,7 +259,14 @@
public <T extends DataElement> HLAvariableArray<T> createHLAvariableArray(
DataElementFactory<T> factory, T... elements) {
- return new HLAvariableArrayImpl<T>(factory);
+
+ HLAvariableArray<T> va = new HLAvariableArrayImpl<T>(factory,10);
+ // this is varargs + autoboxing
+ // see:
http://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html
+ for (T e : elements) {
+ va.addElement(e);
+ }
+ return va;
}
}
Index: HLAfixedArrayImpl.java
===================================================================
RCS file: HLAfixedArrayImpl.java
diff -N HLAfixedArrayImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HLAfixedArrayImpl.java 22 Feb 2012 18:51:24 -0000 1.1
@@ -0,0 +1,121 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2011 Eric Noulard
+//
+// 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 ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// 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, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// ----------------------------------------------------------------------------
+package hla.rti1516e.jlc;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+
+import hla.rti1516e.encoding.ByteWrapper;
+import hla.rti1516e.encoding.DataElement;
+import hla.rti1516e.encoding.DataElementFactory;
+import hla.rti1516e.encoding.DecoderException;
+import hla.rti1516e.encoding.EncoderException;
+
+public class HLAfixedArrayImpl<T extends DataElement> extends DataElementBase
+ implements hla.rti1516e.encoding.HLAfixedArray<T> {
+
+ private ArrayList<T> values;
+ private DataElementFactory<T> efactory;
+
+ public HLAfixedArrayImpl(int size) {
+ values = new ArrayList<T>(size);
+
+ }
+
+ public HLAfixedArrayImpl(T[] elements) {
+ values = new ArrayList<T>(elements.length);
+ values.addAll(Arrays.asList(elements));
+ efactory = null;
+ }
+
+ public HLAfixedArrayImpl(DataElementFactory<T> factory, int size) {
+ values = new ArrayList<T>(size);
+ efactory = factory;
+ }
+
+ public int getOctetBoundary() {
+ /* at least 4 since we encode the size */
+ int obound = 4;
+ for (Iterator<T> it = values.iterator(); it.hasNext();) {
+ T elem = it.next();
+ obound = Math.max(obound, elem.getOctetBoundary());
+ }
+ return obound;
+ }
+
+ public void encode(ByteWrapper byteWrapper) throws EncoderException {
+ byteWrapper.align(getOctetBoundary());
+ byteWrapper.putInt(values.size());
+ for (Iterator<T> it = values.iterator(); it.hasNext();) {
+ T elem = it.next();
+ elem.encode(byteWrapper);
+ }
+ }
+
+ public int getEncodedLength() {
+ int elength = 4;
+ for (Iterator<T> it = values.iterator(); it.hasNext();) {
+ T elem = it.next();
+ elength += elem.getEncodedLength();
+ }
+ return elength;
+ }
+
+ public void decode(ByteWrapper byteWrapper) throws DecoderException {
+ byteWrapper.align(getOctetBoundary());
+ int nbElem = byteWrapper.getInt();
+ values.ensureCapacity(nbElem);
+ /* FIXME we may optimize this in order to avoid reallocation
+ * we should
+ * - verify size
+ * - trimToSize
+ * - clear
+ * - add
+ */
+ values.clear();
+ for (int i = 0; i<nbElem;++i) {
+ T elem = efactory.createElement(i);
+ elem.decode(byteWrapper);
+ values.add(elem);
+ }
+ }
+
+ public void addElement(T dataElement) {
+ values.add(dataElement);
+ }
+
+ public int size() {
+ return values.size();
+ }
+
+ public T get(int index) {
+ return values.get(index);
+ }
+
+ public Iterator<T> iterator() {
+ return values.iterator();
+ }
+
+ public void resize(int newSize) {
+ values.ensureCapacity(newSize);
+ }
+
+}
Index: HLAfixedRecordImpl.java
===================================================================
RCS file: HLAfixedRecordImpl.java
diff -N HLAfixedRecordImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ HLAfixedRecordImpl.java 22 Feb 2012 18:51:24 -0000 1.1
@@ -0,0 +1,128 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2011 Eric Noulard
+//
+// 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 ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// 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, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// ----------------------------------------------------------------------------
+package hla.rti1516e.jlc;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+
+import hla.rti1516e.encoding.ByteWrapper;
+import hla.rti1516e.encoding.DataElement;
+import hla.rti1516e.encoding.DataElementFactory;
+import hla.rti1516e.encoding.DecoderException;
+import hla.rti1516e.encoding.EncoderException;
+
+public class HLAfixedRecordImpl extends DataElementBase
+ implements hla.rti1516e.encoding.HLAfixedRecord {
+
+ private ArrayList<DataElement> values;
+ private DataElementFactory<DataElement> efactory;
+
+ public HLAfixedRecordImpl() {
+ values = new ArrayList<DataElement>(10);
+ }
+
+ public HLAfixedRecordImpl(int size) {
+ values = new ArrayList<DataElement>(size);
+ }
+
+ public HLAfixedRecordImpl(DataElement e) {
+ values = new ArrayList<DataElement>(10);
+ values.add(e);
+ }
+
+ public HLAfixedRecordImpl(DataElement[] elems) {
+ values = new ArrayList<DataElement>(10);
+ values.addAll(Arrays.asList(elems));
+ }
+
+ public HLAfixedRecordImpl(DataElementFactory<DataElement> factory) {
+ values = new ArrayList<DataElement>(20);
+ efactory = factory;
+ }
+
+ public void add(DataElement e) {
+ values.add(e);
+ }
+
+ public int getOctetBoundary() {
+ /* at least 4 since we encode the size */
+ int obound = 4;
+ for (Iterator<DataElement> it = values.iterator(); it.hasNext();) {
+ DataElement elem = it.next();
+ obound = Math.max(obound, elem.getOctetBoundary());
+ }
+ return obound;
+ }
+
+ public void encode(ByteWrapper byteWrapper) throws EncoderException {
+ byteWrapper.align(getOctetBoundary());
+ byteWrapper.putInt(values.size());
+ for (Iterator<DataElement> it = values.iterator(); it.hasNext();) {
+ DataElement elem = it.next();
+ elem.encode(byteWrapper);
+ }
+ }
+
+ public int getEncodedLength() {
+ int elength = 4;
+ for (Iterator<DataElement> it = values.iterator(); it.hasNext();) {
+ DataElement elem = it.next();
+ elength += elem.getEncodedLength();
+ }
+ return elength;
+ }
+
+ public void decode(ByteWrapper byteWrapper) throws DecoderException {
+ byteWrapper.align(getOctetBoundary());
+ int nbElem = byteWrapper.getInt();
+ values.ensureCapacity(nbElem);
+ /* FIXME we may optimize this in order to avoid reallocation
+ * we should
+ * - verify size
+ * - trimToSize
+ * - clear
+ * - add
+ */
+ values.clear();
+ for (int i = 0; i<nbElem;++i) {
+ DataElement elem = efactory.createElement(i);
+ elem.decode(byteWrapper);
+ values.add(elem);
+ }
+ }
+
+ public int size() {
+ return values.size();
+ }
+
+ public DataElement get(int index) {
+ return values.get(index);
+ }
+
+ public Iterator<DataElement> iterator() {
+ return values.iterator();
+ }
+
+ public void resize(int newSize) {
+ values.ensureCapacity(newSize);
+ }
+
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] jcerti/src/hla/rti1516e/jlc HLAvariableArrayImp...,
CERTI CVS commits <=