Represents the set variables of a Query if it was created from a string.

This class is also used to represent the results of a PlQuery after PlQuery.ToList() or PlQuery.SolutionVariables was called.

Beispiel #1
0
        /// <summary>
        /// <para>Create a <see cref="ReadOnlyCollection&lt;T&gt;"/> of <see cref="PlQueryVariables"/>.</para>
        /// <para>If calling ToList() all solutions of the query are generated and stored in the Collection.</para>
        /// </summary>
        /// <returns>A ReadOnlyCollection of PlQueryVariables containing all solutions of the query.</returns>
        /// <example>
        ///     <code source="..\..\TestSwiPl\LinqSwiPl.cs" region="Test_multi_goal_ToList_doc" />
        /// </example>
        public ReadOnlyCollection <PlQueryVariables> ToList()
        {
            List <PlQueryVariables> list = new List <PlQueryVariables>();

            EraseRecords();
            while (this.NextSolution())
            {
                for (int i = 0; i < _queryVariables.Count; i++)
                {
                    _records.Add(libpl.PL_record(_queryVariables[i].Value.TermRef));   // to keep the PlTerms
                }
            }

            PlQueryVariables qv = new PlQueryVariables(); // dummy to make the compiler happy
            int avIdx           = _queryVariables.Count;

            foreach (uint record_t in _records)
            {
                uint term_t = libpl.PL_new_term_ref();;
                libpl.PL_recorded(record_t, term_t);
                if (avIdx == _queryVariables.Count)
                {
                    qv = new PlQueryVariables();
                    list.Add(qv);
                    avIdx = 0;
                }
                //qv.Add(new PlQueryVar(GetVariableName(avIdx), new PlTerm(term_t)));   // If this line is deleted -> update comment in PlTern(term_ref)
                qv.Add(new PlQueryVar(_queryVariables[avIdx].Name, new PlTerm(term_t)));   // If this line is deleted -> update comment in PlTern(term_ref)
                avIdx++;
                //av[avIdx++].TermRef = term_t;
            }
            return(new ReadOnlyCollection <PlQueryVariables>(list));
        }
Beispiel #2
0
        /// <summary>
        /// <para>Create a <see cref="ReadOnlyCollection&lt;T&gt;"/> of <see cref="PlQueryVariables"/>.</para>
        /// <para>If calling ToList() all solutions of the query are generated and stored in the Collection.</para>
        /// </summary>
        /// <returns>A ReadOnlyCollection of PlQueryVariables containing all solutions of the query.</returns>
        /// <example>
        ///     <code source="..\..\TestSwiPl\LinqSwiPl.cs" region="Test_multi_goal_ToList_doc" />
        /// </example>
        public ReadOnlyCollection<PlQueryVariables> ToList()
        {
            List<PlQueryVariables> list = new List<PlQueryVariables>();
            EraseRecords();
            while (this.NextSolution())
            {
                for (int i = 0; i < _queryVariables.Count; i++ )
                {
                    _records.Add(libpl.PL_record(_queryVariables[i].Value.TermRef));   // to keep the PlTerms
                }
            }

            PlQueryVariables qv = new PlQueryVariables(); // dummy to make the compiler happy
            int avIdx = _queryVariables.Count;
            foreach (uint record_t in _records)
            {
                uint term_t = libpl.PL_new_term_ref(); ;
                libpl.PL_recorded(record_t, term_t);
                if (avIdx == _queryVariables.Count)
                {
                    qv = new PlQueryVariables();
                    list.Add(qv);
                    avIdx = 0;
                }
                //qv.Add(new PlQueryVar(GetVariableName(avIdx), new PlTerm(term_t)));   // If this line is deleted -> update comment in PlTern(term_ref)
                qv.Add(new PlQueryVar(_queryVariables[avIdx].Name, new PlTerm(term_t)));   // If this line is deleted -> update comment in PlTern(term_ref)
                avIdx++;
                //av[avIdx++].TermRef = term_t;
            }
            return new ReadOnlyCollection<PlQueryVariables>(list);
        }