SetName + replaceDataFromFile

This commit is contained in:
Морозов Андрей 2021-11-05 15:25:16 +04:00
parent e4d8d6133c
commit 26d610b302
1 changed files with 45 additions and 6 deletions

View File

@ -174,6 +174,8 @@ class Graphs {
_fixAfterDel(inn); _fixAfterDel(inn);
return null; return null;
} }
void flushData() => _dots = <Dot>[];
//*********Delete********* //*********Delete*********
//******Helper******* //******Helper*******
@ -242,6 +244,49 @@ class Graphs {
} }
//******Helper******* //******Helper*******
//*****Setters*******
void setName(String name) => _name = name;
String? replaceDataFromFile(String path) {
Separators sep = Separators();
File file = File(path);
List<String> lines = file.readAsLinesSync();
_name = lines.removeAt(0);
_oriented = lines.removeAt(0) == sep.isOriented.trim();
_useLength = lines.removeAt(0) == sep.hasLength.trim();
_dots = <Dot>[];
for (var l in lines) {
l = l.trimRight();
if (l != sep.end) {
var spl = l.split(sep.space);
List<int> dot = <int>[];
List<int> len = <int>[];
String name = spl.removeAt(0);
name = name.substring(0, name.length - 1);
for (var splitted in spl) {
if (splitted != "") {
var dt = splitted.split(sep.dotToLength);
if (dt.length == 2) {
dot.add(int.parse(dt[0]));
if (_useLength) {
len.add(int.parse(dt[1]));
} else {
len.add(0);
}
} else if (dt.length == 1) {
dot.add(int.parse(splitted));
len.add(0);
}
}
}
_dots.add(Dot.fromTwoLists(name, dot, len));
}
}
_syncNum();
_syncNameTable();
if (!_oriented) _fullFix();
}
//*****Setters*******
//*****Getters******* //*****Getters*******
bool getDoubleSided() => _oriented; bool getDoubleSided() => _oriented;
bool getUseLength() => _useLength; bool getUseLength() => _useLength;
@ -401,12 +446,6 @@ class Graphs {
_syncNameTable(); _syncNameTable();
} }
//***********Cleaning***********
void flushData() {
_dots = <Dot>[];
}
//***********Cleaning***********
//************Алгоритмы************ //************Алгоритмы************
bool bfsHasPath(int startDot, int goalDot) { bool bfsHasPath(int startDot, int goalDot) {
// обход в ширину // обход в ширину