toImmutable() public method

public toImmutable ( ) : object
return object
Example #1
0
        private static List loadDatabase()
        {
            InStream input         = null;
            List     quantityNames = new List(Sys.StrType);

            try
            {
                // parse etc/sys/units.fog as big serialized list which contains
                // lists for each quantity (first item being the name)
                String path = "etc/sys/units.txt";
                input = Env.cur().findFile(path).@in();

                // parse each line
                string curQuantityName = null;
                List   curQuantityList = null;
                string line;
                while ((line = input.readLine()) != null)
                {
                    // skip comment and blank lines
                    line = line.Trim();
                    if (line.StartsWith("//") || line.Length == 0)
                    {
                        continue;
                    }

                    // quanity sections delimited as "-- name (dim)"
                    if (line.StartsWith("--"))
                    {
                        if (curQuantityName != null)
                        {
                            m_quantities[curQuantityName] = curQuantityList.toImmutable();
                        }
                        curQuantityName = line.Substring(2, line.IndexOf('(') - 2).Trim();
                        curQuantityList = new List(Sys.UnitType);
                        quantityNames.add(curQuantityName);
                        continue;
                    }

                    // must be a unit
                    try
                    {
                        Unit unit = Unit.define(line);
                        curQuantityList.add(unit);
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine("WARNING: Init unit in etc/sys/units.txt: " + line);
                        System.Console.WriteLine("  " + e);
                    }
                }
                m_quantities[curQuantityName] = curQuantityList.toImmutable();
            }
            catch (Exception e)
            {
                try { input.close(); } catch (Exception) {}
                System.Console.WriteLine("WARNING: Cannot load lib/units.txt");
                Err.dumpStack(e);
            }
            return((List)quantityNames.toImmutable());
        }
Example #2
0
 static List checkIds(List ids)
 {
     if (ids.sz() == 0)
     {
         throw ParseErr.make("No unit ids defined").val;
     }
     for (int i = 0; i < ids.sz(); ++i)
     {
         checkId((string)ids.get(i));
     }
     return((List)ids.toImmutable());
 }
Example #3
0
 public List list()
 {
     if (m_list == null)
     {
         m_list = new List(Sys.FacetType, m_map.Count);
         IDictionaryEnumerator en = ((Hashtable)m_map.Clone()).GetEnumerator();
         while (en.MoveNext())
         {
             Type type = (Type)en.Key;
             m_list.add(get(type, true));
         }
         m_list = (List)m_list.toImmutable();
     }
     return(m_list);
 }
Example #4
0
File: Unit.cs Project: nomit007/f4
        private static List loadDatabase()
        {
            InStream input = null;
              List quantityNames = new List(Sys.StrType);
              try
              {
            // parse etc/sys/units.fog as big serialized list which contains
            // lists for each quantity (first item being the name)
            String path = "etc/sys/units.txt";
            input = Env.cur().findFile(path).@in();

            // parse each line
            string curQuantityName = null;
            List curQuantityList = null;
            string line;
            while ((line = input.readLine()) != null)
            {
              // skip comment and blank lines
              line = line.Trim();
              if (line.StartsWith("//") || line.Length == 0) continue;

              // quanity sections delimited as "-- name (dim)"
              if (line.StartsWith("--"))
              {
            if (curQuantityName != null) m_quantities[curQuantityName] = curQuantityList.toImmutable();
            curQuantityName = line.Substring(2, line.IndexOf('(')-2).Trim();
            curQuantityList = new List(Sys.UnitType);
            quantityNames.add(curQuantityName);
            continue;
              }

              // must be a unit
              try
              {
            Unit unit = Unit.define(line);
            curQuantityList.add(unit);
              }
              catch (Exception e)
              {
            System.Console.WriteLine("WARNING: Init unit in etc/sys/units.txt: " + line);
            System.Console.WriteLine("  " + e);
              }
            }
            m_quantities[curQuantityName] = curQuantityList.toImmutable();
              }
              catch (Exception e)
              {
            try { input.close(); } catch (Exception) {}
            System.Console.WriteLine("WARNING: Cannot load lib/units.txt");
            Err.dumpStack(e);
              }
              return (List)quantityNames.toImmutable();
        }
Example #5
0
File: Unit.cs Project: nomit007/f4
 static List checkIds(List ids)
 {
     if (ids.sz() == 0) throw ParseErr.make("No unit ids defined").val;
       for (int i=0; i<ids.sz(); ++i) checkId((string)ids.get(i));
       return (List)ids.toImmutable();
 }
Example #6
0
 public List list()
 {
     if (m_list == null)
       {
     m_list = new List(Sys.FacetType, m_map.Count);
     IDictionaryEnumerator en = ((Hashtable)m_map.Clone()).GetEnumerator();
     while (en.MoveNext())
     {
       Type type = (Type)en.Key;
       m_list.add(get(type, true));
     }
     m_list = (List)m_list.toImmutable();
       }
       return m_list;
 }