## Registration code : 12 ##
It is currently Mon Nov 20, 2017 10:49 pm

All times are UTC + 1 hour [ DST ]





Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Macros
PostPosted: Mon Jul 28, 2008 11:10 pm 
Offline
Site Admin
User avatar
 WWW  Profile

Joined: Mon Jan 28, 2008 9:44 pm
Posts: 200
Location: France
Hi !
The port to Ogre3D forces me to re-write most of the code I've written so far, so I though it was a good occasion to use a few tools to make my life simpler.
I've made two macros that are really useful when dealing with stl containers, and I wanted to share them with you :

  • mapfind(key, map) : Searches for "key" in "map". Returns true if "key" is found, false otherwise.
    Code :
    Code:
    #define mapfind(key, map) ((map).find(key) != (map).end())

    Usage :
    Code:
    if (mapfind("parent", properties))
    {
        ...
    }

    ------------------------------------------------------
  • foreach(iter, container) : Iterates through "container" using iterator "iter" that you have previously defined.
    Code :
    Code:
    #define foreach(iter, container) for ((iter) = (container).begin(); (iter) != (container).end(); (iter)++)

    Usage :
    Code:
    vector<string>::iterator iterStr;
    foreach (iterStr, stringVector)
    {
        ...
    }

    map<int, string>::iterator iterKeys;
    foreach (iterKeys, keyMap)
    {
        ...
    }

_________________
- Kal.


Top
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour [ DST ]



Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
SourceForge.net Logo
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group  
Design By Poker Bandits