Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    331

    HashMap sincronizzate in Visual C++

    Salve a tutti, ho questa classe in java:

    public class DatiAggiornamentoPermanenzaLista {

    private static Map elencoSMS = Collections.synchronizedMap(new HashMap());

    public static void addElem(DatiAggiornamentoPermanenzaVO elem, String key) {
    elencoSMS.put(key, elem);
    }

    public static void removeElem(String key) {
    elencoSMS.remove(key);
    }

    public static DatiAggiornamentoPermanenzaVO getElem(String key) {
    return (DatiAggiornamentoPermanenzaVO)elencoSMS.get(key);
    }

    public static int getSizeLista() {
    return elencoSMS.size();
    }

    }

    che realizza una HashMap statica sincronizzata e vorrei sapere se e' possibile fare qualcosa del genere usando Microsoft Visual C++ 6.0.

    Ciao
    Sandro

  2. #2
    codice:
    // Compiled with: i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367) 
    
    #include <iostream>
    #include <map>
    #include <string>
    
    namespace ig{
    	struct DatiAggiornamentoPermanenzaVO{
    		int test;
    	};
    	
    	typedef std::string String;
    	typedef std::map <String, DatiAggiornamentoPermanenzaVO> Map;
    	
    	class DatiAggiornamentoPermanenzaLista{
    		private:
    		static Map elencoSMS;
    		
    		public:
    		static void addElem (const DatiAggiornamentoPermanenzaVO &elem, const String &key){
    			elencoSMS[key] = elem;
    		}
    
    		static void removeElem (const String &key){
    			elencoSMS.erase (key);
    		}
    
    		static DatiAggiornamentoPermanenzaVO getElem (const String &key){
    			return elencoSMS[key];
    		}
    		static int getSizeLista() {
    			return elencoSMS.size();	
    		}
    	};
    	
    	// necessary because it is static in class declaration
    	Map DatiAggiornamentoPermanenzaLista::elencoSMS;
    }
    
    int main (int argc, char * const argv[]){
    	const ig:: DatiAggiornamentoPermanenzaVO el1={1};
    	const ig:: DatiAggiornamentoPermanenzaVO el2={2};
    	ig:: DatiAggiornamentoPermanenzaLista lista;
    	lista.addElem (el1, "uno");
    	lista.addElem (el2, "due");
    	lista.removeElem ("uno");
    	std::cout << lista.getSizeLista () << std::endl;
    	return 0;
    }

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.