Ejemplo n.º 1
0
                    // wide to narrow
                    extern_string_type wton(const intern_string_type& src) const {
                        // preparations
                        // a size of src string
                        const std::size_t src_size = src.length();

                        // no more task
                        if (src_size == 0) return extern_string_type();

                        // calc a size of dst string
                        // This value is expected maximum.
                        const std::size_t dst_size = codecvt().max_length() * src_size;
                        // buffers
                        std::vector<extern_type> dst_vctr(dst_size);
                        extern_type* const dst = &dst_vctr[0];
                        // a dummy variable and a pointer to the next position
                        const intern_type* dummy;
                        extern_type* next;
                        // cache the first position of c style characters
                        const intern_type* const s = src.c_str();

                        // do it
                        if (codecvt().out(
                                    out_state(),
                                    s,   s   + src_size, dummy,
                                    dst, dst + dst_size, next) == codecvt_type::ok) {
                            return std::string(dst, next - dst);
                        }

                        std::wstring errmsg(L"failed: ");
                        errmsg.append(src);
                        throw util::exception::wlogic_error(errmsg);
                    }
Ejemplo n.º 2
0
int main(void)
{
	QUEUE queue;
	int value;

	init(&queue);

	in_state(en_queue(&queue, 1));
	in_state(en_queue(&queue, 3));
	in_state(en_queue(&queue, 6));
	in_state(en_queue(&queue, 4));
	in_state(en_queue(&queue, 9));
	in_state(en_queue(&queue, 10));
	in_state(en_queue(&queue, 19));

	traverse(&queue);

	out_state(out(&queue, &value));
	printf("出队元素:%d\n", value);

	traverse(&queue);

	return ;
}
Ejemplo n.º 3
0
int main(int argc, char** argv)
{
    (void)(argc);
    (void)(argv);
    
    test_fsm fsm;

    std::cout << std::endl << "Test fsm" << std::endl;

    std::cout << "sizeof(test_fsm): " << sizeof(test_fsm) << std::endl;

    struct ev_1 ev1;
    struct ev_2 ev2;
    struct ev_3 ev3;
    struct ev_4 ev4;
    struct ev_5 ev5;
    struct ev_6 ev6;

    st s;

    std::cout << "TEST 1" << std::endl;
    std::cout << "initial state: ";
    out_state(fsm.state());

    // 1 -> 2 -> 3 -> 4 -> 5 -> 1
    s = fsm.process_event(ev1);
    out_state(s);
    s = fsm.process_event(ev2);
    out_state(s);
    s = fsm.process_event(ev3);
    out_state(s);
    s = fsm.process_event(ev4);
    out_state(s);
    s = fsm.process_event(ev5);
    out_state(s);

    std::cout << std::endl << "TEST 2" << std::endl;
    std::cout << "initial state: ";
    out_state(fsm.state());

    // 1 -> 2 -> 4 -> 5 -> 5
    s = fsm.process_event(ev1);
    out_state(s);
    s = fsm.process_event(ev6);
    out_state(s);
    s = fsm.process_event(ev4);
    out_state(s);
    s = fsm.process_event(ev6);
    out_state(s);

    fsm.reset();
    std::cout << std::endl << "TEST 3" << std::endl;
    std::cout << "initial state: ";
    out_state(fsm.state());

    // 1 -> 2 -> 3
    s = fsm.process_event(ev1);
    out_state(s);
    s = fsm.process_event(ev2);
    out_state(s);
    s = fsm.process_event(ev6);
    out_state(s);

    std::cout << std::endl << "Player fsm" << std::endl;

    player p;
    std::cout << "sizeof(player): " << sizeof(player) << std::endl;

    p.process_event(open_close()); // user opens CD player
    p.process_event(open_close()); // inserts CD and closes
    std::vector<float> tracks(7);
    tracks[0] = 3.08;
    tracks[1] = 4.34;
    tracks[2] = 2.58;
    tracks[3] = 5.01;
    tracks[4] = 4.12;
    tracks[5] = 3.24;
    tracks[6] = 1.23;

    p.process_event(               // CD is detected
        cd_detected(
             "CD disk"
           , tracks
        )
    );
    p.process_event(play());       // etc.
    p.process_event(pause());
    p.process_event(play());
    p.process_event(stop());
}