gil900

VectorEx - vector 2D array, debug functions (Array Display for vector 1D , 2D and vector of vectors)

8 posts in this topic

#1 ·  Posted (edited)

Features:

VectorEx.h
* vectorex::vector2d<DataType> easily create and work with 2D array bassed on std::vector.

Functions in vectorex::vector2d:
.initialize(int iRows, int iColumns) - You must to call this before using the vector 2d. this function will build the 2d array (with the rows and columns).

.size_rows() - return the number of rows (1 based index).
.size_columns() - return the number of columns (1 based index) .

.assign(int iRow, int iColumn, T* ptr_T) - Assign value to [x row, y col] from pointer. (use this for big datatypes)
.assign(int iRow, int iColumn, T tVar) - Assign value to [x row, y col]

.at(int iRow, int iColumn) - return the value in [x row, y col]
.at(int iRow, int iColumn, T* dst) - return the value in [x row, y col] to pointer

.resize(int iRows, int iColumns)

.clear()

VectorDisplay.h

DisplayVector_2d(vectorex::vector2d<T>* ptr_vector,char sTitle[] =  ....) - Display the vectorex::vector2d  data structure
DisplayVector_1d(std::vector<T>* ptr_vector, char sTitle[] = ...) - Display the std::vector  data structure

 

At this time there is no more.. Here is the first example

571a34bdbbe3d_vectorexexample1.thumb.png

 

Project page: https://github.com/gileli121/VectorEx

This library is based also on  https://github.com/gileli121/CU3-Library

 

Next time I will also release the support for 1D array. I decided focus first on development for 2D array.

 

 

Update:

Added Example 2

// includes.functions
#include <windows.h>







// Include CU3 Library
// Get the files from https://github.com/gileli121/CU3-Library/tree/22/4/2016
#include "CU3_Library\EasyCoding\easy_macros.h"



// Include VectorEx https://github.com/gileli121/VectorEx
#include "VectorEx\VectorEx.h"
#include "VectorEx\VectorDisplay.h"
using namespace vectorex;
using namespace vectordisplay;


#include "WndProc.h"

/*
    This example shows how to use vector vectorex::vector2d array datatype,
    and how to display it using vectordisplay::DisplayVector_2d
*/




int main()
{


// Create 2D vector of strings
    vector2d<std::string> aArray;


// Initialize the 2D vector. *You must do this before using the vector2d!
    aArray.initialize(10, 5);


// Get rows count and columns count and print it
    pp "The number of rows is" ss aArray.size_rows() npp
        "And the number of columns is" ss aArray.size_columns() << std::endl ee;




// Display the vector2d. *You must to give the same datatype in the "<>"
    DisplayVector_2d<std::string>(&aArray,"Display the vector 2D before changes");


    
// Assign some values

    // Method 1:
    aArray.assign(0, 0, "STR1"); // Assign to [row 0,col 0] the value "STR1".
    aArray.assign(0, 1, "STR2"); // Assign to [row 1,col 1] the value "STR2".
    aArray.assign(0, 2, "STR3"); // Assign to [row 2,col 2] the value "STR3".
    aArray.assign(0, 3, "STR4"); // Assign to [row 3,col 3] the value "STR4".
    aArray.assign(0, 4, "STR5"); // Assign to [row 4,col 4] the value "STR5".

    // Method 2 - From pointer:
    std::string stringStr = "string from pointer";
    int iRow, iColumn;
    for (iRow = 1; iRow < aArray.size_rows(); iRow++)
    {
        for (iColumn = 0; iColumn < aArray.size_columns(); iColumn++)
        {
            aArray.assign(iRow, iColumn, &stringStr);

        }
    }


    // Method 1 (again):
    aArray.assign(5, 3, "STR6"); // Assign to [row 5,col 3] the value "STR6".
    aArray.assign(6, 2, "STR7"); // Assign to [row 6,col 2] the value "STR7".
    aArray.assign(7, 1, "STR8"); // Assign to [row 7,col 1] the value "STR8".
    aArray.assign(8, 0, "STR9"); // Assign to [row 8,col 0] the value "STR9".



// Print Methods

    // Method 1:
    pp "The value in row 0, col 1 is" ss aArray.at(0, 1) npp
        "And the value in row 1, col 1 is" ss aArray.at(1, 1) << std::endl ee;

    // Method 2 (to pointer):
    std::string stringTmp;
    aArray.at(0, 4, &stringTmp);
    pp "The value in row 0, col 4 is" ss stringTmp ee;
    aArray.at(7, 1, &stringTmp);
    pp "And the value in row 7, col 1 is" ss stringTmp ee;



// Display the vector2d again to see the changes
    DisplayVector_2d<std::string>(&aArray);



    return 0;
}

 

Improved:
DisplayVector_2d:
1) You can now resize the GUI.
2) The width of the columns wiil fit automatically to the text size.

 

Edited by gil900
1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

New example:

example%204.png

 

I rewrote the print module of DisplayVector_2d. It is much faster now compared to the previous.

Edited by gil900
1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

After a long time of development, I have new Display function that can display Vector of Vectors.
It was hard to make. but at the end (As always) the the result is exactly the same as the image in my imagination.

5722b598ea60d_examplevectorofvectorsdisp

 

I will release it but not now. Unless you ask for it.

Edited by gil900

Share this post


Link to post
Share on other sites

Pretty nice

I vote for it

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

 

 Released

 

std::vector<std::vector<std::string>> stringVecofvec; // Create Vector of std::string vectors



    DisplayVector_OfVectors(&stringVecofvec); // Display it
    /*
        As you can see, you get list view that is completely gray with nothing in it.
        This is because that the vector (that intended to contains other vectors)
        have 0 size.

        So we resize this main vector to 10 in the next step.
    */

    stringVecofvec.resize(10); // Resize the main vector to 10. so will be space for 10 vector in it.


    DisplayVector_OfVectors(&stringVecofvec); // Display it
    /*
        As you can see, now the list view is not completely empty. you will see vector 0 - vector 9 (10 vectors)
        It shows the room for the 10 vectors.

        However, the list view is still completely gray. because all the 10 vector inside the main vector
        is 0 size.

        So we resize some few vector (few vectors of 0-9 ) to random sizes.
    */

    stringVecofvec[0].resize(5); // Resize vector 0 to 5.
    stringVecofvec[3].resize(10); // And resize vector 3 to 10
    stringVecofvec[6].resize(15); // And resize vector 6 to 15
    stringVecofvec[9].resize(6); // And resize vector 9 to 6
    
    
    DisplayVector_OfVectors(&stringVecofvec); // Display it
    /*
        As you can see, now not everything is gray. you will see some vectors that colored in white color.
        And some are still completely gray.

        The vectors that are completely gray are those that with size 0. others have size that is bigger
        then 0.

        The size of each vector is visualized by the number of the white columns.
        For example, in this case - vector 0 will have 5 white columns, and vector 6 will have 15 white columns.
        Vector with 0 size have no white columns. only gray.


        In the next step will fill some vectors with data. You can fill data only on areas with white color.
        (white color = space for data
        gray color = no space for data)
    */



/*
    Liked this example? Did that helped you? If so, you can also thanks by giving a small contribution
    https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=S2KFGDTQZG4XQ
*/



    // Fill data in vector 0
    stringVecofvec[0].at(0) = "HELLO"; //       Fill data in vector 0 -> row 0
    stringVecofvec[0].at(4) = "VECTORS!"; //    Fill data in vector 0 -> row 4
        /*
            Try to add stringVecofvec[0].at(5) = "TEST";
            It will not work because you try to fill data in no-space (gray color)
            you can fill data only in space.

        */


    // Fill data in vector 3 (you can't fill data in the next vector. it have 0 space/size = 100% gray color
    stringVecofvec[3].at(4) = "OF";  //         Fill data in vector 3 -> row 4
    stringVecofvec[3].at(0) = "WORLD"; //       Fill data in vector 3 -> row 0
    stringVecofvec[3].at(8) = "VERY"; //        Fill data in vector 3 -> row 8


    // Fill data in vector 6
    stringVecofvec[6].at(4) = "VECTORS"; //     Fill data in vector 6 -> row 4
    stringVecofvec[6].at(0) = "OF MANY"; //     Fill data in vector 6 -> row 0
    stringVecofvec[6].at(14) = "EASY :)"; //    Fill data in vector 6 -> row 14



    // Fill data in vector 9
    stringVecofvec[9].at(4) = "EXAMPLE !"; //   Fill data in vector 9 -> row 4
    stringVecofvec[9].at(0) = "VECTORS !"; //   Fill data in vector 9 -> row 0

    
    
    DisplayVector_OfVectors(&stringVecofvec); // Display it
    /*
        Is it looks much more beautiful than this ugly black console?
        



        Enjoy.
    */

example%207%20-%20display%20vector%20of%

 

Full example here: https://github.com/gileli121/VectorEx/blob/master/VectorEx-Examples/main/Example%207.h

 

 

Edited by gil900
1 person likes this

Share this post


Link to post
Share on other sites

Thanks for sharing

o:)

Share this post


Link to post
Share on other sites

Another example:
5723a21749fda_example8-displayvector2dwi

// includes.functions
#include <windows.h>







// Include CU3 Library
// Get the files from https://github.com/gileli121/CU3-Library/
#include "CU3_Library\EasyCoding\easy_macros.h"



// Include VectorEx https://github.com/gileli121/VectorEx
#include "VectorEx\VectorEx.h"
#include "VectorEx\VectorDisplay.h"
using namespace vectorex;
using namespace vectordisplay;


/*

	This example shows and visualize that

	vectorex::vector2d<DataType>
	is just 
	std::vector<std::vector<DataType>>


	We create the data type vectorex::vector2d,
	then we modify it a bit, and finally we show it with 
	vectordisplay::DisplayVector_2d and  vectordisplay::DisplayVector_OfVector


*/


int main()
{
	
	vectorex::vector2d<std::string> stringVector2D; // Create the 2d vector
	stringVector2D.build(15, 5); // Build it with 10 rows and 5 cols
	
	// Fill it
	stringVector2D.overwrite("X", 0, 0, 9, 0); //	Fill rows 0-9, cols 0 with X
	stringVector2D.overwrite("Y", 0, 1, 9, 1); //	Fill rows 0-9, cols 1 with Y
	stringVector2D.overwrite("Z", 0, 2, 9, 2); //   Fill rows 0-9, cols 2 with Z
	stringVector2D.overwrite("Q", 0, 3, 9, 3); //   Fill rows 0-9, cols 3 with Q
	stringVector2D.overwrite("M", 0, 4, 9, 4); //   Fill rows 0-9, cols 4 with M


	stringVector2D.overwrite("=+=", 13, 0, 13, stringVector2D.iSize_cols - 1); // Fill row 13, cols 0-4 with "=+="


	// Display it with DisplayVector_2d
	DisplayVector_2d(&stringVector2D);

	// Display it with DisplayVector_OfVector
	DisplayVector_OfVectors(&stringVector2D.aArray);





	return 0;
}


/*
	Liked this example? Did that helped you? If so, you can also thanks by giving a small contribution
	https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=S2KFGDTQZG4XQ
*/

 

1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

 DisplayVector_OfVectors updated to visualize the .capacity()

example%209%20-%20display%20vector%202d%

 

Example of this included here: https://github.com/gileli121/VectorEx/blob/master/VectorEx-Examples/main/Example%209.h

 

 

 

Edited by gil900
Updated example to for the new version of VectorDisplay.h

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now