summaryrefslogtreecommitdiffhomepage
path: root/dev/examples/opt/opt.cc
blob: b34f2c7cc840cca92586195c29ac02ac43ddf6d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* 
  string checksum example
  written by Amlal El Mahrouss.
  licensed under the MIT license
 */

#include <lib/logic/opt.hpp>
#include <lib/io/print.hpp>
#include <lib/utility/crc32.hpp>
#include <string>

static const char do_hash(const std::string& in)
{
	int hash = 0;

	for (long index = 0; index < in.size(); ++index)
	{
		hash += in[index];
	}

	return hash;
}

static auto do_some(const std::string recv_data, const std::string check_data)
{
	const int hash_to_check = do_hash(check_data); /* here we assume this should match opt_hash */
	const int opt_hash		= do_hash(recv_data);  /* we assume that the hash is correct */

	auto opt = ocl::opt(ocl::eval_eq(hash_to_check, opt_hash)); /* do the compute */
	return opt;
}

/* finally test it */
int main(int argc, char** argv)
{
	// ... let's assume we fetch data from network...

	ocl::io::println("Testing data...");

	auto opt = do_some("Ohio", "Ohio");
	opt.expect("Checksum failed, Ohio isn't Ohio!");


	return 0;
}