Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ memory table
    primarykey
    data
    text
    <p>Can anyone recommend a <strong>lightweight</strong> open source C++ table data structure that has data access similar to a database table? (i.e. a 2D array but with named columns - ideally, each column will hold data of a single type [see below]).</p> <p>I have had a quick look on Google, but have not found anything very useful.</p> <p>The way I see it, these are the options available to me:</p> <ol> <li>Write my own from scratch (don't really want to invent the wheel)</li> <li>rip out the SimpleResult class from mySQL++ and hack around it</li> <li>use <a href="http://www.sqlite.org/index.html" rel="nofollow noreferrer">sqlite</a> (don't know how lightwight this will be - since I don't need the querying engine and all the other stuff)</li> <li>Ask in here to see if anyone is aware of such a library</li> </ol> <p>So here I am, choosing the quickest route (hopefully one that will also prove to be the the most efficient use of my time - since whatever is recommended here is likely to be peer reviewed).</p> <p>So, can anyone recommend a C++ class/ set of classes that provides a "database table like" interface?</p> <p>The main requirements are:</p> <ol> <li>Columns have names</li> <li>Cells can be accessed using row, column indexes</li> <li>I Can add rows and columns to the table (ideally, I can remove them too)</li> <li>(Nice to have): columns can have types, so it saves teh cost of converting to/from strings</li> </ol> <p><strong>[EDIT]</strong></p> <p>To further demonstrate how I want to use the library, please see the pseudo code below to see simple use of such a class (simple, meaning now iteration of rows and columns - which would be really cool). For now just keeping things simple:</p> <pre><code>typedef MemoryTable::ColType ColumnType; table = new MemoryTable(); // Set up the structure (this can be modified later using removeColumn() etc table-&gt;addColumn(ColumnType::Integer, 'id'); table-&gt;addColumn(ColumnType::String, 'name'); table-&gt;addColumn(ColumnType::Boolean, 'gender'); table-&gt;addColumn(ColumnType::Double, 'weight'); for (size_t i=0; i&lt;10; i++) { table-&gt;addRow(); numrows = table-&gt;getNumRows(); std::cout &lt;&lt; "We now have " &lt;&lt; numrows &lt;&lt; " rows.\n"; // Note can access cells using column name or index // Also using generic value getter/setter methods. Can throw exception on type mismatch table-&gt;setValue(i, 'id', i*i); table-&gt;setValue(i, 'name', getRandomSimpsonCharacterName()); //just to show use of a getter method table-&gt;setValue(i, 'gender', checkGender(table-&gt;getValue(i, 'name'))); table-&gt;setValue(i, 3, guessWeight(table-&gt;getValue(i, 'name'))); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload