Skip to content

packages/engine/scram-node/src/model.h

Representation for a model container for risk analysis.

Namespaces

Name
scram
scram::mef

Classes

Name
classscram::mef::Model <br>This class represents a risk analysis model.

Source code

cpp
/*
 * Copyright (C) 2014-2018 Olzhas Rakhimov
 * Copyright (C) 2023 OpenPRA ORG Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#pragma once

#include <memory>
#include <string>
#include <string_view>
#include <vector>

#include "alignment.h"
#include "ccf_group.h"
#include "element.h"
#include "event.h"
#include "event_tree.h"
#include "expression.h"
#include "expression/extern.h"
#include "expression/test_event.h"
#include "fault_tree.h"
#include "instruction.h"
#include "parameter.h"
#include "substitution.h"

namespace scram::mef {

class Model
    : public Element,
      public MultiContainer<Model, InitiatingEvent, EventTree, Sequence, Rule,
                            Alignment, Substitution, FaultTree, BasicEvent,
                            Gate, HouseEvent, Parameter, CcfGroup,
                            ExternLibrary, ExternFunction<void>> {
 public:
  static constexpr const char* kTypeString = "model";

  static constexpr const char kDefaultName[] = "__unnamed-model__";

  explicit Model(std::string name = "");

  bool HasDefaultName() const { return Element::name() == kDefaultName; }

  const std::string& GetOptionalName() const {
    static const std::string empty_name("");
    return HasDefaultName() ? empty_name : Element::name();
  }

  void SetOptionalName(std::string name = "") {
    Element::name(name.empty() ? kDefaultName : std::move(name));
  }

  const MissionTime& mission_time() const { return *mission_time_; }
  MissionTime& mission_time() { return *mission_time_; }

  Context* context() const { return const_cast<Context*>(&context_); }

  auto initiating_events() const { return table<InitiatingEvent>(); }
  auto event_trees() const { return table<EventTree>(); }
  auto sequences() const { return table<Sequence>(); }
  auto rules() const { return table<Rule>(); }
  auto fault_trees() const { return table<FaultTree>(); }
  auto alignments() const { return table<Alignment>(); }
  auto substitutions() const { return table<Substitution>(); }
  auto parameters() const { return table<Parameter>(); }
  auto house_events() const { return table<HouseEvent>(); }
  auto basic_events() const { return table<BasicEvent>(); }
  auto gates() const { return table<Gate>(); }
  auto ccf_groups() const { return table<CcfGroup>(); }
  auto libraries() const { return table<ExternLibrary>(); }
  auto extern_functions() const { return table<ExternFunction<void>>(); }

  using Composite::Add;
  using Composite::Remove;

  void Add(std::unique_ptr<HouseEvent> element) {
    AddEvent(std::move(element));
  }
  void Add(std::unique_ptr<BasicEvent> element) {
    AddEvent(std::move(element));
  }
  void Add(std::unique_ptr<Gate> element) { AddEvent(std::move(element)); }
  void Add(std::unique_ptr<Expression> element) {
    expressions_.emplace_back(std::move(element));
  }
  void Add(std::unique_ptr<Instruction> element) {
    instructions_.emplace_back(std::move(element));
  }

  Formula::ArgEvent GetEvent(std::string_view id);

 private:
  template <class T>
  void AddEvent(std::unique_ptr<T> element) {
    CheckDuplicateEvent(*element);
    Composite::Add(std::move(element));
  }

  void CheckDuplicateEvent(const Event& event);

  std::vector<std::unique_ptr<Expression>> expressions_;
  std::vector<std::unique_ptr<Instruction>> instructions_;

  std::unique_ptr<MissionTime> mission_time_;  
  Context context_;  
};

}  // namespace scram::mef

Updated on 2025-11-11 at 16:51:08 +0000