blob: dade5c560a72b71c6ee4350e81eae2cb5dd709cc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
// See LICENSE for license details.
package firrtl.options
import firrtl.AnnotationSeq
/** Type class defining a "view" of an [[AnnotationSeq]]
* @tparam T the type to which this viewer converts an [[AnnotationSeq]] to
*/
trait OptionsView[T] {
/** Convert an [[AnnotationSeq]] to some other type
* @param options some annotations
*/
def view(options: AnnotationSeq): Option[T]
}
/** A shim to manage multiple "views" of an [[AnnotationSeq]] */
object Viewer {
/** Convert annotations to options using an implicitly provided [[OptionsView]]
* @param options some annotations
* @param optionsView a converter of options to the requested type
* @tparam T the type to which the input [[AnnotationSeq]] should be viewed as
*/
def view[T](options: AnnotationSeq)(implicit optionsView: OptionsView[T]): Option[T] = optionsView.view(options)
}
|