Example #1
0
        //- setting values ----------------------------------------------------

        private void setLeafValue(String path, SettingsStem subtree, String val)
        {
            int dotpos = path.IndexOf('.');

            if (dotpos != -1)                                                           //path is name.subpath
            {
                String name    = path.Substring(0, dotpos);
                String subpath = path.Substring(dotpos + 1);
                if (!subtree.children.ContainsKey(name))
                {
                    subtree.children[name] = new SettingsStem();
                }
                setLeafValue(subpath, (SettingsStem)subtree.children[name], val);
            }
            else
            {
                if (!subtree.children.ContainsKey(path))
                {
                    subtree.children[path] = new SettingsLeaf(val);
                }
                else
                {
                    ((SettingsLeaf)subtree.children[path]).value = val;
                }
            }
        }
Example #2
0
        //- getting values ----------------------------------------------------

        private String findLeafValue(String path, SettingsStem subtree)
        {
            String result = null;
            int    dotpos = path.IndexOf('.');

            if (dotpos != -1)                                   //path is name.subpath
            {
                String name    = path.Substring(0, dotpos);
                String subpath = path.Substring(dotpos + 1);    //break path apart
                if (subtree.children.ContainsKey(name))
                {
                    SettingsNode val = subtree.children[name];
                    if (val != null && val is SettingsStem)
                    {
                        result = findLeafValue(subpath, (SettingsStem)val);
                    }
                }
            }
            else
            {
                if (subtree.children.ContainsKey(path))
                {
                    SettingsNode leaf = subtree.children[path];
                    if (leaf != null && leaf is SettingsLeaf)
                    {
                        result = ((SettingsLeaf)leaf).value;
                    }
                }
            }
            return(result);
        }
Example #3
0
 public void setStringValue(String path, String str)
 {
     if (root == null)
     {
         root = new SettingsStem();
     }
     setLeafValue(path, root, str);
 }
Example #4
0
        private void storeSubTree(List <string> lines, SettingsStem stem, String indent)
        {
            List <string> childNameList = new List <string>(stem.children.Keys);

            foreach (String childname in childNameList)
            {
                storeNode(lines, stem.children[childname], indent + ((stem != root) ? "  " : ""), childname);
            }
        }
Example #5
0
        public void setIntValue(String path, int val)
        {
            String intstr = val.ToString();

            if (root == null)
            {
                root = new SettingsStem();
            }
            setLeafValue(path, root, intstr);
        }
Example #6
0
        private SettingsStem parseSubtree(string[] lines, ref int lineNum)
        {
            SettingsStem curStem     = new SettingsStem();
            int          indentLevel = -1;

            while (lineNum < lines.Length)
            {
                String line = lines[lineNum++].TrimEnd(wspace);
                if (line.Length == 0 || line[0] == '#')                 //skip blank lines & comments
                {
                    continue;
                }

                int indent = 0;
                while ((indent < line.Length) && (line[indent] == ' '))
                {
                    indent++;                                                       //get line indent
                }
                if (indentLevel == -1)
                {
                    indentLevel = indent;                                           //if first line of subtree, get indent level
                }
                if (indent < indentLevel)
                {
                    lineNum--;              //this line is not in subgroup so back up one line
                    return(curStem);
                }
                else
                {
                    line = line.TrimStart(wspace);                              //we have the indent count, remove the leading spaces
                    int    colonpos = line.IndexOf(':');
                    String name     = line.Substring(0, colonpos).Trim();
                    if (colonpos + 1 != line.Length)                                //nnn : xxx
                    {
                        String val = line.Substring(colonpos + 1).Trim();
                        curStem.children.Add(name, new SettingsLeaf(val));
                    }
                    else
                    {
                        SettingsStem substem = parseSubtree(lines, ref lineNum);
                        curStem.children.Add(name, substem);
                    }
                }
            }
            return(curStem);
        }
Example #7
0
        private void getSubpathKeys(SettingsStem subtree, String path, List <String> keyList)
        {
            if (subtree == null)
            {
                return;
            }

            int dotpos = path.IndexOf('.');

            if (dotpos != -1)                                   //not at end of path - path is name.subpath
            {
                String name    = path.Substring(0, dotpos);
                String subpath = path.Substring(dotpos + 1);              //remove name from start of path
                if (subtree.children.ContainsKey(name))
                {
                    SettingsNode val = subtree.children[name];
                    if (val != null && val is SettingsStem)
                    {
                        getSubpathKeys((SettingsStem)val, subpath, keyList);
                    }
                }
            }
            else
            {
                if (subtree.children.ContainsKey(path))      //at end of path
                {
                    SettingsNode val = subtree.children[path];
                    if (val != null && val is SettingsStem)
                    {
                        foreach (string key in ((SettingsStem)val).children.Keys)
                        {
                            keyList.Add(key);
                        }
                    }
                }
            }
        }
Example #8
0
        //no error checking yet!
        private void parseRoot(string[] lines)
        {
            int lineNum = 0;

            root = parseSubtree(lines, ref lineNum);
        }
Example #9
0
 public EnamlData()
 {
     root = null;
 }