//****************************************************************************************************** // CompoundValue.cs - Gbtc // // Copyright © 2010, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/eclipse-1.0.php // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 01/25/2008 - J. Ritchie Carroll // Initial version of source generated. // 09/14/2009 - Stephen C. Wills // Added new header and license agreement. // 10/8/2012 - Danyelle Gilliam // Modified Header // //****************************************************************************************************** #region [ Contributor License Agreements ] /**************************************************************************\ Copyright © 2009 - J. Ritchie Carroll All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \**************************************************************************/ #endregion using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace GSF { /// /// Represents a collection of individual values that together represent a compound value once all the values have been assigned. /// /// /// Composite values are stored as and can be cumulated until all values have been assigned so that a /// compound value can be created. /// /// of composite values. public class CompoundValue : Collection where T: struct { #region [ Constructors ] /// /// Creates a new . /// public CompoundValue() { } /// /// Creates a new specifing the total number of composite values to track. /// /// /// The specified of items are added to the , /// each item will be marked as unassigned (i.e., null). /// /// Total number of composite values to track. public CompoundValue(int count) { for (int i = 0; i < count; i++) { Add(null); } } /// /// Creates a new from the specified list. /// /// List of values used to initialize . public CompoundValue(IEnumerable values) : base(values.ToList().ConvertAll(item => item)) { } /// /// Creates a new from the specified list. /// /// List of values used to initialize . public CompoundValue(IEnumerable values) : base(values.ToList()) { } #endregion #region [ Properties ] /// /// Gets a boolean value indicating if all of the composite values have been assigned a value. /// /// True, if all composite values have been assigned a value; otherwise, false. public bool AllAssigned { get { return this.All(item => item.HasValue); } } /// /// Gets a boolean value indicating if none of the composite values have been assigned a value. /// /// True, if no composite values have been assigned a value; otherwise, false. public bool NoneAssigned { get { return this.All(item => !item.HasValue); } } #endregion #region [ Methods ] /// /// Gets an array of all the elements of the . /// /// A new array containing copies of the elements of the . public T[] ToArray() { T[] values = new T[Count]; for (int i = 0; i < Count; i++) { values[i] = this[i].GetValueOrDefault(); } return values; } #endregion } }