static void OnClosingKey(CKey key, EKeyAddingMode inKeyAddMode, ITreeBuildSupport inSupport) { if (key == null) { return; } if (key.IsEmpty) { inSupport.GetLogger().LogError(EErrorCode.HeadWithoutValues, key); return; } if (inKeyAddMode == EKeyAddingMode.AddUnique) { return; } CKey parent = key.Parent; if (parent == null) { inSupport.GetLogger().LogError(EErrorCode.KeyMustHaveParent, key); return; } key.SetParent(null); if (inKeyAddMode == EKeyAddingMode.Override) { var pathes = new List <List <string> >(); key.GetTerminalPathes(pathes, new List <string>()); //for correct deleting array elems for (int i = pathes.Count - 1; i >= 0; --i) { var path = pathes[i]; RemoveKeysByPath(parent, path); } inKeyAddMode = EKeyAddingMode.Add; } if (inKeyAddMode == EKeyAddingMode.Add) { CKey child_key = parent.FindChildKey(key.Name); if (child_key != null) { child_key.MergeKey(key); } else { key.SetParent(parent); } } }
internal void CheckOnOneArray() { if (_keys.Count != 1) { return; } if (!_keys[0].IsArray) { return; } if (_keys[0].ValuesCount > 0) { return; } CKey arr = _keys[0]; if (!string.IsNullOrEmpty(arr._name) && !string.IsNullOrEmpty(_name)) { return; } if (!string.IsNullOrEmpty(arr._name)) { _name = arr._name; } TakeAllElements(arr, false); arr.SetParent(null); }
static void ExecuteCommand_Insert(CKey arr_key, CTokenLine line, ITreeBuildSupport inSupport) { string file_name = line.CommandParams["file"]; string key_path = line.CommandParams["key"]; if (string.IsNullOrEmpty(file_name) && string.IsNullOrEmpty(key_path)) { inSupport.GetLogger().LogError(EErrorCode.PathEmpty, line); } CKey root = null; if (!string.IsNullOrEmpty(file_name)) { root = (CKey)inSupport.GetTree(file_name); } else { root = arr_key.GetRoot(); } if (root == null) { inSupport.GetLogger().LogError(EErrorCode.CantFindInsertFile, line); return; } if (root.KeyCount == 1 && root.GetKey(0).IsArrayKey()) { root = root.GetKey(0); } CKey key = root; if (!string.IsNullOrEmpty(key_path)) { key = (CKey)root.FindKey(key_path); if (key == null) { inSupport.GetLogger().LogError(EErrorCode.CantFindKey, line); return; } } bool insert_parent = line.CommandParams.ContainsKey("parent"); CKey copy_key = key.GetCopy() as CKey; if (insert_parent) { copy_key.SetParent(arr_key); } else { arr_key.TakeAllElements(copy_key, false); } arr_key.CheckOnOneArray(); }
public EKeyOpResult AddChild(IKey inNewChild) { EKeyOpResult res = IsKeyAddable(inNewChild); if (res != EKeyOpResult.OK) { return(res); } CKey k = inNewChild as CKey; k.SetParent(this); return(res); }
public EKeyOpResult RemoveChild(IKey inChild) { CKey k = inChild as CKey; if (k == null) { return(EKeyOpResult.UnnativeKey); } if (!_keys.Contains(k)) { return(EKeyOpResult.NotFound); } k.SetParent(null); return(EKeyOpResult.OK); }
public EKeyOpResult InsertChild(int inIndexPos, IKey inChild) { EKeyOpResult res = IsKeyAddable(inChild); if (res != EKeyOpResult.OK) { return(res); } CKey k = inChild as CKey; k.SetParent(this); _keys.RemoveAt(_keys.Count - 1); _keys.Insert(inIndexPos, k); return(EKeyOpResult.OK); }
//inStartLine - next of parent line static void CollectByDivs(CKey inParent, int inParentRank, int inStartLine, int inEndLine, List <CTokenLine> inLines, ITreeBuildSupport inSupport, CKey inRoot, EKeyAddingMode inKeyAddingMode) { int curr_rank = inParentRank + 1; List <Tuple <int, int> > recs_by_divs = new List <Tuple <int, int> >(); CollectDividers(inStartLine, inEndLine, curr_rank, inLines, inSupport, recs_by_divs); if (recs_by_divs.Count > 1) { if (inKeyAddingMode == EKeyAddingMode.Override) { inParent.ClearAllArrayKeys(); } for (int i = 0; i < recs_by_divs.Count; i++) { int first_line = recs_by_divs[i].Item1; int exlude_last_line = recs_by_divs[i].Item2; if (first_line < exlude_last_line) { CKey arr_key = CKey.CreateArrayKey(inParent, inLines[first_line].Position); if (IsLinePresent(curr_rank, first_line, exlude_last_line, inLines)) { Collect(arr_key, curr_rank, first_line, exlude_last_line, inLines, inSupport, inRoot, EKeyAddingMode.AddUnique); } else { CollectByDivs(arr_key, curr_rank, first_line, exlude_last_line, inLines, inSupport, inRoot, EKeyAddingMode.AddUnique); } if (arr_key.IsEmpty) { arr_key.SetParent(null); } } } } else { Collect(inParent, inParentRank, recs_by_divs[0].Item1, recs_by_divs[0].Item2, inLines, inSupport, inRoot, inKeyAddingMode); } }
static bool RemoveKeysByPath(CKey inParent, IList <string> inPath) { CKey key = inParent.FindKey(inPath); if (key == null) { return(false); } CKey parent = key.Parent; key.SetParent(null); while (parent != inParent && parent.IsEmpty) { CKey prev = parent; parent = parent.Parent; prev.SetParent(null); } return(true); }
static void ExecuteCommand_Insert(CKey inParent, CTokenLine line, ITreeBuildSupport inSupport, CKey inRoot) { string file_name = line.CommandParams["file"]; string key_path = line.CommandParams["key"]; if (string.IsNullOrEmpty(file_name) && string.IsNullOrEmpty(key_path)) { inSupport.GetLogger().LogError(EErrorCode.PathEmpty, line); } CKey root = inRoot; if (!string.IsNullOrEmpty(file_name)) { root = (CKey)inSupport.GetTree(file_name); } //else // root = inParent.GetRoot(); if (root == null) { inSupport.GetLogger().LogError(EErrorCode.CantFindInsertFile, line); return; } if (root.KeyCount == 1 && root.GetKey(0).IsArrayKey()) { root = root.GetKey(0); } CKey key = root; if (!string.IsNullOrEmpty(key_path)) { key = (CKey)root.FindKey(key_path); if (key == null) { inSupport.GetLogger().LogError(EErrorCode.CantFindKey, line); return; } } CKey destination_key = inParent; bool insert_in_parent = line.CommandParams.ContainsKey("insert_in_parent"); if (insert_in_parent) { if (inParent.Parent != null) { destination_key = inParent.Parent; } else { inSupport.GetLogger().LogError(EErrorCode.KeyMustHaveParent, line); } } bool add_key = line.CommandParams.ContainsKey("add_key"); CKey copy_key = key.GetCopy() as CKey; if (add_key) { copy_key.SetParent(destination_key); } else { destination_key.TakeAllElements(copy_key, false); } destination_key.CheckOnOneArray(); }