#region License Information
/* HeuristicLab
* Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using HeuristicLab.Core;
using System.IO;
using HeuristicLab.Persistence.Default.Xml;
namespace HeuristicLab.Operators.MPISupport {
///
/// A simple wrapper to transport items over the message passing interface
///
[Serializable]
public class MPITransportWrapper: ISerializable where T: class, IItem {
[NonSerialized]
private T innerItem;
public T InnerItem {
get {
return innerItem;
}
}
public MPITransportWrapper(T item) {
innerItem = item;
}
protected MPITransportWrapper(SerializationInfo info, StreamingContext context) {
byte[] buffer = info.GetValue("Item", typeof(byte[])) as byte[];
if (buffer != null)
innerItem = XmlParser.Deserialize(new MemoryStream(buffer)) as T;
else
innerItem = null;
}
#region ISerializable Members
public void GetObjectData(SerializationInfo info, StreamingContext context) {
object value = null;
if (innerItem != null) {
MemoryStream stream = new MemoryStream();
XmlGenerator.Serialize(innerItem, stream);
value = stream.GetBuffer();
}
info.AddValue("Item", value);
}
#endregion
}
}