? programs-2002Jan31.patch Index: Makefile =================================================================== RCS file: Makefile diff -N Makefile *** /dev/null Fri Mar 23 21:37:44 2001 --- Makefile Thu Jan 31 15:19:46 2002 *************** *** 0 **** --- 1,15 ---- + ### Oldham, Jeffrey D. + ### 2001Nov27 + ### Pooma + ### + ### Produce Annotated Source Code + + ## These rules combine executable code, which can be compiled and run, + ## with DocBook annotations used in the manual to explain the code. + + all: array-copy-annotated.cpp dynamicarray-annotated.cpp \ + initialize-finalize-annotated.cpp \ + pairs-templated-annotated.cpp pairs-untemplated-annotated.cpp + + %-annotated.cpp: %-annotated.patch %.cpp + patch -o $@ < $< Index: array-copy-annotated.patch =================================================================== RCS file: array-copy-annotated.patch diff -N array-copy-annotated.patch *** /dev/null Fri Mar 23 21:37:44 2001 --- array-copy-annotated.patch Thu Jan 31 15:19:46 2002 *************** *** 0 **** --- 1,78 ---- + *** array-copy.cpp Thu Jan 24 11:12:23 2002 + --- array-copy-annotated.cpp Thu Jan 31 09:22:57 2002 + *************** + *** 1,8 **** + #include "Pooma/Pooma.h" + #include "Pooma/Arrays.h" + ! #include + + // Changes the Array value at index (0,0). + ! void changeValue(Array<2,int,Brick>& z) + { z(0,0) = 6; } + + --- 1,9 ---- + + + #include "Pooma/Pooma.h" + #include "Pooma/Arrays.h" + ! #include <iostream> + + // Changes the Array value at index (0,0). + ! void changeValue(Array<2,int,Brick>& z) + { z(0,0) = 6; } + + *************** + *** 11,35 **** + Pooma::initialize(argc,argv); + + ! Array<2,int,Brick> a(3,4, ModelElement(4)); + ! std::cout << "Initial value:\n"; + ! std::cout << "a: " << a(0,0) << std::endl; + + // Array copies share the same underlying values. + + ! // Explicit initialization uses reference semantics so changing the + ! // copy's value at (0,0) also changes the original's value. + ! Array<2,int,Brick> b(a); + b(0,0) = 5; + ! std::cout << "After explicit initialization.\n"; + ! std::cout << "a: " << a(0,0) << std::endl; + ! std::cout << "b: " << b(0,0) << std::endl; + ! + ! // Initialization of function arguments also uses reference semantics. + ! std::cout << "After function call:\n"; + changeValue(a); + ! std::cout << "a: " << a(0,0) << std::endl; + ! std::cout << "b: " << b(0,0) << std::endl; + + Pooma::finalize(); + return 0; + } + --- 12,39 ---- + Pooma::initialize(argc,argv); + + ! Array<2,int,Brick> a(3,4, ModelElement<int>(4)); + ! std::cout &openopen; "Initial value:\n"; + ! std::cout &openopen; "a: " &openopen; a(0,0) &openopen; std::endl; + + // Array copies share the same underlying values. + + ! // Explicit initialization uses reference semantics + ! // so changing the copy's value at (0,0) also + ! // changes the original's value. + ! Array<2,int,Brick> b(a); + b(0,0) = 5; + ! std::cout &openopen; "After explicit initialization.\n"; + ! std::cout &openopen; "a: " &openopen; a(0,0) &openopen; std::endl; + ! std::cout &openopen; "b: " &openopen; b(0,0) &openopen; std::endl; + ! + ! // Initialization of function arguments also uses + ! // reference semantics. + ! std::cout &openopen; "After function call:\n"; + changeValue(a); + ! std::cout &openopen; "a: " &openopen; a(0,0) &openopen; std::endl; + ! std::cout &openopen; "b: " &openopen; b(0,0) &openopen; std::endl; + + Pooma::finalize(); + return 0; + } + + Index: array-size-annotated.patch =================================================================== RCS file: array-size-annotated.patch diff -N array-size-annotated.patch *** /dev/null Fri Mar 23 21:37:44 2001 --- array-size-annotated.patch Thu Jan 31 15:19:46 2002 *************** *** 0 **** --- 1,80 ---- + *** array-size.cpp Tue Jan 15 13:30:53 2002 + --- array-size-annotated.cpp Thu Jan 31 09:24:16 2002 + *************** + *** 1,25 **** + #include "Pooma/Pooma.h" + #include "Pooma/Arrays.h" + ! #include + + // Print an Array's Size + + ! // This program illustrates using the Array member functions. + ! // computeArraySize's computation is redundant because Array's size() + ! // function computes the same value, but it illustrates using Array + // member functions. + + ! template + inline + ! long computeArraySize(const Array& a) + { + ! const Loc fs = a.firsts(); + ! const Loc ls = a.lasts(); + ! const Loc lens = a.lengths(); + long size = 1; + ! for (int d = 0; d < Dim; ++d) { + ! size *= lens[d].first(); + // Check that lengths() and our computed lengths agree. + ! PAssert((ls[d] - fs[d] + 1).first() == a.length(d)); + } + return size; + --- 1,27 ---- + + + #include "Pooma/Pooma.h" + #include "Pooma/Arrays.h" + ! #include <iostream> + + // Print an Array's Size + + ! // This program illustrates using the Array member + ! // functions. computeArraySize's computation is + ! // redundant because Array's size() function computes + ! // the same value, but it illustrates using Array + // member functions. + + ! template <int Dim,typename Type,typename EngineTag> + inline + ! long computeArraySize(const Array<Dim,Type,EngineTag>& a) + { + ! const Loc<Dim> fs = a.firsts(); + ! const Loc<Dim> ls = a.lasts(); + ! const Loc<Dim> lens = a.lengths(); + long size = 1; + ! for (int d = 0; d < Dim; ++d) { + ! size *= lens[d].first(); + // Check that lengths() and our computed lengths agree. + ! PAssert((ls[d]-fs[d]+1).first()==a.length(d)); + } + return size; + *************** + *** 30,38 **** + Pooma::initialize(argc,argv); + + ! Array<3,int,Brick> a(3,4,5, ModelElement(4)); + ! PAssert(computeArraySize(a) == a.size()); + ! std::cout << "The array's size is " << a.size() << ".\n"; + + Pooma::finalize(); + return 0; + } + --- 32,42 ---- + Pooma::initialize(argc,argv); + + ! Array<3,int,Brick> a(3,4,5, ModelElement<int>(4)); + ! PAssert(computeArraySize(a) == a.size()); + ! std::cout &openopen; + ! "The array's size is " &openopen; a.size() &openopen; ".\n"; + + Pooma::finalize(); + return 0; + } + + Index: dynamicarray-annotated.patch =================================================================== RCS file: dynamicarray-annotated.patch diff -N dynamicarray-annotated.patch *** /dev/null Fri Mar 23 21:37:44 2001 --- dynamicarray-annotated.patch Thu Jan 31 15:19:46 2002 *************** *** 0 **** --- 1,80 ---- + *** dynamicarray.cpp Mon Jan 21 17:29:38 2002 + --- dynamicarray-annotated.cpp Tue Jan 22 07:06:15 2002 + *************** + *** 1,5 **** + #include "Pooma/Pooma.h" + ! #include "Pooma/DynamicArrays.h" + ! #include + + // Demonstrate using DynamicArrays. + --- 1,6 ---- + + + #include "Pooma/Pooma.h" + ! #include "Pooma/DynamicArrays.h" + ! #include <iostream> + + // Demonstrate using DynamicArrays. + *************** + *** 9,38 **** + Pooma::initialize(argc,argv); + + ! // Create a DynamicArray with one element. + ! DynamicArray<> d0(1); + ! DynamicArray d01(1); + ! DynamicArray d02(1); + + ! // Add five more elements. + d0.create(5); + // Store values in the array. + ! for (int i = d0.domain().first(); i <= d0.domain().last(); ++i) + ! d0(i) = i; + + ! // Delete every other element. + ! d0.destroy(Range<1>(d0.domain().first(),d0.domain().last(),2), BackFill()); + + // Print the resulting array. + ! std::cout << d0 << std::endl; + + // Use the iterator form of 'destroy.' + ! DynamicArray<> d1(6); + for (int i = d1.domain().first(); i <= d1.domain().last(); ++i) + d1(i) = i; + ! int killList[] = { 0, 2, 4 }; + d1.destroy(killList, killList+3); + ! std::cout << d1 << std::endl; + + Pooma::finalize(); + return 0; + } + --- 10,40 ---- + Pooma::initialize(argc,argv); + + ! // Create a DynamicArray with one element. + ! DynamicArray<> d0(1); + ! DynamicArray<double> d01(1); + ! DynamicArray<double, Dynamic> d02(1); + + ! // Add five more elements. + d0.create(5); + // Store values in the array. + ! for (int i = d0.domain().first(); i <= d0.domain().last(); ++i) + ! d0(i) = i; + + ! // Delete every other element. + ! d0.destroy(Range<1>(d0.domain().first(),d0.domain().last(),2), BackFill()); + + // Print the resulting array. + ! std::cout &openopen; d0 &openopen; std::endl; + + // Use the iterator form of 'destroy.' + ! DynamicArray<> d1(6); + for (int i = d1.domain().first(); i <= d1.domain().last(); ++i) + d1(i) = i; + ! int killList[] = { 0, 2, 4 }; + d1.destroy(killList, killList+3); + ! std::cout &openopen; d1 &openopen; std::endl; + + Pooma::finalize(); + return 0; + } + + Index: initialize-finalize-annotated.patch =================================================================== RCS file: initialize-finalize-annotated.patch diff -N initialize-finalize-annotated.patch *** /dev/null Fri Mar 23 21:37:44 2001 --- initialize-finalize-annotated.patch Thu Jan 31 15:19:46 2002 *************** *** 0 **** --- 1,20 ---- + *** initialize-finalize.cpp Thu Jan 24 11:14:13 2002 + --- initialize-finalize-annotated.cpp Thu Jan 24 11:14:17 2002 + *************** + *** 1,4 **** + #include "Pooma/Pooma.h" + ! #include + + int main(int argc, char *argv[]) + --- 1,5 ---- + + + #include "Pooma/Pooma.h" + ! #include <iostream> + + int main(int argc, char *argv[]) + *************** + *** 11,12 **** + --- 12,14 ---- + return 0; + } + + Index: pairs-templated-annotated.patch =================================================================== RCS file: pairs-templated-annotated.patch diff -N pairs-templated-annotated.patch *** /dev/null Fri Mar 23 21:37:44 2001 --- pairs-templated-annotated.patch Thu Jan 31 15:19:46 2002 *************** *** 0 **** --- 1,38 ---- + *** pairs-templated.cpp Mon Jan 7 16:11:56 2002 + --- pairs-templated-annotated.cpp Thu Jan 31 08:44:35 2002 + *************** + *** 1,15 **** + ! // Declare a template class storing a pair of values with the same type. + ! template + struct pair { + ! pair(const int& left, const int& right) + : left_(left), right_(right) {} + + ! T left_; + T right_; + }; + + ! // Define a class storing a pair of integers. + ! pair pair1; + + ! // Define a class storing a pair of doubles; + ! pair pair2; + --- 1,18 ---- + ! + ! // Declare a template class storing a pair of values + ! // with the same type. + ! template <typename T> // + struct pair { + ! pair(const T& left, const T& right) // + : left_(left), right_(right) {} + + ! T left_; // + T right_; + }; + + ! // Use a class storing a pair of integers. + ! pair<int> pair1; + + ! // Use a class storing a pair of doubles; + ! pair<double> pair2; + ! Index: pairs-untemplated-annotated.patch =================================================================== RCS file: pairs-untemplated-annotated.patch diff -N pairs-untemplated-annotated.patch *** /dev/null Fri Mar 23 21:37:44 2001 --- pairs-untemplated-annotated.patch Thu Jan 31 15:19:46 2002 *************** *** 0 **** --- 1,35 ---- + *** pairs-untemplated.cpp Wed Dec 26 13:48:10 2001 + --- pairs-untemplated-annotated.cpp Wed Dec 26 14:02:58 2001 + *************** + *** 1,5 **** + // Declare a class storing a pair of integers. + struct pairOfInts { + ! pairOfInts(const int& left, const int& right) + : left_(left), right_(right) {} + + --- 1,6 ---- + + + // Declare a class storing a pair of integers. + struct pairOfInts { + ! pairOfInts(const int& left, const int& right) + : left_(left), right_(right) {} + + *************** + *** 10,14 **** + // Declare a class storing a pair of doubles. + struct pairOfDoubles { + ! pairOfDoubles(const double& left, const double& right) + : left_(left), right_(right) {} + + --- 11,15 ---- + // Declare a class storing a pair of doubles. + struct pairOfDoubles { + ! pairOfDoubles(const double& left, const double& right) + : left_(left), right_(right) {} + + *************** + *** 16,17 **** + --- 17,19 ---- + double right_; + }; + +