Skip to content

How to dynamically generate a Bundle that contains only outputs from a given Bundle? #2447

Answered by larluc
larluc asked this question in Q&A
Discussion options

You must be logged in to vote

Hello again,

I found a way to generate the bundle based on the "ActualDirection". My first approach was quite close to the solution:

class DirectedBundle(bundle: Bundle, dir: ActualDirection) extends Record {
  val elements =
    for ((name, data) <- bundle.elements
    if (DataMirror.directionOf(data.asInstanceOf[Data]) == dir || data.isInstanceOf[Bundle])) yield {
      if (data.isInstanceOf[Bundle]) {
        (name -> new DirectedBundle(data.asInstanceOf[Bundle], dir))
      }
      else {
        (name -> data.asInstanceOf[Data].cloneType)
      }
    }
  override def cloneType: this.type = (new DirectedBundle(bundle, dir)).asInstanceOf[this.type]
}

To instantiate a "DirectedBundle", …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by larluc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant