本文整理汇总了C++中Hashtable::Get方法的典型用法代码示例。如果您正苦于以下问题:C++ Hashtable::Get方法的具体用法?C++ Hashtable::Get怎么用?C++ Hashtable::Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hashtable
的用法示例。
在下文中一共展示了Hashtable::Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ssys
StarSystem * GetLoadedStarSystem( const char *system )
{
StarSystem *ss = star_system_table.Get( string( system ) );
std::string ssys( string( system )+string( ".system" ) );
if (!ss)
ss = star_system_table.Get( ssys );
return ss;
}
示例2:
Texture * Texture::Exists (string s) {
Texture * tmp = texHashTable.Get(VSFileSystem::GetHashName(s));
if (tmp==NULL) {
string tmpo;
tmp = texHashTable.Get (VSFileSystem::GetSharedTextureHashName (s));
}
if (tmp)
return tmp->Original();
return tmp;
}
示例3: checkbad
bool Texture::checkbad(const string & s)
{
string hashname = VSFileSystem::GetSharedTextureHashName(s);
bool * found=NULL;
found = badtexHashTable.Get (hashname);
if(found!=NULL) {
return true;
}
hashname = VSFileSystem::GetHashName(s);
found= badtexHashTable.Get (hashname);
if(found!=NULL) {
return true;
}
return false;
}
示例4: JumpTo
bool StarSystem::JumpTo( Unit *un, Unit *jumppoint, const std::string &system, bool force, bool save_coordinates )
{
if ( ( un->DockedOrDocking()&(~Unit::DOCKING_UNITS) ) != 0 )
return false;
if (Network == NULL || force) {
if (un->jump.drive >= 0)
un->jump.drive = -1;
#ifdef JUMP_DEBUG
VSFileSystem::vs_fprintf( stderr, "jumping to %s. ", system.c_str() );
#endif
StarSystem *ss = star_system_table.Get( system );
std::string ssys( system+".system" );
if (!ss)
ss = star_system_table.Get( ssys );
bool justloaded = false;
if (!ss) {
justloaded = true;
ss = _Universe->GenerateStarSystem( ssys.c_str(), filename.c_str(), Vector( 0, 0, 0 ) );
//NETFIXME: Do we want to generate the system if an AI unit jumps?
}
if ( ss && !isJumping( pendingjump, un ) ) {
#ifdef JUMP_DEBUG
VSFileSystem::vs_fprintf( stderr, "Pushing back to pending queue!\n" );
#endif
bool dosightandsound = ( ( this == _Universe->getActiveStarSystem( 0 ) ) || _Universe->isPlayerStarship( un ) );
int ani = -1;
if (dosightandsound)
ani = _Universe->activeStarSystem()->DoJumpingLeaveSightAndSound( un );
_Universe->AccessCockpit()->OnJumpBegin(un);
pendingjump.push_back( new unorigdest( un, jumppoint, this, ss, un->GetJumpStatus().delay, ani, justloaded,
save_coordinates ? ComputeJumpPointArrival( un->Position(), this->getFileName(),
system ) : QVector( 0, 0, 0 ) ) );
} else {
#ifdef JUMP_DEBUG
VSFileSystem::vs_fprintf( stderr, "Failed to retrieve!\n" );
#endif
return false;
}
if (jumppoint)
ActivateAnimation( jumppoint );
} else
//Networking mode
if (jumppoint) {
Network->jumpRequest( system, jumppoint->GetSerial() );
}
return true;
}
示例5: GetFactionIndex
/**
* Returns the relationship between myfaction and theirfaction
* 1 is happy. 0 is neutral (btw 1 and 0 will not attack)
* -1 is mad. <0 will attack
*/
int FactionUtil::GetFactionIndex( const string& name )
{
static Hashtable< string, int, 47 >factioncache;
int *tmp = factioncache.Get( name );
if (tmp)
return *tmp;
int i = GetFactionLookup( name.c_str() );
tmp = new int;
*tmp = i;
factioncache.Put( name, tmp );
return i;
}
示例6: checkold
GFXBOOL Texture::checkold(const string &s, bool shared, string & hashname)
{
hashname = shared?VSFileSystem::GetSharedTextureHashName(s):VSFileSystem::GetHashName(s);
Texture *oldtex= texHashTable.Get (hashname);
if(oldtex!=NULL) {
//*this = *oldtex;//will be obsoleted--unpredictable results with string()
setReference(oldtex);
//cerr<<"Found cached texture : "<<s<<" with hashname="<<hashname<<endl;
return GFXTRUE;
} else {
return GFXFALSE;
}
}
示例7: fprintf
Mesh::Mesh( const Mesh &m )
{
fprintf( stderr, "UNTESTED MESH COPY CONSTRUCTOR" );
this->orig = NULL;
this->hash_name = m.hash_name;
InitUnit();
Mesh *oldmesh = meshHashTable.Get( hash_name );
if (0 == oldmesh) {
vector< Mesh* > *vec = bfxmHashTable.Get( hash_name );
for (unsigned int i = 0; i < vec->size(); ++i) {
Mesh *mush = (*vec)[i]->orig ? (*vec)[i]->orig : (*vec)[i];
if (mush == m.orig || mush == &m)
oldmesh = (*vec)[i];
}
if (0 == oldmesh) {
if (vec->size() > 1) fprintf( stderr, "Copy constructor %s used in ambiguous Situation", hash_name.c_str() );
if ( vec->size() )
oldmesh = (*vec)[0];
}
}
if ( LoadExistant( oldmesh->orig != NULL ? oldmesh->orig : oldmesh ) )
return;
}
示例8: LoadString
PyCodeObject *CompilePython (const std::string &name) {
Python::reseterrors();
PyCodeObject * retval = compiled_python.Get (name);
Python::reseterrors();
if (retval) {
return retval;
}
char * str = LoadString (name.c_str());
if (str) {
fprintf(stdout,"Compiling python module %s\n",name.c_str());
std::string compiling_name = getCompilingName(name).c_str();
char * temp = strdup(compiling_name.c_str());
retval = (PyCodeObject *) Py_CompileString (str,temp,Py_file_input);
if (retval) {
compiled_python.Put(name,retval);
}
free (temp);
free (str);
}
return retval;
}
示例9: LoadMesh
Mesh::Mesh( std::string filename, const Vector &scale, int faction, Flightgroup *fg, bool orig ) : hash_name( filename )
{
this->convex = false;
Mesh *cpy = LoadMesh( filename.c_str(), scale, faction, fg, vector< std::string > () );
if (cpy->orig) {
LoadExistant( cpy->orig );
delete cpy; //wasteful, but hey
if (orig != false) {
orig = false;
std::vector< Mesh* > *tmp = bfxmHashTable.Get( this->orig->hash_name );
if (tmp && tmp->size() && (*tmp)[0] == this->orig) {
if (this->orig->refcount == 1) {
bfxmHashTable.Delete( this->orig->hash_name );
delete tmp;
orig = true;
}
}
if (meshHashTable.Get( this->orig->hash_name ) == this->orig) {
if (this->orig->refcount == 1) {
meshHashTable.Delete( this->orig->hash_name );
orig = true;
}
}
if (orig) {
Mesh *tmp = this->orig;
tmp->orig = this;
this->orig = NULL;
refcount = 2;
delete[] tmp;
}
}
} else {
delete cpy;
fprintf( stderr, "fallback, %s unable to be loaded as bfxm\n", filename.c_str() );
}
}
示例10: main
// This program exercises the Hashtable class.
int main(int argc, char ** argv)
{
CompleteSetupSystem css;
Message temp; if (ParseArgs(argc, argv, temp) == B_NO_ERROR) HandleStandardDaemonArgs(temp);
if (temp.HasName("inter")) return DoInteractiveTest();
// Make sure that setting equal to an empty Hashtable clears the buffer (FogBugz #10274)
{
Hashtable<String,String> table;
for (int32 i=0; i<1000; i++) table.Put(String("xxx%1").Arg(i), "foo");
printf("After population of " UINT32_FORMAT_SPEC " items, table size is " UINT32_FORMAT_SPEC "\n", table.GetNumItems(), table.GetNumAllocatedItemSlots());
if (table.ShrinkToFit() == B_NO_ERROR) printf("After shrink-to-fit, table allocation is " UINT32_FORMAT_SPEC " for " UINT32_FORMAT_SPEC " items\n", table.GetNumAllocatedItemSlots(), table.GetNumItems());
else printf("Shrink-to-fit failed!?\n");
printf("Before copy-from-empty, table allocation is " UINT32_FORMAT_SPEC "\n", table.GetNumAllocatedItemSlots());
table = GetDefaultObjectForType< Hashtable<String,String> > ();
printf(" After copy-from-empty, table allocation is " UINT32_FORMAT_SPEC "\n", table.GetNumAllocatedItemSlots());
}
// Test C++11 move semantics to make sure they aren't stealing
{
String key = "key";
String value = "value";
Hashtable<String,String> table;
table.Put(key, value);
if (key != "key") {printf("ERROR, Hashtable stole my key!\n"); exit(10);}
if (value != "value") {printf("ERROR, Hashtable stole my value!\n"); exit(10);}
}
// Test muscleSwap()
TestMuscleSwap<Hashtable<String,String> >("Hashtable");
TestMuscleSwap<OrderedKeysHashtable<String,String> >("OrderedKeysHashtable");
TestMuscleSwap<OrderedValuesHashtable<String,String> >("OrderedValuesHashtable");
// Test iterator behaviour when deleting keys
TestIteratorSanityOnRemoval(false);
TestIteratorSanityOnRemoval(true);
{
LogTime(MUSCLE_LOG_INFO, "Testing a keys-only Hashtable value...\n");
Hashtable<int, Void> keysOnly;
printf("sizeof(keysOnly)=%u\n", (unsigned int) sizeof(keysOnly));
keysOnly.PutWithDefault(1);
keysOnly.PutWithDefault(2);
keysOnly.PutWithDefault(5);
keysOnly.PutWithDefault(10);
for (HashtableIterator<int, Void> iter(keysOnly); iter.HasData(); iter++) printf("key=%i\n", iter.GetKey());
}
{
LogTime(MUSCLE_LOG_INFO, "Testing Tuple as a Hashtable key...\n");
// A quick test of the Tuple class as a Hashtable key
typedef Tuple<2,int> MyType;
Hashtable<MyType, int> tupleTable;
MyType a; a[0] = 5; a[1] = 6;
MyType b; b[0] = 7; b[1] = 8;
tupleTable.Put(a, 1);
tupleTable.Put(b, 2);
for (HashtableIterator<MyType, int> iter(tupleTable); iter.HasData(); iter++)
{
const MyType & key = iter.GetKey();
printf("key=%i,%i val=%i\n", key[0], key[1], iter.GetValue());
}
int * ra = tupleTable.Get(a);
int * rb = tupleTable.Get(b);
printf("tuple: ra=[%i] rb=[%i]\n", ra?*ra:666, rb?*rb:666);
}
{
LogTime(MUSCLE_LOG_INFO, "Testing Rect as a Hashtable key...\n");
// A quick test of the Tuple class as a Hashtable key
Hashtable<Rect, int> tupleTable;
Rect a(1,2,3,4);
Rect b(5,6,7,8);
tupleTable.Put(a, 1);
tupleTable.Put(b, 2);
for (HashtableIterator<Rect, int> iter(tupleTable); iter.HasData(); iter++)
{
const Rect & key = iter.GetKey();
printf("key=%f,%f,%f,%f val=%i\n", key.left(), key.top(), key.right(), key.bottom(), iter.GetValue());
}
int * ra = tupleTable.Get(a);
int * rb = tupleTable.Get(b);
printf("Rect: ra=[%p] rb=[%p]\n", ra, rb);
}
{
LogTime(MUSCLE_LOG_INFO, "Testing Point as a Hashtable key...\n");
// A quick test of the Tuple class as a Hashtable key
Hashtable<Point, int> tupleTable;
//.........这里部分代码省略.........
示例11: StdinThreadEntryFunc
static unsigned __stdcall StdinThreadEntryFunc(void *)
{
if (_stdinHandle != INVALID_HANDLE_VALUE)
{
DWORD oldConsoleMode = 0;
GetConsoleMode(_stdinHandle, &oldConsoleMode);
SetConsoleMode(_stdinHandle, oldConsoleMode | ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
// The only time this thread is allowed to exit is if stdin is closed. Otherwise it runs until the
// process terminates, because Windows has no way to unblock the call to ReadFile()!
Hashtable<uint32, ConstSocketRef> temp; // declared out here only to avoid reallocations on every loop iteration
char buf[4096];
DWORD numBytesRead;
while(ReadFile(_stdinHandle, buf, sizeof(buf), &numBytesRead, NULL))
{
// Grab a temporary copy of the listeners-set. That we we don't risk blocking in SendData() while holding the mutex.
if (_slaveSocketsMutex.Lock() == B_NO_ERROR)
{
temp = _slaveSockets;
_slaveSocketsMutex.Unlock();
}
// Now send the data we read from stdin to all the registered sockets
bool trim = false;
for (HashtableIterator<uint32, ConstSocketRef> iter(temp); iter.HasData(); iter++) if (SendData(iter.GetValue(), buf, numBytesRead, true) != numBytesRead) {trim = true; iter.GetValue().Reset();}
// Lastly, remove from the registered-sockets-set any sockets that SendData() errored out on.
// This will cause the socket connection to be closed and the master thread(s) to be notified.
if ((trim)&&(_slaveSocketsMutex.Lock() == B_NO_ERROR))
{
for (HashtableIterator<uint32, ConstSocketRef> iter(_slaveSockets); iter.HasData(); iter++)
{
const ConstSocketRef * v = temp.Get(iter.GetKey());
if ((v)&&(v->IsValid() == false)) (void) _slaveSockets.Remove(iter.GetKey());
}
_slaveSocketsMutex.Unlock();
}
temp.Clear(); // it's important not to have extra Refs hanging around in case the process exits!
}
// Restore the old console mode before we leave
SetConsoleMode(_stdinHandle, oldConsoleMode);
}
// Oops, stdin failed... clear the slave sockets table so that the client objects will know to close up shop
if (_slaveSocketsMutex.Lock() == B_NO_ERROR)
{
_stdinThreadStatus = STDIN_THREAD_STATUS_EXITED;
_slaveSockets.Clear();
// We'll close our own handle, thankyouverymuch
if (_slaveThread != INVALID_HANDLE_VALUE)
{
CloseHandle(_slaveThread);
_slaveThread = INVALID_HANDLE_VALUE;
}
if (_stdinHandle != INVALID_HANDLE_VALUE)
{
CloseHandle(_stdinHandle);
_stdinHandle = INVALID_HANDLE_VALUE;
}
_slaveSocketsMutex.Unlock();
}
return 0;
}
示例12: Get
collideTrees* collideTrees::Get( const std::string &hash_key )
{
return unitColliders.Get( hash_key );
}
示例13: RemoveStarsystemFromUniverse
void StarSystem::RemoveStarsystemFromUniverse()
{
if ( star_system_table.Get( filename ) )
star_system_table.Delete( filename );
}
示例14: main
int main()
{
ScreenManager::GetInstance().SetText("Testing");
ScreenManager::GetInstance().DrawText();
Material* quartz = new Material((char*)"Quartz", false, false);
Material* granite = new Material((char*)"Granite", false, false);
Clock* clock = new Clock();
World* world = new World();
SolarSystem* solar = new SolarSystem();
// name, mass, diameter (mi), radius (mi), surf gravity (m/s2)
solar->Add(new Star((char*)"Sun", MASS(1.989,30), 864337.3, 432169, 274));
solar->Add(new Planet((char*)"Mercury", MASS(3.285,23), 3032, 1516, 3.7));
solar->Add(new Planet((char*)"Venus", MASS(4.867,24), 7520.8, 3760, 8.87));
solar->Add(new Planet((char*)"Earth", MASS(5.972,24), 7917.5, 3959, 9.807));
solar->Add(new Planet((char*)"Mars", MASS(6.39,23), 4212, 2106, 3.711));
solar->Add(new Planet((char*)"Jupiter", MASS(1.898,27), 86881.4, 43441, 24.79));
solar->Add(new Planet((char*)"Saturn", MASS(5.683,26), 72367.4, 36184, 10.44));
solar->Add(new Planet((char*)"Uranus", MASS(8.681,25), 31518, 15759, 8.87));
solar->Add(new Planet((char*)"Neptune", MASS(1.024,26), 30599, 15299, 11.15));
// name mass diameter (mi)radius (mi)surf gravity (m/s2)
Planet* earth = new Planet( (char*)"Earth", MASS(5.972,24), 7917.5, 3959, 9.807);
Satellite* moon = new Satellite( (char*)"Moon", MASS(7.347,22), 2159, 1079, 1.62);
earth->Add(moon);
solar->Add(earth);
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "Game");
window.setFramerateLimit(60);
srand(time(0));
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
Hashtable hash;
hash.Put("Test","Test2");
int one = 1;
hash.Put("one", &one);
printf("Hashtable %s %d",(char *)hash.Get("Test"), *(int *)hash.Get("one"));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
clock->Update();
window.clear();
window.draw(shape);
window.display();
}
Engine egnine;
return 0;
}
示例15: main
/* This little program demonstrates the semantics of the keys used in a Hashtable */
int main(int argc, char ** argv)
{
CompleteSetupSystem css;
PrintExampleDescription();
// In order to use a type as a Key in a Hashtable, that type must have
// two properties: There must be a way to compute a hash-code for any
// give Key object, and it must be possible to compare two Key objects
// for equality (using the == operator).
//
// If you want to call SortByKey() or use the type as a key in an
// OrderedKeysHashtable, the < operator must also be defined for the type.
// For primitive/POD key types, the Hashtable class uses SFINAE
// magic so that Hashtables with those keys will automatically "just work".
// For example:
Hashtable<int, String> tableWithIntKeys; // works!
Hashtable<uint16, String> tableWithUint16Keys; // works!
Hashtable<uint32, String> tableWithUint32Keys; // works!
Hashtable<int32, String> tableWithInt32Keys; // works!
Hashtable<char, String> tableWithCharKeys; // works!
Hashtable<float, String> tableWithFloatKeys; // works! (but probably a bad idea!)
// When using a "Proper class" as a Key type, you'll want to make
// sure it has a working == operator and that it has a method
// like this one defined:
//
// uint32 HashCode() const;
//
// This method should return a 32-bit value based on the object's
// current state; that value will be used to place the key/value
// pair within the Hashtable's array.
Hashtable<MyKeyClass, int> myTable;
(void) myTable.Put(MyKeyClass(12, 23), 0);
(void) myTable.Put(MyKeyClass(21, 22), 5);
(void) myTable.Put(MyKeyClass(37, 19), 6);
printf("myTable's contents are:\n");
for (HashtableIterator<MyKeyClass, int> iter(myTable); iter.HasData(); iter++)
{
printf(" [%s] -> %i\n", iter.GetKey().ToString()(), iter.GetValue());
}
printf("\n");
// Test retrieving a value using a MyKeyClass object as the key
int retVal;
if (myTable.Get(MyKeyClass(21, 22), retVal) == B_NO_ERROR)
{
printf("myTable.Get(MyKeyClass(21, 22) retrieved a key with value %i\n", retVal);
}
else printf("myTable.Get(MyKeyClass(21, 22) failed!\n");
// You can even use pointers-to-objects as your keys as long as
// the pointed-to-objects can be used as keys. The pointer-keys
// will generally work the same as the value-keys, but note that
// you are responsible for making sure the pointers remain valid
// for the lifetime of the Hashtable!
String s1 = "One";
String s2 = "Two";
String s3 = "Three";
Hashtable<String *, int> ptrTable;
ptrTable.Put(&s1, 1);
ptrTable.Put(&s2, 2);
ptrTable.Put(&s3, 3);
printf("\n");
printf("ptrTable's contents are:\n");
for (HashtableIterator<String *, int> iter(ptrTable); iter.HasData(); iter++)
{
printf(" %s -> %i\n", iter.GetKey()->Cstr(), iter.GetValue());
}
printf("\n");
// Refs can also be used as keys, if, you're in to that sort of thing.
// Here's a Hashtable with ConstSocketRefs as keys!
Hashtable<ConstSocketRef, Void> sockTable;
for (int i=0; i<10; i++) sockTable.PutWithDefault(CreateUDPSocket());
printf("sockTable's contents are:\n");
for (HashtableIterator<ConstSocketRef, Void> iter(sockTable); iter.HasData(); iter++)
{
const Socket * s = iter.GetKey()();
printf(" socket descriptor #%i\n", s ? s->GetFileDescriptor() : -1);
}
printf("\n");
return 0;
}