Loading...

Jul 27, 2015

Boogie Board Sync 9.7 - Box Contents & Details


The Boogie Board Sync 9.7 is an electronic "eWriter."  From my side it looks like two devices in one.  It seems to have stylus-only features but at the same time has more advanced features found in digitizer devices.  More info below.

Jul 9, 2015

A Pool, Blocks, and Cells in C++


An example on how to use pointer to a pointer (char**). There could be errors.

#define _SCL_SECURE_NO_WARNINGS // Prevents some warnings when performing std::copy

#include <iostream>
#include <algorithm> // for std::copy
using namespace std;

int main() {
 int x = 5;
 cout << "The value of x is " << x << " address: " << &x << " same as " << static_cast<void*>(&x) << endl;

 size_t Size = 2;
 char** pool = new char*[Size];

 cout << "\nCREATE " << Size << " BLOCKS AND POPULATE " << Size << " CELLS." << endl;
 for (size_t i = 0; i < Size; i++) {
  cout << "Block " << i << endl;
  char* block = new char[Size];

  for (size_t j = 0; j < Size; j++)
  {
   int iJ = int(j);
   char c = 97 + iJ;
   new (block + j) char(c); // same as block[j] = c
   cout << "\tAddress of " << j << " is " << static_cast<void*>(block + j) << endl;
  }

  pool[i] = block;  // Store the block in the pool.
 }

 ++Size;
 cout << "\nEXPAND THE POOL TO " << Size << " BLOCKS" << endl;
 char** newPool = new char*[Size];
 std::copy(pool, pool + Size-1, newPool);
 delete[] pool;
 pool = newPool;

 // Create a new block, populate it.
 char* newBlock = new char[Size-1];
 for (size_t j = 0; j < Size-1; j++) {
  newBlock[j] = char(97 + j);
 }
 
 // Insert characters
 new (newBlock + 0) char(); // empty
 new (newBlock + 1) char('u'); // u

 // Add the new block to the pool
 pool[Size-1] = newBlock;

 cout << "\nDISPLAY CONTENTS OF EACH BLOCK CELL." << endl;
 for (size_t i = 0; i < Size; i++) {
  cout << "Block " << i << endl;
  for (size_t j = 0; j < Size-1; j++) {
   cout << "\t Cell " << j << " val is '" << (pool[i])[j] << "' addr is: " << static_cast<void*>((pool[i]) + j) << endl;
  }
  delete[] pool[i]; // delete block
 }

 cout << "\nTEST FOR EMPTY." << endl;
 for (size_t i = 0; i < Size; i++) {
  cout << "Block " << i << endl;
  for (size_t j = 0; j < Size-1; j++) {
   cout << "\t Cell " << j << " val is '" << (pool[i])[j] << "' addr is: " << static_cast<void*>((pool[i]) + j) << endl;
  }
 }

 delete[] pool;
 cout << "Done" << endl;
 cin.get();
}

Jul 7, 2015

Overloading operator << in C++

Here's some code on how to overload the << operator in c++. This involves pointers.
#include <iostream>
using namespace std;

std::ostream& operator <<(std::ostream &aOs, const int* aInt)
{
 return aOs << "Value via overloaded << of aInt is " << *(aInt) << " or same as " << aInt[0];
}

int main() {
 int* myInts[2];
 myInts[0] = new int;
 myInts[1] = new int;
 int* IntPointer = new int;
 
 *myInts[0] = 1;
 *myInts[1] = 2;
 *IntPointer = 5;

 cout << "Address is: " << &myInts[0] << endl;
 cout << "Address is: " << &myInts[1] << endl;
 cout << "Address is: " << &IntPointer << endl;
 cout << "Value is: " << *myInts[0] << endl;
 cout << "Value is: " << *myInts[1] << endl;
 cout << "Value is: " << *IntPointer << endl;
 cout << myInts[0] << endl;
 cout << myInts[1] << endl;
 cout << IntPointer << endl;
 
 cin.get();
}

/*
Output
Address is 00A8F8B8
Address is 00A8F8BC
Address is 00A8F8AC
Value is: 1
Value is: 2
Value is: 5
Value via overloaded << of aInt is 1 ,or same as 1
Value via overloaded << of aInt is 2 ,or same as 2
Value via overloaded << of aInt is 5 ,or same as 5
*/


Doing it as a friend for a Something class. This goes in Something.h
// In Something.h
class Something
{
 friend std::ostream& operator <<(std::ostream &aOs, const Something& argSomething);
 private:
  int myPrivateMember;
}; 

// in Something.cpp
std::ostream& operator <<(std::ostream &aOs, const Something& argSomething);
{
  return aOs << argSomething.myPrivateMember;
}