Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2893_BNLR/HeuristicLab.ExtLibs/HeuristicLab.AutoDiff/1.0/AutoDiff-1.0/Sum.cs @ 17553

Last change on this file since 17553 was 8703, checked in by gkronber, 12 years ago

#1960 added HL wrapper plugin for AutoDiff

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Collections.ObjectModel;
6using System.Diagnostics;
7
8namespace AutoDiff
9{
10    /// <summary>
11    /// Represents a sum of at least two terms.
12    /// </summary>
13    [Serializable]
14    [DebuggerDisplay("Sum: {Terms.Count}")]
15    public class Sum : Term
16    {
17        /// <summary>
18        /// Constructs an instance of the <see cref="Sum"/> class.
19        /// </summary>
20        /// <param name="first">The first term in the sum</param>
21        /// <param name="second">The second term in the sum</param>
22        /// <param name="rest">The rest of the terms in the sum.</param>
23        public Sum(Term first, Term second, params Term[] rest)
24        {
25            var allTerms =
26                (new Term[] { first, second}).Concat(rest);
27
28            Terms = allTerms.ToList().AsReadOnly();
29        }
30
31        internal Sum(IEnumerable<Term> terms)
32        {
33            Terms = Array.AsReadOnly(terms.ToArray());
34        }
35
36        /// <summary>
37        /// Gets the terms of this sum.
38        /// </summary>
39        public ReadOnlyCollection<Term> Terms { get; private set; }
40       
41        /// <summary>
42        /// Accepts a term visitor
43        /// </summary>
44        /// <param name="visitor">The term visitor to accept.</param>
45        public override void Accept(ITermVisitor visitor)
46        {
47            visitor.Visit(this);
48        }
49
50        /// <summary>
51        /// Accepts a term visitor with a generic result
52        /// </summary>
53        /// <typeparam name="TResult">The type of the result from the visitor's function</typeparam>
54        /// <param name="visitor">The visitor to accept</param>
55        /// <returns>
56        /// The result from the visitor's visit function.
57        /// </returns>
58        public override TResult Accept<TResult>(ITermVisitor<TResult> visitor)
59        {
60            return visitor.Visit(this);
61        }
62    }
63}
Note: See TracBrowser for help on using the repository browser.