PDA

Visualizza la versione completa : [C++] HashMap sincronizzate in Visual C++


DarthSandr
19-10-2007, 17:58
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

MacApp
20-10-2007, 09:32
// 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;
}

Loading