本文整理汇总了C++中DynArray类的典型用法代码示例。如果您正苦于以下问题:C++ DynArray类的具体用法?C++ DynArray怎么用?C++ DynArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DynArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/**
* Constructor handles program flow. Gets user menu choice then acts on that.
*/
Controller::Controller() {
bool running = true;
int menuChoice = -1;
do {
menuChoice = view.getMenuChoice();
if (menuChoice == 1) { // add movies
DynArray movieList;
view.getMovies(&movieList);
localMovies.addAllMovies(&movieList);
masterMovies.addMovies(&movieList);
} else if (menuChoice == 2) { // delete movie
string movieTitle = view.deleteMovie();
Movie* removedMovie = localMovies.removeMovie(movieTitle);
for (int i = 0; i < localMovies.getSize(); ++i) {
if (localMovies.movieList[i]->getTitle().compare(movieTitle)
== 0) {
DynArray movieToRemove;
movieToRemove.addMovie(localMovies.movieList[i]);
masterMovies.removeMovies(&movieToRemove);
break;
}
}
delete removedMovie;
} else if (menuChoice == 3) { // list all movies
view.listMovies(&localMovies);
} else if (menuChoice == 4) { // list movies by genre
Genre genre = view.getGenre();
DynArray genreMovies;
for (int i = 0; i < localMovies.getSize(); ++i) {
if (localMovies.movieList[i]->getGenre() == genre) {
genreMovies.addMovie(localMovies.movieList[i]);
}
}
view.listMovies(&genreMovies);
} else if (menuChoice == 0) { // exit
running = false;
} else {
view.displayMessage("Invalid menu option!");
}
} while (running);
}
示例2: SetExpiry
int Client::SetExpiry(const ByteString &key, uint64_t expiryTime)
{
int status;
Command* cmd;
ByteString args[2];
DynArray<32> numString;
VALIDATE_CLIENT();
VALIDATE_KEY_LEN(key);
VALIDATE_SAFE();
VALIDATE_WRITE();
numString.Writef("%U", expiryTime);
args[0] = key;
args[1] = numString;
cmd = CreateCommand(KEYSPACECLIENT_SET_EXPIRY, SIZE(args), args);
safeCommands.Append(cmd);
if (IS_BATCHED())
{
result->AppendCommand(cmd);
return KEYSPACE_SUCCESS;
}
result->Close();
result->AppendCommand(cmd);
EventLoop();
status = result->CommandStatus();
return status;
}
示例3: FindPaletteIndex
// FindPaletteIndex()
// Returns the palette index that most closely matches the given
// RGB value. This only works in Indexed mode. The optional low
// and high values specify the low and hight palette indices to
// to search (inclusive). This is similar to the other
// FindPaletteIndex() functions, but also takes a pointer to a
// DynArray of palette indices to match against.
IMG_BYTE ImageClass::FindPaletteIndex( IMG_BYTE r, IMG_BYTE g, IMG_BYTE b, DynArray<int> &array ) {
if( type != IMAGE_INDEXED )
return 0;
if( array.NumElements() == 0 )
return 0;
IMG_BYTE closest = 0; // Closest index to the target color
int how_close = 1000; // 0 == perfect match
int this_try;
int step = sizeof( IMG_BYTE ) * 3;
IMG_BYTE * rgb = &(palette[ (array[0]) ]);
for( unsigned int i=0; i < array.NumElements(); i++ ) {
rgb = GetPaletteColor( array[i] );
if( r > rgb[0] ) this_try = r - rgb[0]; // Find the red difference
else this_try = rgb[0] - r;
if( g > rgb[1] ) this_try += g - rgb[1]; // Find the green difference
else this_try += rgb[1] - g;
if( b > rgb[2] ) this_try += b - rgb[2]; // Find the blue difference
else this_try += rgb[2] - b;
if( this_try < how_close ) { // See if this is closer than the last match
closest = array[i];
how_close = this_try;
}
}
return closest;
}
示例4: main
int main(int argc, char **argv)
{
init_shogun(&print_message, &print_message, &print_message);
/* create example tree */
CModelSelectionParameters* tree=create_param_tree();
tree->print();
SG_SPRINT("----------------------------------\n");
/* build combinations of parameter trees */
DynArray<CParameterCombination*> combinations;
tree->get_combinations(combinations);
apply_parameter_tree(combinations);
/* print and directly delete them all */
for (index_t i=0; i<combinations.get_num_elements(); ++i)
combinations[i]->destroy(true, true);
/* delete example tree (after processing of combinations because CSGObject
* (namely the kernel) of the tree is SG_UNREF'ed (and not REF'ed anywhere
* else) */
tree->destroy();
exit_shogun();
return 0;
}
示例5: SetProperty
void CEntityPropertyHandler::SetProperty(IEntity *pIEntity, int index, const char *value)
{
EntityId id = pIEntity->GetId();
CMonoEntityExtension *pEntity = nullptr;
if (IGameObject *pGameObject = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetGameObject(id))
pEntity = static_cast<CMonoEntityExtension *>(pGameObject->QueryExtension(pIEntity->GetClass()->GetName()));
// Only true after game has started, limiting this to changes made in Editor.
if(pEntity && pEntity->IsInitialized())
pEntity->SetPropertyValue(m_pProperties[index].info, value);
else
{
bool exists = false;
for(auto it = m_queuedProperties.begin(); it != m_queuedProperties.end(); ++it)
{
if((*it).first == id)
{
(*it).second.push_back(SQueuedProperty(m_pProperties[index].info, value));
exists = true;
break;
}
}
if(!exists)
{
DynArray<SQueuedProperty> queuedPropertiesForEntity;
queuedPropertiesForEntity.push_back(SQueuedProperty(m_pProperties[index].info, value));
m_queuedProperties.insert(TQueuedPropertyMap::value_type(id, queuedPropertiesForEntity));
}
}
}
示例6: UpdateRenderMesh
void CClipVolumeProxy::UpdateRenderMesh(IRenderMesh* pRenderMesh, const DynArray<Vec3>& meshFaces)
{
m_pRenderMesh = pRenderMesh;
gEnv->pEntitySystem->ReleaseBSPTree3D(m_pBspTree);
const size_t nFaceCount = meshFaces.size() / 3;
if(nFaceCount > 0)
{
IBSPTree3D::FaceList faceList;
faceList.reserve(nFaceCount);
for(int i=0; i<meshFaces.size(); i+=3)
{
IBSPTree3D::CFace face;
face.push_back(meshFaces[i + 0]);
face.push_back(meshFaces[i + 1]);
face.push_back(meshFaces[i + 2]);
faceList.push_back(face);
}
m_pBspTree = gEnv->pEntitySystem->CreateBSPTree3D(faceList);
}
if(m_pEntity && m_pClipVolume)
gEnv->p3DEngine->UpdateClipVolume(m_pClipVolume, m_pRenderMesh, m_pBspTree, m_pEntity->GetWorldTM(), !m_pEntity->IsHidden(), m_pEntity->GetName());
}
示例7: Breathe
void KChatSocket::Breathe(int msec)
{
JgVirtualSocket::Breathe(msec);
void* packetPtrs[64];
char packetBuffer[10240];
DynArray<void*> packets;
packets.attach(&packetPtrs[0], 64, 0);
KClientGateListener* cgl = KClientGateListener::getSingletonPtr();
while(!m_shouldRemove)
{
int_r packetNum = this->ReadPackets(packetBuffer, sizeof(packetBuffer), packets, 64);
if(packetNum < 1) break;
for(int_r i=0; i<packetNum; i++)
{
JgPacketHead* head = (JgPacketHead*)packets[(int)i];
//cgl->m_gateChatC.Process(this, head);
if(m_shouldRemove) break;
}
}
if(m_shouldRemove)
{
cgl->m_vsocketManager.detach(this);
m_pGatewaySocket->setChatCnn(NULL);
Log(LOG_DEBUG, "debug: free %s", this->ToString().c_str());
this->Destroy();
}
}
示例8: StructuredDatabaseTest
int StructuredDatabaseTest()
{
Table* table;
int user_id;
DynArray<1024> what;
DynArray<1024> where;
table = new Table(&database, "structured_test");
table->Truncate();
user_id = InsertUser(table, "dopey", "dopeypass", "online");
InsertEvent(table, user_id, "dinner", "cheezburger", "2009-03-24 01:09:00");
InsertEvent(table, user_id, "meeting", "important", "2009-03-24 11:12:00");
// SELECT * FROM event WHERE user=%d AND date > 2009-03-24 01
what.Printf("event:user:%d", user_id);
where.Printf("date:2009-03-24 01");
//TableSelector selector(what.buffer, where.buffer);
// QuerySelector selector("SELECT date, note FROM event WHERE user_id=%d", user_id);
// table->Visit(selector);
ListTableVisitor visitor;
table->Visit(visitor);
return TEST_SUCCESS;
}
示例9: Set
bool Endpoint::Set(const char* ip_port, bool resolv)
{
const char* p;
int port;
bool ret;
DynArray<32> ipbuf;
p = ip_port;
while (*p != '\0' && *p != ':')
p++;
if (*p == '\0')
{
Log_Trace("No ':' in host specification");
return false;
}
ipbuf.Append(ip_port, p - ip_port);
ipbuf.Append("", 1);
p++;
port = -1;
port = atoi(p);
if (port < 1 || port > 65535)
{
Log_Trace("atoi() failed to produce a sensible value");
return false;
}
ret = Set(ipbuf.buffer, port, resolv);
return ret;
}
示例10: HELIUM_VERIFY
void SimpleSortedSetData< KeyT, CompareKeyT, AllocatorT >::Serialize( ArchiveT& archive )
{
DynArray< ObjectPtr > components;
components.Reserve( m_Data->GetSize() );
{
DataType::ConstIterator itr = m_Data->Begin();
DataType::ConstIterator end = m_Data->End();
for ( ; itr != end; ++itr )
{
ObjectPtr dataElem = Registry::GetInstance()->CreateInstance( Reflect::GetDataClass< KeyT >() );
// downcast to data type
Data* dataSer = AssertCast< Data >( dataElem );
// connect to our map data memory address
dataSer->ConnectData( const_cast< KeyT* >( &( *itr ) ) );
// serialize to the archive stream
HELIUM_VERIFY( components.New( dataSer ) );
}
}
archive.SerializeArray( components );
DynArray< ObjectPtr >::Iterator itr = components.Begin();
DynArray< ObjectPtr >::Iterator end = components.End();
for ( ; itr != end; ++itr )
{
Data* ser = AssertCast< Data >( *itr );
ser->Disconnect();
// might be useful to cache the data object here
}
}
示例11: TXT
void SimpleObjectSortedMapData< KeyT, CompareKeyT, AllocatorT >::Deserialize( ArchiveT& archive )
{
DynArray< ObjectPtr > components;
archive.DeserializeArray( components, ArchiveFlags::Sparse );
size_t componentCount = components.GetSize();
if ( componentCount % 2 != 0 )
{
throw Reflect::DataFormatException( TXT( "Unmatched map objects" ) );
}
// if we are referring to a real field, clear its contents
m_Data->Clear();
m_Data->Reserve( componentCount / 2 );
DynArray< ObjectPtr >::Iterator itr = components.Begin();
DynArray< ObjectPtr >::Iterator end = components.End();
while ( itr != end )
{
Data* key = SafeCast< Data >( *itr );
++itr;
Object* value = *itr;
++itr;
if ( key ) // The object value can be null, so don't check it here.
{
KeyT k;
Data::GetValue( key, k );
(*m_Data)[ k ] = value;
}
}
}
示例12: boot_run
void Boot::boot_run() const
{
DynArray<unsigned> boot;
buildBoot(boot,Range(&__std_boot_beg,&__std_boot_end));
__std_boot(boot.getPtr(),boot.getPtr()+boot.getLen());
}
示例13: HELIUM_ASSERT
/// Resolve a set of shader preprocessor options from the associated index.
///
/// @param[in] shaderType Type of shader.
/// @param[in] index Option set index.
/// @param[out] rToggleNames List of enabled shader toggles.
/// @param[out] rSelectPairs List shader selection pair values.
void Shader::Options::GetOptionSetFromIndex(
RShader::EType shaderType,
size_t index,
DynArray< Name >& rToggleNames,
DynArray< SelectPair >& rSelectPairs ) const
{
HELIUM_ASSERT( static_cast< size_t >( shaderType ) < static_cast< size_t >( RShader::TYPE_MAX ) );
rToggleNames.Resize( 0 );
rSelectPairs.Resize( 0 );
uint32_t shaderTypeMask = ( 1 << shaderType );
size_t shaderToggleCount = m_toggles.GetSize();
for( size_t shaderToggleIndex = 0; shaderToggleIndex < shaderToggleCount; ++shaderToggleIndex )
{
const Toggle& rShaderToggle = m_toggles[ shaderToggleIndex ];
if( !( rShaderToggle.shaderTypeFlags & shaderTypeMask ) )
{
continue;
}
if( index & 0x1 )
{
HELIUM_VERIFY( rToggleNames.New( rShaderToggle.name ) );
}
index >>= 1;
}
size_t shaderSelectCount = m_selects.GetSize();
for( size_t shaderSelectIndex = 0; shaderSelectIndex < shaderSelectCount; ++shaderSelectIndex )
{
const Select& rShaderSelect = m_selects[ shaderSelectIndex ];
if( !( rShaderSelect.shaderTypeFlags & shaderTypeMask ) )
{
continue;
}
const DynArray< Name >& rShaderSelectChoices = rShaderSelect.choices;
size_t shaderSelectChoiceCount = rShaderSelectChoices.GetSize();
size_t selectIndexMultiplier = shaderSelectChoiceCount + rShaderSelect.bOptional;
size_t selectIndex = index % selectIndexMultiplier;
index /= selectIndexMultiplier;
if( !rShaderSelect.bOptional || selectIndex != shaderSelectChoiceCount )
{
SelectPair* pSelectPair = rSelectPairs.New();
HELIUM_ASSERT( pSelectPair );
pSelectPair->name = rShaderSelect.name;
pSelectPair->choice = rShaderSelectChoices[ selectIndex ];
}
}
}
示例14: ReadCacheObjectFromBuffer
Reflect::ObjectPtr Helium::Cache::ReadCacheObjectFromBuffer( const DynArray< uint8_t > &_buffer )
{
if (_buffer.GetSize() == 0)
{
Reflect::ObjectPtr null_object;
return null_object;
}
return ReadCacheObjectFromBuffer(_buffer.GetData(), 0, _buffer.GetSize());
}
示例15: count
int count(const char* key){
DynArray<int> * a = valarray->get(keys->indexofVal(key));
int count = 0;
for(int i = 0; i<a->getLength();i++){
if(a->get(i) >= 0){
count++;
}
}
return count;
}