CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   add entry to wordList (http://www.cfd-online.com/Forums/openfoam-programming-development/80329-add-entry-wordlist.html)

peterwy September 22, 2010 12:03

add entry to wordList
 
Hello,

I've a probably very easy question, but I tried already a lot - nearly the cpl. afternoon - but nothing worked so far.

First I used something like vector<std::string> and here I added strings with the command vector.push_back(....)

Now I want to use the std foam syntax

I created a wordList what should be nearly the same as vector<std::string>
To add elements at the end the .append function should work.

But now the problems comes by:
I can append only another wordList but I'm not able to append a entry like
wordList testList;
testList.append("the first entry");
testList.append("next entry");
and so far.

Is anybody able to help me? Would be greatful.

Thx a lot, bye
Peter

olesen September 24, 2010 02:44

Quote:

Originally Posted by peterwy (Post 276201)
Hello,

I've a probably very easy question, but I tried already a lot - nearly the cpl. afternoon - but nothing worked so far.

First I used something like vector<std::string> and here I added strings with the command vector.push_back(....)

Now I want to use the std foam syntax

I created a wordList what should be nearly the same as vector<std::string>
To add elements at the end the .append function should work.

But now the problems comes by:
I can append only another wordList but I'm not able to append a entry like
wordList testList;
testList.append("the first entry");
testList.append("next entry");
and so far.

Is anybody able to help me?

1. a "word" has no spaces, so in your example you really want a list of "string", where "string" is actually Foam::string and not std::string.
2. If you are doing several appends, using "List" is very inefficient.

A "List" is normally used with pre-allocated space.
For example,
Code:

    // dimension for exactly 2 items
    List<string> testList(2);

    testList[0] = "the first entry";
    testList[1] = "next entry";

If you want many appends, you should use a DynamicList.
For example,
Code:

    // reserve at least 10 spaces
    DynamicList<string> testList(10);

    testList.append("the first entry");
    testList.append("next entry");
    testList.append("yet another entry");

Take a look at "applications/test/DynamicList/DynamicListTest.C" for some more ideas ... the DynamicList has lots of functionality.

Note that if you have a list of bool values, you should consider using PackedBoolList - it has many pleasant features that make it behave somewhat like a DynamicList.

peterwy September 24, 2010 03:00

Thx already now for your reply. Some time ago I worked with those dynamic Lists. I will try what's possible in this case. I will come back to this threat then in the next days because at the moment other project work is urgent.

Thx & have a nice weekend
Peter

peterwy October 4, 2010 07:13

SOLVED

working with those dynamic lists is exactly what I needed because when using vector OF has problems with other include files.

Thx @ all, Best Regards, Peter


All times are GMT -4. The time now is 16:51.