/// <summary>
        /// Save the specified object.
        /// </summary>
        ///
        /// <param name="os">The output stream to write to.</param>
        /// <param name="obj">The object to save.</param>
        public static void SaveObject(Stream os, Object obj)
        {
            try
            {
                IEncogPersistor p = PersistorRegistry.Instance
                                    .GetPersistor(obj.GetType());

                if (p == null)
                {
                    throw new PersistError("Do not know how to persist object: "
                                           + obj.GetType().Name);
                }

                os.Flush();
                var      pw  = new StreamWriter(os);
                DateTime now = DateTime.Now;
                pw.WriteLine("encog," + p.PersistClassString + ",java,"
                             + EncogFramework.Version + "," + p.FileVersion + ","
                             + (now.Ticks / 10000));
                pw.Flush();
                p.Save(os, obj);
            }
            catch (IOException ex)
            {
                throw new PersistError(ex);
            }
        }
        /// <summary>
        /// Load an object from an input stream.
        /// </summary>
        ///
        /// <param name="mask0">The input stream to read from.</param>
        /// <returns>The loaded object.</returns>
        public static Object LoadObject(Stream mask0)
        {
            String header = ReadLine(mask0);

            String[] paras = header.Split(',');

            if (!"encog".Equals(paras[0]))
            {
                throw new PersistError("Not a valid EG file.");
            }

            String name = paras[1];

            IEncogPersistor p = PersistorRegistry.Instance.GetPersistor(
                name);

            if (p == null)
            {
                throw new PersistError("Do not know how to read the object: "
                                       + name);
            }

            if (p.FileVersion < Int32.Parse(paras[4]))
            {
                throw new PersistError(
                          "The file you are trying to read is from a later version of Encog.  Please upgrade Encog to read this file.");
            }

            return(p.Read(mask0));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Add a persistor.
 /// </summary>
 ///
 /// <param name="persistor">The persistor to add.</param>
 public void Add(IEncogPersistor persistor)
 {
     _map[persistor.PersistClassString] = persistor;
     _classMap[persistor.NativeType]    = persistor;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Add a persistor.
 /// </summary>
 ///
 /// <param name="persistor">The persistor to add.</param>
 public void Add(IEncogPersistor persistor)
 {
     _map[persistor.PersistClassString] = persistor;
     _classMap[persistor.NativeType] = persistor;
 }
Exemplo n.º 5
0
 public void Add(IEncogPersistor persistor)
 {
     this._x12fedb3de1c57ea7[persistor.PersistClassString] = persistor;
     this._x785cd8b1f9494d74[persistor.NativeType] = persistor;
 }