Exemplo n.º 1
0
void testIter() {
	std::ostringstream out { };
	std::ostream_iterator<std::string> out_iter(out, " ");
	dynArray<std::string> test { "the", "answer", "is", "42" };
	std::copy(test.begin(), test.end(), out_iter);
	ASSERT_EQUAL("the answer is 42 ", out.str());
}
Exemplo n.º 2
0
void testReverseIter() {
	std::ostringstream out { };
	std::ostream_iterator<char> out_iter(out, "");
	dynArray<char> test { 'o', 'l', 'l', 'a', 'h' };
	std::copy(test.rbegin(), test.rend(), out_iter);
	ASSERT_EQUAL("hallo", out.str());
}
Exemplo n.º 3
0
static void extract_base64_str(const std::string &_src, std::string &_dst)
{
    _dst.reserve (_src.length() * 3 / 4);
    std::back_insert_iterator<std::string> out_iter (_dst);

    yplatform::service::base64::decoder base64;
    base64.decode (_src.begin(), _src.end(), out_iter);
}
Exemplo n.º 4
0
void test_rev_iter_const() {
	std::ostringstream out { };
	std::ostream_iterator<int> out_iter(out, "");
	dynArray<int> const test { 2, 4 };

	std::copy(test.rbegin(), test.rend(), out_iter);

	ASSERT_EQUAL("42", out.str());
}
Exemplo n.º 5
0
void test_rev_iter() {
	std::ostringstream out { };
	std::ostream_iterator<char> out_iter(out, "");
	dynArray<char> test { 't', 's', 'e', 't' };

	std::copy(test.rbegin(), test.rend(), out_iter);

	ASSERT_EQUAL("test", out.str());
}
Exemplo n.º 6
0
void test_rand_acc_iter_const() {
	std::ostringstream out { };
	std::ostream_iterator<std::string> out_iter(out, " ");
	dynArray<std::string> const test { "42", "is", "always", "the", "answer" };

	std::copy(test.begin(), test.end(), out_iter);

	ASSERT_EQUAL("42 is always the answer ", out.str());
}
Exemplo n.º 7
0
void test_const_rev_iter_const() {
	std::ostringstream out { };
	std::ostream_iterator<int> out_iter(out, " ");
	dynArray<int> test { 13, 8, 5, 3, 2, 1, 1 };

	std::copy(test.crbegin(), test.crend(), out_iter);

	ASSERT_EQUAL("1 1 2 3 5 8 13 ", out.str());
}
Exemplo n.º 8
0
void test_make_dynArray() {
	std::ostringstream out { };
	std::ostream_iterator<std::string> out_iter(out, " ");
	auto test = dynArray<std::string>::makedynArray( { "this", "is", "my", "last", "test" });

	std::copy(test.begin(), test.end(), out_iter);

	ASSERT_EQUAL("this is my last test ", out.str());
}
Exemplo n.º 9
0
void test_func_erase() {
	std::ostringstream out { };
	std::ostream_iterator<std::string> out_iter(out, " ");
	dynArray<std::string> test { "this", "lköhjasf", "is", "a test" };

	test.erase(test.begin() + 1);

	std::copy(test.begin(), test.end(), out_iter);

	ASSERT_EQUAL("this is a test ", out.str());
}
Exemplo n.º 10
0
 inline utf8_string to_utf8(Char value)
 {
     // always store as UTF8
     utf8_string result;
     typedef std::back_insert_iterator<utf8_string> insert_iter;
     insert_iter out_iter(result);
     utf8_output_iterator<insert_iter> utf8_iter(out_iter);
     typedef typename make_unsigned<Char>::type UChar;
     *utf8_iter = (UChar)value;
     return result;
 }
Exemplo n.º 11
0
void testEraseTwoIter() {
	std::ostringstream out { };
	std::ostream_iterator<std::string> out_iter(out, " ");
	dynArray<std::string> test { "this", "is", "a", "test", "this", "will", "be", "erased" };

	test.erase(test.begin() + 4, test.end());

	std::copy(test.begin(), test.end(), out_iter);

	ASSERT_EQUAL("this is a test ", out.str());
}
Exemplo n.º 12
0
void test_func_erase_cont_iter() {
	std::ostringstream out { };
	std::ostream_iterator<int> out_iter(out, "");
	dynArray<int> test { 4, 3, 2, 1 };

	test.erase(test.erase(test.cbegin() + 1) + 1);

	std::copy(test.begin(), test.end(), out_iter);

	ASSERT_EQUAL("42", out.str());
}
Exemplo n.º 13
0
void test_func_erase_two_const_iter() {
	std::ostringstream out { };
	std::ostream_iterator<std::string> out_iter(out, " ");
	dynArray<std::string> test { "this", "will", "be", "erased", "this", "is", "another", "test" };

	test.erase(test.begin(), test.begin() + 4);

	std::copy(test.begin(), test.end(), out_iter);

	ASSERT_EQUAL("this is another test ", out.str());
}
Exemplo n.º 14
0
bool CInfiniteMediatorTest::filesEqual(std::string fname0, std::string fname1)
{
  std::ifstream filein(fname0.c_str());
  std::ifstream fileout(fname1.c_str());

  std::istream_iterator<char> end_of_stream;
  std::istream_iterator<char> in_iter(filein);
  std::istream_iterator<char> out_iter(fileout);

  return std::equal(in_iter,end_of_stream,out_iter);

}
Exemplo n.º 15
0
 inline utf8_string to_utf8(Char const* str)
 {
     // always store as UTF8
     utf8_string result;
     typedef std::back_insert_iterator<utf8_string> insert_iter;
     insert_iter out_iter(result);
     utf8_output_iterator<insert_iter> utf8_iter(out_iter);
     typedef typename make_unsigned<Char>::type UChar;
     while (*str)
         *utf8_iter++ = (UChar)*str++;
     return result;
 }
Exemplo n.º 16
0
 inline utf8_string 
 to_utf8(std::basic_string<Char, Traits, Allocator> const& str)
 {
     // always store as UTF8
     utf8_string result;
     typedef std::back_insert_iterator<utf8_string> insert_iter;
     insert_iter out_iter(result);
     utf8_output_iterator<insert_iter> utf8_iter(out_iter);
     typedef typename make_unsigned<Char>::type UChar;
     BOOST_FOREACH(Char ch, str)
     {
         *utf8_iter++ = (UChar)ch;
     }
Exemplo n.º 17
0
void to_dot(
    std::ostream& out,
    Iterator begin, Iterator end,
    dot_node_decorator_t node_decorator
)
{
    boost::function_output_iterator<Impl::dot_node_outputer>
        out_iter(Impl::dot_node_outputer(out, node_decorator));

    out << "digraph G {" << std::endl;
    out << "  ordering = out;" << std::endl;
    bfs_down(begin, end, out_iter);
    out << "}" << std::endl;
}
Exemplo n.º 18
0
int main() 
{
    // write one string per line to the standard output
    ostream_iterator<string> out_iter(cout, "\n");

    // read strings from standard input and the end iterator
    istream_iterator<string> in_iter(cin), eof;

    // read until eof and write what was read to the standard output
    while (in_iter != eof) 
	    // write value of in_iter to standard output
	    // and then increment the iterator to get the next value from cin
	    *out_iter++ = *in_iter++;  

    return 0;
}
Exemplo n.º 19
0
int main()
{
    unsigned long i;
    struct timeval start, end;
    long long startusec, endusec;
    double elapsed;
    int err;
    pthread_t tid;

    srandom(time(NULL));
    for (i = 0; i < NUMNUM; ++i)
    {
        nums[i] = random() % NUMNUM;
    }
    gettimeofday(&start, NULL);
    pthread_barrier_init(&b, NULL, NTHR + 1);
    for (i = 0; i < NTHR; ++i)
    {
        err = pthread_create(&tid, NULL, thr_fn, (void *)(i * THUM));
        if (err != 0)
        {
            std::cerr << "phread_create faile" << std::endl;
            exit(EXIT_FAILURE);
        }
    }
    pthread_barrier_wait(&b);
    merge();
    gettimeofday(&end, NULL);

    startusec = start.tv_sec * 1000000 + start.tv_usec;
    endusec = end.tv_sec * 1000000 + end.tv_usec;
    elapsed = static_cast<double>(endusec - startusec) / 1000000.0;
    std::cout << "sort took " << elapsed << "seconds." << std::endl;

    std::ostream_iterator<int> out_iter(std::cout, " ");
    std::copy(std::begin(snums), std::end(snums), out_iter);
    std::cout << std::endl;

    return 0;
}
Exemplo n.º 20
0
int main ( )
{
#ifndef _RWSTD_STRICT_ANSI

    // use an extension of this implementation: NULL file name argument
    // creates a temporary file; closing the file stream object or its
    // associated filebuf removes the temporary file
    const char* const fname = 0;
    
#else   // if defined (_RWSTD_STRICT_ANSI)

    char fnamebuf [L_tmpnam];

    // create a temporary filename
    const char* const fname = std::tmpnam (fnamebuf);

    if (!fname)
        return 1;

#endif   // _RWSTD_STRICT_ANSI

    // create a filebuf object
    std::filebuf buf;

    // open the file and link it to the filebuf object
    buf.open (fname, std::ios::in | std::ios::out | std::ios::trunc);

    // create an ostreambuf_iterator and link it to 
    // the filebuf object
    std::ostreambuf_iterator<char, std::char_traits<char> > out_iter (&buf);

    const char charset[] =
        "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

    // output characters into the file using the ostreambuf_iterator
    for (unsigned i = 0; charset [i]; ++i)
        out_iter = charset [i];

    // seek to the beginning of the file
    buf.pubseekpos(0);
  
    // create an istreambuf_iterator and link it to  the filebuf object
    std::istreambuf_iterator<char, std::char_traits<char> > in_iter (&buf);

    // construct an end of stream iterator
    std::istreambuf_iterator<char, std::char_traits<char> > end;

    std::cout << '\n';

    // output the contents of the file
    while (!in_iter.equal (end))
        std::cout << *in_iter++;

    std::cout << '\n';

    if (fname) {
        // close the stream before removing the file
        buf.close ();

        // remove the temporary file (must have a name)
        std::remove (fname);
    }

    return 0;
}