Add support for callbacks
This commit is contained in:
245
ctest/main.cpp
245
ctest/main.cpp
@@ -10,144 +10,141 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <complex>
|
||||
#include <common/callback.hpp>
|
||||
|
||||
|
||||
// #include <iostream> // For standard input/output operations (like std::cout)
|
||||
// #include <fstream> // For file stream operations (like std::ifstream)
|
||||
// #include <string> // For using std::string
|
||||
// int main()
|
||||
// {
|
||||
// Profiler profiler = Profiler();
|
||||
// std::ifstream inputFile("/mnt/mariadb/backupdb.sql");
|
||||
|
||||
// if (!inputFile.is_open())
|
||||
// {
|
||||
// std::cerr << "Error: Could not open the file." << std::endl;
|
||||
// return 1; // Indicate an error
|
||||
// }
|
||||
|
||||
// DWORD lines = 0;
|
||||
// std::string line;
|
||||
// while (std::getline(inputFile, line))
|
||||
// {
|
||||
// lines++;
|
||||
// if(!(lines%1000000))
|
||||
// {
|
||||
// std::cout << "reading " << lines << " " << line << std::endl;
|
||||
// }
|
||||
// }
|
||||
|
||||
// inputFile.close();
|
||||
// std::cout << "Done, total took " << profiler.end() << " (ms)" << std::endl;
|
||||
// return 0; // Indicate successful execution
|
||||
// }
|
||||
|
||||
// int main(int argc, char ** argv)
|
||||
// {
|
||||
// Profiler profiler = Profiler();
|
||||
// FileIO inputFile = FileIO("/mnt/mariadb/backupdb.sql");
|
||||
// inputFile.setBufferLength(500000000);
|
||||
// // FileIO inputFile = FileIO("/home/pi/Boneyard/ctest/main.cpp");
|
||||
// String strLine = String();
|
||||
// DWORD length = 0;
|
||||
// DWORD lines = 0;
|
||||
|
||||
// printf("opening...\n");
|
||||
// while(inputFile.readLine(strLine))
|
||||
// {
|
||||
// lines++;
|
||||
// // printf("reading %d %s\n",lines,(char*)strLine);
|
||||
// if(!(lines%1000000))
|
||||
// {
|
||||
// printf("reading %d %s\n",lines,(char*)strLine);
|
||||
// }
|
||||
// }
|
||||
// printf("Done, read %d lines\n",lines);
|
||||
// inputFile.close();
|
||||
// printf("done, took %d(ms)...\n",profiler.end());
|
||||
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
std::tuple<int,int,int> foo()
|
||||
class Info
|
||||
{
|
||||
return std::make_tuple(2,3,4);
|
||||
public:
|
||||
Info();
|
||||
~Info();
|
||||
String getMessage(void);
|
||||
void setMessage(const String &message);
|
||||
private:
|
||||
String mMessage;
|
||||
};
|
||||
|
||||
Info::Info()
|
||||
{
|
||||
std::cout << "Info" << std::endl;
|
||||
}
|
||||
|
||||
Info::~Info()
|
||||
{
|
||||
std::cout << "~Info" << std::endl;
|
||||
}
|
||||
|
||||
String Info::getMessage(void)
|
||||
{
|
||||
return mMessage;
|
||||
}
|
||||
|
||||
void Info::setMessage(const String &message)
|
||||
{
|
||||
mMessage = message;
|
||||
}
|
||||
|
||||
class B
|
||||
{
|
||||
public:
|
||||
B();
|
||||
LONG callback(CallbackData<Info> &callbackData);
|
||||
~B();
|
||||
private:
|
||||
String mFoo;
|
||||
};
|
||||
|
||||
B::B()
|
||||
{
|
||||
}
|
||||
|
||||
B::~B()
|
||||
{
|
||||
}
|
||||
|
||||
LONG B::callback(CallbackData<Info> &callbackData)
|
||||
{
|
||||
std::cout << "callback with data " << callbackData.getData().getMessage().str() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
class Monitor
|
||||
{
|
||||
public:
|
||||
Monitor();
|
||||
~Monitor();
|
||||
void setCallback(Callback<B,Info> &callback);
|
||||
void doCallback(CallbackData<Info> &callbackData);
|
||||
private:
|
||||
Callback<B,Info> mCallback;
|
||||
};
|
||||
|
||||
Monitor::Monitor()
|
||||
{
|
||||
std::cout << "Monitor" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
Monitor::~Monitor()
|
||||
{
|
||||
std::cout << "~Monitor" << std::endl;
|
||||
}
|
||||
|
||||
void Monitor::setCallback(Callback<B,Info> &callback)
|
||||
{
|
||||
mCallback=callback;
|
||||
}
|
||||
|
||||
void Monitor::doCallback(CallbackData<Info> &callbackData)
|
||||
{
|
||||
CallbackPointer cbptr(&mCallback);
|
||||
cbptr.callback(callbackData);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
// std::complex<double> c{4.0,3.0};
|
||||
// std::vector<int> myBigVec(10000000, 2011);
|
||||
// std::vector<std::string> s1;
|
||||
// std::vector<std::string> s2;
|
||||
|
||||
// s1.push_back("hello");
|
||||
// s1.push_back("world");
|
||||
|
||||
// s2 = std::move(s1);
|
||||
|
||||
|
||||
Monitor monitor;
|
||||
// SmartPointer<B> b(::new B(),PointerDisposition::Delete);
|
||||
SmartPointer<B> b(true);
|
||||
Callback<B,Info> callback(&(*b),&B::callback);
|
||||
monitor.setCallback(callback);
|
||||
|
||||
// FileIO fileIO = FileIO("/mnt/mariadb/backupdb.sql");
|
||||
// std::cout << "Reading ... " << std::endl;
|
||||
// int lines =0;
|
||||
// String strLine;
|
||||
// while(fileIO.readLine(strLine))
|
||||
// {
|
||||
// lines++;
|
||||
// if(!(lines%1000000))
|
||||
// {
|
||||
// printf("reading %d %s\n",lines,(char*)strLine);
|
||||
// }
|
||||
// }
|
||||
// fileIO.close();
|
||||
}
|
||||
|
||||
void stdLibStuff()
|
||||
{
|
||||
// std::vector<int> numbers;
|
||||
// numbers.push_back(100);
|
||||
// numbers.push_back(50);
|
||||
// numbers.push_back(100);
|
||||
|
||||
// int *p=&numbers[0];
|
||||
// int *p1=&numbers[1];
|
||||
// int *p2=&numbers[2];
|
||||
|
||||
// int max = *std::max_element(numbers.begin(), numbers.end());
|
||||
|
||||
// std::cout << typeid(max_it).name() << std::endl;
|
||||
// if(max_it == p)std::cout << "p" << std::endl;
|
||||
// if(max_it == p1) std::cout << "p1" << std::endl;
|
||||
// if(max_it == p2)std::cout << "p2" << std::endl;
|
||||
|
||||
|
||||
// std::cout << *max_it << std::endl;
|
||||
|
||||
|
||||
// int max_value = *max_it;
|
||||
// std::max(*numbers.begin());
|
||||
|
||||
|
||||
// std::cout << std::max(numbers) << std::endl;
|
||||
// Block<int> numbers;
|
||||
|
||||
|
||||
|
||||
// numbers.insert(newInt(100);
|
||||
|
||||
// std::cout<< std::min(100,50) << std::endl;
|
||||
// std::string s = "hello";
|
||||
// std::cout << s << std::endl;
|
||||
// std::vector<std::string> strings;
|
||||
// strings.push_back("hello");
|
||||
// strings.push_back("world");
|
||||
|
||||
// for (const std::string& s : strings)
|
||||
// {
|
||||
// std::cout << s << " ";
|
||||
// }
|
||||
|
||||
// char buffer[] = "Another direct copy";
|
||||
|
||||
// int a = sizeof(buffer);
|
||||
Info info;
|
||||
info.setMessage("Hello");
|
||||
|
||||
CallbackData<Info> callbackData(info);
|
||||
monitor.doCallback(callbackData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Callback callback(&(*b),C
|
||||
|
||||
|
||||
// SmartPointer<B> b1 = b;
|
||||
// b1->foo();
|
||||
// b->foo();
|
||||
|
||||
// String str="Hello";
|
||||
// b->setFoo(str);
|
||||
// str="Goodbye";
|
||||
// String str2=b->getFoo();
|
||||
// str2="world";
|
||||
|
||||
void readFile()
|
||||
{
|
||||
// MemoryMappedFile memoryMappedFile("/home/pi/Boneyard/ctest/main.cpp",MemoryMappedFile::CreationFlags::ReadOnly);
|
||||
|
||||
Reference in New Issue
Block a user