Esempio n. 1
0
        private String GetValue(String op, String var1, String position1, String var2, String position2,
                                UserType utPosition, UserType global, String option = "0")
        {
            // COMP<, COMP>, EQ, NOTEQ
            if (null == utPosition)
            {
                return("ERROR");
            }

            var x = Get(var1, position1, utPosition, global);
            var y = Get(var2, position2, utPosition, global);

            if ("~" != position1 && false == x.first)
            {
                return("ERROR GV1");
            }
            if ("~" != position2 && false == y.first)
            {
                return("ERROR GV2");
            }
            //
            if (((x.first && x.second.size() > 1) || (y.first && y.second.size() > 1)))
            {
                return("ERROR GV3");
            }

            Vector <ItemType <String> > value1 = new Vector <ItemType <String> >();  // Item<String> <-
            Vector <ItemType <String> > value2 = new Vector <ItemType <String> >();

            // added..
            if (position1 != "~")
            {
                value1 = x.second.get(0).GetItem(var1);
            }
            if (position2 != "~")
            {
                value2 = y.second.get(0).GetItem(var2);
            }
            //
            if (position1 == "~")
            {
                value1.push_back(new ItemType <String>()); // var1
                value1.get(0).Push(var1);
            }
            if (position2 == "~")
            {
                value2.push_back(new ItemType <String>()); // var2
                value2.get(0).Push(var2);
            }

            //
            if (value1.size() == 0)
            {
                return("ERROR GV4");
            }
            if (value2.size() == 0)
            {
                return("ERROR GV5");
            }

            if (option == "0" && (value1.size() > 1 || value2.size() > 1))
            {
                return("ERROR GV6");
            }

            if ("COMP<" == op)
            {
                if ("0" != option)
                { // ToDo.. // 0. just 1-1, // 1. for any case // 2. for all case
                    for (int i = 0; i < value1.size(); ++i)
                    {
                        for (int j = 0; j < value2.size(); ++j)
                        {
                            if (Compare(value1.get(i).GetVal(), value2.get(j).GetVal()) == "< 0")
                            {
                                if ("1" == option)
                                {
                                    return("TRUE");
                                }
                            }
                            else
                            {
                                if ("2" == option)
                                {
                                    return("FALSE");
                                }
                            }
                        }
                    }
                    if ("1" == option)
                    {
                        return("FALSE");
                    }
                    else if ("2" == option)
                    {
                        return("TRUE");
                    }
                }
                else
                {
                    if (Compare(value1.get(0).GetVal(), value2.get(0).GetVal()) == "< 0")
                    {
                        return("TRUE");
                    }
                }
                return("FALSE");
            }
            else if ("COMP<EQ" == op)
            {
                if ("0" != option)
                { /// ToDo.. // 0. just 1-1, // 1. for any case // 2. for all case
                    for (int i = 0; i < value1.size(); ++i)
                    {
                        for (int j = 0; j < value2.size(); ++j)
                        {
                            String temp = Compare(value1.get(i).GetVal(), value2.get(j).GetVal());
                            if (temp == "< 0" || temp == "== 0")
                            {
                                if ("1" == option)
                                {
                                    return("TRUE");
                                }
                            }
                            else
                            {
                                if ("2" == option)
                                {
                                    return("FALSE");
                                }
                            }
                        }
                    }
                    if ("1" == option)
                    {
                        return("FALSE");
                    }
                    else if ("2" == option)
                    {
                        return("TRUE");
                    }
                }
                else
                {
                    String temp = Compare(value1.get(0).GetVal(), value2.get(0).GetVal());
                    if (temp == "< 0" || temp == "== 0")
                    {
                        return("TRUE");
                    }
                }
                return("FALSE");
            }
            else if ("COMP>" == op)
            {
                if ("0" != option)
                { /// ToDo.. // 0. just 1-1, // 1. for any case // 2. for all case
                    for (int i = 0; i < value1.size(); ++i)
                    {
                        for (int j = 0; j < value2.size(); ++j)
                        {
                            if (Compare(value1.get(i).GetVal(), value2.get(j).GetVal()) == "> 0")
                            {
                                if ("1" == option)
                                {
                                    return("TRUE");
                                }
                            }
                            else
                            {
                                if ("2" == option)
                                {
                                    return("FALSE");
                                }
                            }
                        }
                    }
                    if ("1" == option)
                    {
                        return("FALSE");
                    }
                    else if ("2" == option)
                    {
                        return("TRUE");
                    }
                }
                else
                {
                    if (Compare(value1.get(0).GetVal(), value2.get(0).GetVal()) == "> 0")
                    {
                        return("TRUE");
                    }
                }
                return("FALSE");
            }
            else if ("COMP>EQ" == op)
            {
                if ("0" != option)
                { /// ToDo.. // 0. just 1-1, // 1. for any case // 2. for all case
                    for (int i = 0; i < value1.size(); ++i)
                    {
                        for (int j = 0; j < value2.size(); ++j)
                        {
                            String temp = Compare(value1.get(i).GetVal(), value2.get(j).GetVal());
                            if (temp == "> 0" || temp == "== 0")
                            {
                                if ("1" == option)
                                {
                                    return("TRUE");
                                }
                            }
                            else
                            {
                                if ("2" == option)
                                {
                                    return("FALSE");
                                }
                            }
                        }
                    }
                    if ("1" == option)
                    {
                        return("FALSE");
                    }
                    else if ("2" == option)
                    {
                        return("TRUE");
                    }
                }
                else
                {
                    String temp = Compare(value1.get(0).GetVal(), value2.get(0).GetVal());
                    if (temp == "> 0" || temp == "== 0")
                    {
                        return("TRUE");
                    }
                }
                return("FALSE");
            }
            else if ("EQ" == op)
            {
                if ("0" != option)
                { /// ToDo.. // 0. just 1-1, // 1. for any case // 2. for all case
                    for (int i = 0; i < value1.size(); ++i)
                    {
                        for (int j = 0; j < value2.size(); ++j)
                        {
                            if (Compare(value1.get(i).GetVal(), value2.get(j).GetVal()) == "== 0")
                            {
                                if ("1" == option)
                                {
                                    return("TRUE");
                                }
                            }
                            else
                            {
                                if ("2" == option)
                                {
                                    return("FALSE");
                                }
                            }
                        }
                    }
                    if ("1" == option)
                    {
                        return("FALSE");
                    }
                    else if ("2" == option)
                    {
                        return("TRUE");
                    }
                }
                else
                {
                    if (Compare(value1.get(0).GetVal(), value2.get(0).GetVal()) == "== 0")
                    {
                        return("TRUE");
                    }
                }
                return("FALSE");
            }
            else if ("NOTEQ" == op)
            {
                if ("0" != option)
                { /// ToDo.. // 0. just 1-1, // 1. for any case // 2. for all case
                    for (int i = 0; i < value1.size(); ++i)
                    {
                        for (int j = 0; j < value2.size(); ++j)
                        {
                            if (Compare(value1.get(i).GetVal(), value2.get(j).GetVal()) != "== 0")
                            {
                                if ("1" == option)
                                {
                                    return("TRUE");
                                }
                            }
                            else
                            {
                                if ("2" == option)
                                {
                                    return("FALSE");
                                }
                            }
                        }
                    }
                    if ("1" == option)
                    {
                        return("FALSE");
                    }
                    else if ("2" == option)
                    {
                        return("TRUE");
                    }
                }
                else
                {
                    if (Compare(value1.get(0).GetVal(), value2.get(0).GetVal()) != "== 0")
                    {
                        return("TRUE");
                    }
                }
                return("FALSE");
            }

            return("ERROR GV7");
        }
Esempio n. 2
0
        private String GetValue(String op, String var, String val, UserType utPosition, UserType global, String option = "0")
        {
            /// ExistItem, ExistUserType
            if (null == utPosition)
            {
                return("ERROR");
            }
            if ("EXISTITEM" == op)
            { /// option == 1?
                var x = Get(var, val, utPosition, global);
                if (x.first)
                {
                    //if (x.second.size() > 1) { return "ERROR"; } ///
                    for (int i = 0; i < x.second.size(); ++i)
                    {
                        if (x.second.get(i).GetItem(var).size() > 0)
                        {
                            return("TRUE");
                        }
                    }
                    return("FALSE");
                }
                return("FALSE");
            }
            else if ("EXISTUSERTYPE" == op)
            { /// option == 1?
                var x = Get(var, val, utPosition, global);
                if (x.first)
                {
                    //if (x.second.size() > 1) { return "ERROR"; } ///
                    for (int i = 0; i < x.second.size(); ++i)
                    {
                        if (x.second.get(i).GetUserTypeItem(var).size() > 0)
                        {
                            return("TRUE");
                        }
                    }
                    return("FALSE");
                }
                return("FALSE");
            }
            else if ("NOTEXISTITEM" == op)
            { /// option == 2 ?
                var x = Get(var, val, utPosition, global);
                if (x.first)
                {
                    //if (x.second.size() > 1) { return "ERROR"; } ///

                    for (int i = 0; i < x.second.size(); ++i)
                    {
                        if (0 < x.second.get(i).GetItem(var).size())
                        {
                            return("FALSE");
                        }
                    }
                    return("TRUE");
                }
                return("FALSE");
            }
            else if ("NOTEXISTUSERTYPE" == op)
            { /// option == 2 ?
                var x = Get(var, val, utPosition, global);
                if (x.first)
                {
                    //if (x.second.size() > 1) { return "ERROR"; } ///

                    for (int i = 0; i < x.second.size(); ++i)
                    {
                        if (0 < x.second.get(i).GetUserTypeItem(var).size())
                        {
                            return("FALSE");
                        }
                    }
                    return("TRUE");
                }
                return("FALSE");
            }

            return("ERROR");
        }
Esempio n. 3
0
        private Pair <bool, Vector <UserType> > Get(String var, String position, UserType utPosition, UserType global)
        {
            String          valTemp   = position;
            StringTokenizer tokenizer = new StringTokenizer(position, "/");
            UserType        utTemp    = new UserType("");

            if (false == tokenizer.hasMoreTokens())
            {
                utTemp = utPosition;
            }
            else
            {
                if (tokenizer.nextToken() != "root")
                {
                    utTemp = utPosition;
                }
                else
                {
                    valTemp = StringUtility.subString(position, 5);
                    utTemp  = global;
                }
            }
            return(UserType.Find(utTemp, valTemp));
        }
Esempio n. 4
0
        // Find Directory?
        public static Pair <bool, Vector <UserType> > Find(UserType global, String _position) /// option, option_offset
        {
            String            position = _position;
            Vector <UserType> temp     = new Vector <UserType>();

            if (position.Length != 0 && position[0] == '@')
            {
                position.Remove(0, 1);
            }
            if (position.Length == 0)
            {
                temp.push_back(global); return(new Pair <bool, Vector <UserType> >(true, temp));
            }
            if (position == ".")
            {
                temp.push_back(global); return(new Pair <bool, Vector <UserType> >(true, temp));
            }
            if (position == "/./")
            {
                temp.push_back(global); return(new Pair <bool, Vector <UserType> >(true, temp));
            }                                                                                                                   // chk..
            if (position == "/.")
            {
                temp.push_back(global); return(new Pair <bool, Vector <UserType> >(true, temp));
            }
            if (StringUtility.startsWith(position, "/."))
            {
                position = StringUtility.subString(position, 3);
            }

            StringTokenizer tokenizer            = new StringTokenizer(position, "/");
            Vector <String> strVec               = new Vector <String>();
            Deck <Pair <UserType, int> > utDeck  = new Deck <Pair <UserType, int> >();
            Pair <UserType, int>         utTemp  = new Pair <UserType, int>(global, 0);
            ItemType <UserType>          utTemp2 = new ItemType <UserType>();

            for (int i = 0; i < tokenizer.countTokens(); ++i)
            {
                String strTemp = tokenizer.nextToken();
                if (strTemp == "root" && i == 0)
                {
                }
                else
                {
                    strVec.push_back(strTemp);
                }

                if ((strVec.size() >= 1) && (" " == strVec.back()))                 /// chk!!
                {
                    strVec.set(strVec.size() - 1, "");
                }
            }

            // maybe, has bug!
            {
                int count = 0;

                for (int i = 0; i < strVec.size(); ++i)
                {
                    if (strVec.get(i) == "..")
                    {
                        count++;
                    }
                    else
                    {
                        break;
                    }
                }

                strVec.reverse();

                for (int i = 0; i < count; ++i)
                {
                    if (utTemp.first == null)
                    {
                        return(new Pair <bool, Vector <UserType> >(false, new Vector <UserType>()));
                    }
                    utTemp.first = utTemp.first.GetParent();
                    strVec.pop_back();
                }
                strVec.reverse();
            }

            utDeck.push_front(utTemp);

            bool exist = false;

            while (false == utDeck.empty())
            {
                utTemp = utDeck.pop_front();

                if (utTemp.second < strVec.size() &&
                    StringUtility.startsWith(strVec.get(utTemp.second), "$ut")
                    )
                {
                    long idx = 0;
                    if (false == long.TryParse(StringUtility.subString(strVec.get(utTemp.second), 3), out idx))
                    {
                        throw new Exception("$ut..., ... is not long(integer)"); //
                    }

                    if (idx < 0 || idx >= utTemp.first.GetUserTypeListSize())
                    {
                        throw new Exception("ERROR NOT VALID IDX");
                    }

                    utDeck.push_front(new Pair <UserType, int>(utTemp.first.GetUserTypeList((int)idx), utTemp.second + 1));
                }
                else if (utTemp.second < strVec.size() && strVec.get(utTemp.second) == "$")
                {
                    for (int j = utTemp.first.GetUserTypeListSize() - 1; j >= 0; --j)
                    {
                        UserType x = utTemp.first.GetUserTypeList(j);
                        utDeck.push_front(new Pair <UserType, int>(x, utTemp.second + 1));
                    }
                }
                else if (utTemp.second < strVec.size() &&
                         (utTemp.first.GetUserTypeItem(strVec.get(utTemp.second)).empty() == false))
                {
                    Vector <UserType> x = utTemp.first.GetUserTypeItem(strVec.get(utTemp.second));
                    for (int j = x.size() - 1; j >= 0; --j)
                    {
                        utDeck.push_front(new Pair <UserType, int>(x.get(j), utTemp.second + 1));
                    }
                }

                if (utTemp.second == strVec.size())
                {
                    exist = true;
                    temp.push_back(utTemp.first);
                }
            }
            if (false == exist)
            {
                return(new Pair <bool, Vector <UserType> >(false, new Vector <UserType>()));
            }
            else
            {
                return(new Pair <bool, Vector <UserType> >(true, temp));
            }
        }
Esempio n. 5
0
        /// save2 - for more seed loading data!
        private void Save2(StreamWriter sw, UserType ut, int depth = 0)
        {
            int itemListCount     = 0;
            int userTypeListCount = 0;

            for (int i = 0; i < ut.commentList.size(); ++i)
            {
                for (int k = 0; k < depth; ++k)
                {
                    sw.Write("\t");
                }
                sw.Write(ut.commentList.get(i));

                if (i < ut.commentList.size() - 1 || false == ut.ilist.empty())
                {
                    sw.Write("\n");
                }
            }
            for (int i = 0; i < ut.ilist.size(); ++i)
            {
                if (ut.IsItemType(i))
                {
                    for (int j = 0; j < ut.itemList.get(itemListCount).size(); j++)
                    {
                        for (int k = 0; k < depth; ++k)
                        {
                            sw.Write("\t");
                        }
                        if (ut.itemList.get(itemListCount).GetName() != "")
                        {
                            sw.Write(ut.itemList.get(itemListCount).GetName() + " = ");
                        }
                        sw.Write(ut.itemList.get(itemListCount).GetVal());
                        if (j != ut.itemList.get(itemListCount).size() - 1)
                        {
                            sw.Write(" ");
                        }
                    }
                    if (i != ut.ilist.size() - 1)
                    {
                        sw.WriteLine("");
                    }
                    itemListCount++;
                }
                else
                {
                    if (ut.userTypeList.get(userTypeListCount).GetName() != "")
                    {
                        sw.Write(ut.userTypeList.get(userTypeListCount).GetName() + " = ");
                    }
                    sw.WriteLine("{");


                    Save2(sw, ut.userTypeList.get(userTypeListCount), depth + 1);
                    sw.WriteLine("");

                    for (int k = 0; k < depth; ++k)
                    {
                        sw.WriteLine("\t");
                    }
                    sw.WriteLine("}");
                    if (i != ut.ilist.size() - 1)
                    {
                        sw.WriteLine("");
                    }
                    userTypeListCount++;
                }
            }
        }
Esempio n. 6
0
 public UserType(UserType other) : base(other.GetName())
 {
     Reset(other);
 }