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

Comparing libgender/util.h (file contents):
Revision 1.59 by root, Tue Nov 9 22:24:14 2004 UTC vs.
Revision 1.60 by root, Fri Nov 12 01:18:42 2004 UTC

531 } 531 }
532 }; 532 };
533 533
534 void draw_bbox (const sector &a, const sector &b); 534 void draw_bbox (const sector &a, const sector &b);
535 535
536}
537
538GLuint SDL_GL_LoadTexture (SDL_Surface *surface, GLfloat *texcoord); 536 GLuint load_texture (SDL_Surface *surface, GLfloat *texcoord);
537}
538
539template<typename value>
540struct idmappable
541{
542 struct idptr
543 {
544 value *p;
545 unsigned int gen;
546
547 idptr () : p(0) { };
548 };
549
550 vector<idptr> idmap;
551};
552
553struct idmap_context
554{
555 struct id
556 {
557 unsigned int idx;
558 unsigned int gen;
559 };
560
561 vector<id> freeid;
562
563 unsigned int next;
564
565 idmap_context ();
566 id get ();
567 void put (id &i);
568};
569
570template<class value>
571struct idmap
572{
573 typedef idmappable<value> base;
574 typedef typename idmappable<value>::idptr idptr;
575
576 idmap_context &ctx;
577 idmap_context::id id;
578
579 idmap (idmap_context &ctx)
580 : ctx (ctx)
581 , id (ctx.get ())
582 {
583 }
584
585 ~idmap ()
586 {
587 ctx.put (id);
588 }
589
590 value *&operator [](const base &k)
591 {
592 if (k.idmap.size () <= id.idx)
593 k.idmap.resize (id.idx + 1);
594
595 idptr &p = k.idmap [id.idx];
596
597 if (p.gen != id.gen)
598 {
599 delete p.p;
600 p.p = 0;
601 p.gen = id.gen;
602 }
603
604 return p.p;
605 }
606};
539 607
540#endif 608#endif
541 609

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines