ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.110 by root, Fri Jul 2 02:00:47 2010 UTC vs.
Revision 1.111 by root, Tue Jul 6 20:00:46 2010 UTC

641 { 641 {
642 erase (&obj); 642 erase (&obj);
643 } 643 }
644}; 644};
645 645
646/////////////////////////////////////////////////////////////////////////////
647
648// something like a vector or stack, but without
649// out of bounds checking
650template<typename T>
651struct fixed_stack
652{
653 T *data;
654 int size;
655 int max;
656
657 fixed_stack ()
658 : size (0), data (0)
659 {
660 }
661
662 fixed_stack (int max)
663 : size (0), max (max)
664 {
665 data = salloc<T> (max);
666 }
667
668 void reset (int new_max)
669 {
670 sfree (data, max);
671 size = 0;
672 max = new_max;
673 data = salloc<T> (max);
674 }
675
676 void free ()
677 {
678 sfree (data, max);
679 data = 0;
680 }
681
682 ~fixed_stack ()
683 {
684 sfree (data, max);
685 }
686
687 T &operator[](int idx)
688 {
689 return data [idx];
690 }
691
692 void push (T v)
693 {
694 data [size++] = v;
695 }
696
697 T &pop ()
698 {
699 return data [--size];
700 }
701
702 T remove (int idx)
703 {
704 T v = data [idx];
705
706 data [idx] = data [--size];
707
708 return v;
709 }
710};
711
712/////////////////////////////////////////////////////////////////////////////
713
646// basically does what strncpy should do, but appends "..." to strings exceeding length 714// basically does what strncpy should do, but appends "..." to strings exceeding length
647// returns the number of bytes actually used (including \0) 715// returns the number of bytes actually used (including \0)
648int assign (char *dst, const char *src, int maxsize); 716int assign (char *dst, const char *src, int maxsize);
649 717
650// type-safe version of assign 718// type-safe version of assign

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines