Exemplo n.º 1
0
int main(int argc, char** argv) {

  named_mutex mutex(open_or_create, "grapevine_collect_files");
  scoped_lock<named_mutex> lock(mutex);

  managed_shared_memory segment(open_or_create, "grapevine_collect_files_memory", 1 << 16);
  CharAllocator charAllocator (segment.get_segment_manager());
  StringAllocator stringAllocator (segment.get_segment_manager());

  MyVector *fileList = segment.find_or_construct<MyVector>("file_list")(stringAllocator);
  time_t* lastUpdate = segment.find_or_construct<time_t>("last_update")(time(NULL));

  if (*lastUpdate + 1 < time(NULL)) {
    fileList->clear();
  }

  for (int iArg = 1; iArg < argc; ++iArg) {
    MyString str(charAllocator);
    str = argv[iArg];
    fileList->push_back(str);
  }

  *lastUpdate = time(NULL);
	return 0;
}
Exemplo n.º 2
0
int main()
{
	// Create a default vector 
	MyVector sam;

	// push some data into sam
	cout << "\nPushing three values into sam";
	sam.push_back(TEST_VALUE1);
	sam.push_back(TEST_VALUE2);
	sam.push_back(TEST_VALUE3);

	cout << "\nThe values in sam are: ";

	// test for out of bounds condition here
	// and test exception 
	for (int i = 0; i < sam.size() + 1; i++)
	{
		try
		{
			cout << sam.at(i) << " ";
		}
		catch (int badIndex)
		{
			cout << "\nOut of bounds at index " << badIndex << endl;
		}
	}
	cout << "\n--------------\n";

	// clear sam and display its size and capacity
	sam.clear();
	cout << "\nsam has been cleared.";
	cout << "\nSam's size is now " << sam.size();
	cout << "\nSam's capacity is now " << sam.capacity() << endl;
	cout << "---------------\n";

	// Push 12 values into the vector - it should grow
	cout << "\nPush 12 values into sam.";
	for (int i = 0; i < MAX; i++)
		sam.push_back(i);

	cout << "\nSam's size is now " << sam.size();
	cout << "\nSam's capcacity is now " << sam.capacity() << endl;
	cout << "---------------\n";

	cout << "\nTest to see if contents are correct...";
	// display the values in the vector
	for (int i = 0; i < sam.size(); i++)
	{

		cout << sam.at(i) << " ";
	}
	cout << "\n--------------\n";

	cout << "\n\nTest Complete...";

	cout << endl;
	system("PAUSE");
	return 0;
}
Exemplo n.º 3
0
 /**
  * Clears and initializes the table.
  * @param n the number of rows.
  */
 void init(int n = 0) {
     table.clear();
     table.resize(n);
 }