diff --git a/src/CacheSim/Model.elm b/src/CacheSim/Model.elm index f068892..f188915 100644 --- a/src/CacheSim/Model.elm +++ b/src/CacheSim/Model.elm @@ -1,11 +1,14 @@ module CacheSim.Model exposing (..) import CacheSim.Raw exposing (..) +import CacheSim.Hierarchy exposing (..) type alias Model = { rawHierarchy : RawCacheModelHierarchy + , hierarchy : Maybe CacheHierarchy } type alias Flags = () type Msg = ChangeRawModel Int (RawCacheModel -> RawCacheModel) | CreateRawModel | DeleteRawModel Int + | UseHierarchy (Maybe CacheModelHierarchy) diff --git a/src/CacheSim/Update.elm b/src/CacheSim/Update.elm index 5b48e2c..c69d6c0 100644 --- a/src/CacheSim/Update.elm +++ b/src/CacheSim/Update.elm @@ -1,5 +1,6 @@ module CacheSim.Update exposing (..) import CacheSim.Model exposing (..) +import CacheSim.Hierarchy exposing (..) import CacheSim.Raw exposing (..) import CacheSim.IntMap exposing (..) @@ -27,3 +28,11 @@ updateDeleteRawModel l m = cmd = Cmd.none in (newModel, cmd) + +updateUseHierarchy : Maybe CacheModelHierarchy -> Model -> (Model, Cmd Msg) +updateUseHierarchy cmh m = + let + newModel = { m | hierarchy = Maybe.map freshCacheHierarchy cmh } + cmd = Cmd.none + in + (newModel, cmd) diff --git a/src/CacheSim/View.elm b/src/CacheSim/View.elm index f574b3a..bed1316 100644 --- a/src/CacheSim/View.elm +++ b/src/CacheSim/View.elm @@ -64,7 +64,9 @@ viewRawCacheModelHierarchy rcmh = Err e -> viewError False e newButton = button "Add level" CreateRawModel - useButton = optionalButton isValid "Use hierarchy" CreateRawModel + useButton = case translationResult of + Ok cmh -> optionalButton True "Use hierarchy" (UseHierarchy <| Just cmh) + Err _ -> optionalButton False "Use hierarchy" (UseHierarchy Nothing) in div [ class "cache-model-hierarchy" ] [ h2 [] [ text "Cache hierarchy" ] diff --git a/src/Main.elm b/src/Main.elm index 3a5ce63..447ba9f 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -17,6 +17,7 @@ init f = let initialModel = { rawHierarchy = testCacheModelHierarchy + , hierarchy = Nothing } in (initialModel, Cmd.none) @@ -33,6 +34,7 @@ update msg m = ChangeRawModel l f -> updateChangeRawModel l f m CreateRawModel -> updateCreateRawModel m DeleteRawModel i -> updateDeleteRawModel i m + UseHierarchy cmh -> updateUseHierarchy cmh m subscriptions : Model -> Sub Msg subscriptions m = Sub.none