Class DataResolver
- java.lang.Object
-
- com.automation_pros.odva.cip.data.DataResolver
-
public class DataResolver extends java.lang.Object
Data extraction helper, with support for selected transforms.The class follows path segments into an array or structure or other base data instance, possibly concluding with a bit index.
A static method starts from a given CipTree instance.
-
-
Field Summary
Fields Modifier and Type Field Description int
bit
Bit index that applies to the subscripted element ofdata
, or, if already a CipBOOL, the bit used to produce that CipBOOL.PathSegment
bitHost
The selector that yielded a hosted bit.BaseDataType<?>
data
Innermost data instance not including subscripts or any bit index.BaseDataType<?>
data0
Outermost data instance.BaseDataType<?>
data1
Fully subscripted/bit selected data instance.int[]
dims
Dimensions ofdata
extracted for convenience.boolean
hasDebug
boolean
hasTrace
int[]
indices
Accumulated subscripts that apply todata
.protected BaseDataType<?>[]
indirectobjs
The indirection values that were extracted from the context at the indirection selectors encountered.protected int[]
indirects
The nesting levels at which indirection selectors were encountered.int
priorBytes
java.lang.Long
unusedParasiteBits
When a hosted bit, holds the unused bits of that host.
-
Constructor Summary
Constructors Constructor Description DataResolver(DataContext ctx, BaseDataType<?> root, java.util.List<PathSegment> path, int nesting)
Given a data element and a path containing zero or more selector segments, resolve the selectors to locate a specific subelement.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BaseDataType<?>
asSubscripted()
Obtain the data with the resolved indices encapsulated.static DataResolver
follow(CipTree tree, java.util.List<PathSegment> path)
Follows a path into a CipTree hierarchy, and if it stops on a DataWrapper, continues drilling into that item's data.static DataDefinitionSeg
followTransform(DataDefinitionSeg outer, PathSegment seg, DataContext ctx)
Helper that identifies supported transform symbols and returns the corresponding data type definition segment.int
getOffset()
Obtain the resolved element's byte offset within the outermost data object's complete payload.static boolean
isStringable(DataDefinitionSeg outer, DataContext ctx)
Helper that examines a data definition segment and determines if it is a structure that fits a Logix-style string type (.LEN and .DATA).static void
main(java.lang.String[] args)
boolean
newSubscript()
Determine if any indirect subscript has changed in the path to the data.java.lang.String
toString()
-
-
-
Field Detail
-
data0
public final BaseDataType<?> data0
Outermost data instance.
-
data
public BaseDataType<?> data
Innermost data instance not including subscripts or any bit index.
-
data1
public final BaseDataType<?> data1
Fully subscripted/bit selected data instance.
-
dims
public int[] dims
Dimensions ofdata
extracted for convenience.
-
indices
public int[] indices
Accumulated subscripts that apply todata
. These are always zero-based. Member offsets are applied as these are accumulated.
-
bit
public int bit
Bit index that applies to the subscripted element ofdata
, or, if already a CipBOOL, the bit used to produce that CipBOOL.
-
bitHost
public PathSegment bitHost
The selector that yielded a hosted bit.
-
unusedParasiteBits
public java.lang.Long unusedParasiteBits
When a hosted bit, holds the unused bits of that host.
-
priorBytes
public int priorBytes
-
indirects
protected int[] indirects
The nesting levels at which indirection selectors were encountered.
-
indirectobjs
protected BaseDataType<?>[] indirectobjs
The indirection values that were extracted from the context at the indirection selectors encountered. Always corresponds 1:1 withindirects
.
-
hasDebug
public final boolean hasDebug
-
hasTrace
public final boolean hasTrace
-
-
Constructor Detail
-
DataResolver
public DataResolver(DataContext ctx, BaseDataType<?> root, java.util.List<PathSegment> path, int nesting)
Given a data element and a path containing zero or more selector segments, resolve the selectors to locate a specific subelement.- Parameters:
ctx
- The reference to use for indirect subscripts, if anyroot
- The starting data elementpath
- The selectors to follownesting
- The number of leading segments to skip
-
-
Method Detail
-
follow
public static DataResolver follow(CipTree tree, java.util.List<PathSegment> path)
Follows a path into a CipTree hierarchy, and if it stops on a DataWrapper, continues drilling into that item's data.- Parameters:
tree
-path
-- Returns:
-
isStringable
public static boolean isStringable(DataDefinitionSeg outer, DataContext ctx)
Helper that examines a data definition segment and determines if it is a structure that fits a Logix-style string type (.LEN and .DATA).- Parameters:
outer
-ctx
-- Returns:
-
followTransform
public static DataDefinitionSeg followTransform(DataDefinitionSeg outer, PathSegment seg, DataContext ctx)
Helper that identifies supported transform symbols and returns the corresponding data type definition segment.- Parameters:
outer
-seg
-ctx
-- Returns:
-
newSubscript
public boolean newSubscript()
Determine if any indirect subscript has changed in the path to the data.- Returns:
- True if callers need to re-resolve the path.
-
getOffset
public int getOffset()
Obtain the resolved element's byte offset within the outermost data object's complete payload. Not valid when variable-length elements are prior to the resolved element, nor when accessing individual bits.- Returns:
- Byte offset or -1 when invalid.
-
asSubscripted
public BaseDataType<?> asSubscripted()
Obtain the data with the resolved indices encapsulated. Needed to properly support assemblies containing elements of arrays or structures.- Returns:
- A data item that is a view into the final resolved data item. If no indices nor bit number are present, then this will be the same object as returned in .data.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
-
-