aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/options/OptionsView.scala
diff options
context:
space:
mode:
authorSchuyler Eldridge2018-11-07 13:48:06 -0500
committerGitHub2018-11-07 13:48:06 -0500
commit17b4e9835bd95dcf91c5ea5a4d7c52280031ea93 (patch)
treee54301b8019d17cce4448ce9d09589815a7315d5 /src/main/scala/firrtl/options/OptionsView.scala
parentd04af59c233cec994087df3d0d3fff14e20ac04c (diff)
parent27c1b366ce58e93434e77e964365474f5e7aa8d7 (diff)
Merge pull request #879 from seldridge/issue-764-refactor-pr-pointer-optionsPackage
- Adds firrtl.options package and tests - Does not use firrtl.options in any way
Diffstat (limited to 'src/main/scala/firrtl/options/OptionsView.scala')
-rw-r--r--src/main/scala/firrtl/options/OptionsView.scala27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/options/OptionsView.scala b/src/main/scala/firrtl/options/OptionsView.scala
new file mode 100644
index 00000000..dade5c56
--- /dev/null
+++ b/src/main/scala/firrtl/options/OptionsView.scala
@@ -0,0 +1,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)
+}