CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   single linked list iterator does not work (http://www.cfd-online.com/Forums/openfoam/78382-single-linked-list-iterator-does-not-work.html)

woody July 20, 2010 07:00

single linked list iterator does not work
 
Hello All!

I am just trying to create a SLList (single linked list) to store my timedependent data, a scalarField ...

I already managed to create the List, but the iterator function is not working...


Any Ideas why??

I created a dummy test:

Code:

#include "fvCFD.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 int main(int argc, char *argv[])
 {
    scalar t=0;
    scalarField a(6);
    SLList<scalarField> test;
    for (int i=0; i<=5; i++)
    {
        a[i]=i;
    }
   
    for (int i=0; i<=5; i++)
    {
        a[0]=t;
        for (int j=1; j<=5; j++)
        {
        a[j]+=1;
        }
        t++;
        test.append(a);

    Info << "test " << test.size()  <<endl;
    Info << "test "<< test.first()<<endl;
    Info << "test "<< test.last()<<endl;
    }
   
    SLList<scalarField>::iterator iterTest;
    for( iterTest=test.begin(); iterTest != test.end(); ++iterTest)
    {
        Info << "Iterator" << iterTest << endl;
    }
}

thx

Tobi

bioexplore July 20, 2010 21:02

what do u mean the iterater not work? can u post the output of this test code?

woody July 21, 2010 04:15

Hi,

sure... when I compile it the output is:


Code:

Making dependency list for source file test.C
test.C: In function ‘int main(int, char**)’:
test.C:61: error: no matching function for call to ‘Foam::LList<Foam::SLListBase, Foam::Field<double> >::iterator::iterator()’
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/LList.H:246: note: candidates are: Foam::LList<LListBase, T>::iterator::iterator(typename LListBase::iterator) [with LListBase = Foam::SLListBase, T = Foam::Field<double>]
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/LList.H:238: note:                Foam::LList<Foam::SLListBase, Foam::Field<double> >::iterator::iterator(const Foam::LList<Foam::SLListBase, Foam::Field<double> >::iterator&)
test.C:64: error: no match for ‘operator<<’ in ‘Foam::operator<<(((Foam::Ostream&)(&((Foam::OSstream*)Foam::Info.Foam::messageStream::operator Foam::OSstream&())->Foam::OSstream::<anonymous>)), ((const char*)"Iterator")) << iterTest’                                                                                                                         
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/scalarRange.H:134: note: candidates are: Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::scalarRange&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/lduMatrix.H:840: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::lduMatrix&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/globalMeshData.H:409: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::globalMeshData&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/lduSchedule.H:68: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::lduScheduleEntry&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/cellZone.H:266: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::cellZone&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/faceZone.H:324: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::faceZone&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/pointZone.H:268: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::pointZone&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/boundBox.H:227: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::boundBox&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/polyBoundaryMesh.H:199: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::polyBoundaryMesh&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/polyPatch.H:358: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::polyPatch&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/objectHit.H:123: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::objectHit&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/patchIdentifier.H:150: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::patchIdentifier&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/nil.H:83: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::nil&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/cellShape.H:164: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::cellShape&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/cellModel.H:175: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::cellModel&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/SHA1Digest.H:80: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::SHA1Digest&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/instant.H:147: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::instant&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/Switch.H:196: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::Switch&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/dimensionSet.H:296: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::dimensionSet&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/dictionary.H:478: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::dictionary&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/entry.H:177: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::entry&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/long.H:58: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, long int)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/Pstream.H:507: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::Pstream::commsStruct&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/token.H:433: note:                std::ostream& Foam::operator<<(std::ostream&, const Foam::InfoProxy<Foam::token>&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/token.H:432: note:                std::ostream& Foam::operator<<(std::ostream&, const Foam::token::punctuationToken&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/token.H:431: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::token::punctuationToken&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/token.H:434: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::token::compound&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/token.H:422: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::token&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/error.H:284: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::IOerror&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/error.H:179: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::error&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/Ostream.H:212: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, Foam::IOstream& (*)(Foam::IOstream&))
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/Ostream.H:206: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, Foam::Ostream& (*)(Foam::Ostream&))
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/IOstream.H:556: note:                Foam::IOstream& Foam::operator<<(Foam::IOstream&, Foam::IOstream& (*)(Foam::IOstream&))
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/IOstream.H:546: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::IOstream::versionNumber&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/IOstream.H:545: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::IOstream::streamFormat&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/fileName.H:178: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::fileName&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/Scalar.H:282: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, Foam::doubleScalar)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/Scalar.H:282: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, Foam::floatScalar)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/uint.H:58: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, unsigned int)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/bool.H:50: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, bool)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/int.H:59: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, int)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/word.H:134: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::word&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/string.H:69: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const std::string&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/string.H:215: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::string&)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/char.H:52: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, const char*)
~/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/char.H:51: note:                Foam::Ostream& Foam::operator<<(Foam::Ostream&, char)
make: *** [Make/linux64GccDPOpt/test.o] Error 1

any idea?

Tobi

l_r_mcglashan July 21, 2010 04:21

That won't even compile. The iterator needs one constructor argument:

Code:

for( SLList<scalarField>::iterator iterTest=test1.begin(); iterTest != test1.end(); ++iterTest)
    {
        Info << "Iterator" << *iterTest << endl;
    }


woody July 21, 2010 04:53

Hy Laurence,

thanks it works. Do I understand right, that there is no empty constructor for this iterator??

l_r_mcglashan July 21, 2010 05:09

Have a look in the source here, from line 235. SLList inherits the iterator from LListBase. It would appear you have to either initialise the iterator with one argument, or implicitly assign an initial iterator value as I have done.

bioexplore July 21, 2010 21:45

Code:


//iterator must be initiated first
SLList<scalarField>::iterator iterTest=test.begin();

and there was no match output operator function related to Info<<sllist<Type>;
so you must call the operator() or operator* member function of the iterator first before you output it's value:
Code:

Info << "Iterator" << *iterTest << endl;
or
Code:

Info << "Iterator" << iterTest() << endl;


All times are GMT -4. The time now is 04:33.