Skip to content

Instantly share code, notes, and snippets.

@nikhil-RGB
Created May 11, 2024 11:00
Show Gist options
  • Save nikhil-RGB/b4b83c5e4b964dec99185434667b6853 to your computer and use it in GitHub Desktop.
Save nikhil-RGB/b4b83c5e4b964dec99185434667b6853 to your computer and use it in GitHub Desktop.
import 'package:hive_flutter/adapters.dart';
import 'package:turing_machines/models/Behaviour.dart';
import 'package:turing_machines/models/Configuration.dart';
import 'package:turing_machines/models/Tape.dart';
import 'package:turing_machines/models/TuringMachines.dart';
part "TuringMachineModel.g.dart";
@HiveType(typeId: 0)
class TuringMachineModel {
@HiveField(0)
int iterations;
@HiveField(1)
String initial_config;
@HiveField(2)
String current_config;
@HiveField(3)
Tape tape;
@HiveField(4)
List<Configuration> configs;
@HiveField(5)
List<Behaviour> behaviours;
TuringMachineModel(
{required this.iterations,
required this.initial_config,
required this.current_config,
required this.tape,
required this.configs,
required this.behaviours});
//Factory constructor for Model to save this machine object
factory TuringMachineModel.fromMachine({required TuringMachine machine}) {
//Construct object from machine object.
return TuringMachineModel(
iterations: machine.iterations,
initial_config: machine.initial_config,
current_config: machine.current_config,
tape: machine.tape,
configs: machine.machine.keys.toList(),
behaviours: machine.machine.values.toList());
//LinkedHashMap to List.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment