本文整理汇总了C++中DynamicArray::size方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicArray::size方法的具体用法?C++ DynamicArray::size怎么用?C++ DynamicArray::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicArray
的用法示例。
在下文中一共展示了DynamicArray::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: call
RealType UserFunction::call(const Context& context, const DynamicArray<RealType>& args) const
{
if (args.size() != m_parameters.size())
throw InvalidArgumentException("Function `" + m_name + "` called with different number of arguments");
Map<String, RealType> arguments;
// Merge names and values
for (int i = 0; i < args.size(); ++i)
arguments.emplace(m_parameters[i], args[i]);
CECE_ASSERT(m_body);
return m_body->eval(Context(context.simulation, context.diffusion, context.cell, context.coords, &arguments));
}
示例2: storeImage
void storeImage(const FilePath& filename, DynamicArray<unsigned char> data,
unsigned int width, unsigned int height)
{
constexpr int CHANNEL_COUNT = 3;
OutFileStream file(filename.c_str(), OutFileStream::binary);
if (!file.is_open())
throw InvalidArgumentException("Cannot open output file: " + filename.toString());
// Image is vertically flipped
DynamicArray<unsigned char> data_flip(data.size());
const unsigned int line_size = width * CHANNEL_COUNT;
// Vertically flip lines
for (unsigned int i = 0; i < height; ++i)
{
std::memcpy(
data_flip.data() + i * line_size,
data.data() + (height - i - 1) * line_size,
line_size
);
}
// Write function
stbi_write_func* func = [] (void* context, void* data, int size) {
reinterpret_cast<OutFileStream*>(context)->write(reinterpret_cast<const char*>(data), size);
};
// Copy data
if (!stbi_write_png_to_func(func, &file, width, height, CHANNEL_COUNT, data_flip.data(), 0))
throw RuntimeException("Unable to write a picture");
}
示例3: findComponent
template<typename T> T* findComponent() {
for (uint32 i = 0; i < components.size(); i++) {
Component* ptr = components[i];
if (dynamic_cast<T*>(ptr)) return (T*)ptr;
}
return (T*)NULL;
}
示例4: map
TEST( Map, Iterator )
{
using namespace nge::cntr;
using namespace nge::mem;
using namespace nge;
DefaultAllocator<String> alloc;
CountingAllocator<Map<String, String>::Pair> pairAlloc;
CountingAllocator<uint32> binAlloc;
Map<String, String> map( &pairAlloc, &binAlloc );
DynamicArray<String> keys = getKeys( &alloc );
uint32 i;
for ( i = 0; i < keys.size(); ++i )
{
map[keys[i]] = keys[i];
}
for ( auto iter = map.cbegin(); iter != map.cend(); ++iter )
{
ASSERT_STREQ( iter->key.c_str(), iter->value.c_str() );
}
auto iter = map.cbegin();
for ( i = 0; i < map.size(); ++i, ++iter )
{
ASSERT_STREQ( keys[i].c_str(), iter->key.c_str() );
ASSERT_STREQ( keys[i].c_str(), iter->value.c_str() );
}
}
示例5: getComponentNames
int getComponentNames (ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char **argv){
// getComponentNames stateIdx trajectoryIdx
if( argc != 3 ) return TCL_ERROR;
ControllerEditor* obj = (ControllerEditor*)clientData;
int idx = atoi( argv[1] );
SimBiConState* state = obj->getFramework()->getController()->getState( idx );
if( !state ) return TCL_ERROR;
idx = atoi( argv[2] );
Trajectory* trajectory = state->getTrajectory( idx );
if( !trajectory ) return TCL_ERROR;
DynamicArray<const char*> componentNames;
for( uint i = 0; i < trajectory->components.size(); ++i ) {
char* componentName = new char[ 32 ];
sprintf( componentName, "Component %d", i );
componentNames.push_back( componentName );
}
char* result = stringListToTclList( componentNames );
for( uint i = 0; i < componentNames.size(); ++i )
delete[] componentNames[i];
Tcl_SetResult(interp, result, TCL_DYNAMIC);
return TCL_OK;
}
示例6: updateJointOrdering
/**
HACK!
*/
void Character::updateJointOrdering(){
if( jointOrder.size() == joints.size() )
return; // HACK assume ordering is ok
jointOrder.clear();
if (!root)
return;
DynamicArray<ArticulatedRigidBody*> bodies;
bodies.push_back(root);
int currentBody = 0;
while ((uint)currentBody<bodies.size()){
//add all the children joints to the list
for (int i=0;i<bodies[currentBody]->getChildJointCount();i++){
Joint *j = bodies[currentBody]->getChildJoint(i);
jointOrder.push_back( getJointIndex(j->getName()) );
bodies.push_back(bodies[currentBody]->getChildJoint(i)->getChild());
}
currentBody++;
}
reverseJointOrder.resize( jointOrder.size() );
for( uint i=0; i < jointOrder.size(); ++i )
reverseJointOrder[jointOrder[i]] = i;
}
示例7:
DiscreteDisGenerator<T>::DiscreteDisGenerator(DynamicArray<T> discrete_data,
DynamicArray<float> distribution,
UniformGenerator<float>* uniform_generator)
{
//construct discrete distribution
m_discrete_data = discrete_data;
m_discrete_num = discrete_data.size();
m_cumulative_dis = DynamicArray<float>(distribution.size() + 1);
m_cumulative_dis[0] = 0.0f;
int size = m_cumulative_dis.size();
for (int i = 1; i < size; ++i)
{
m_cumulative_dis[i] = m_cumulative_dis[i - 1] + distribution[i - 1];
}
m_uniform_generator = uniform_generator;
}
示例8: write
bool EagleeyeIO::write(const DynamicArray<T>& arr,std::string id,std::string file_path,EagleeyeIOMode iomode)
{
switch(iomode)
{
case WRITE_BINARY_MODE:
{
std::ofstream binary_file(file_path.c_str(),std::ios::binary);
if (!binary_file)
{
return false;
}
else
{
//write id
int str_len=id.length();
binary_file.write((char*)(&str_len),sizeof(int));
binary_file.write(id.c_str(),sizeof(char)*str_len);
//write array data
int arr_size=arr.size();
binary_file.write((char*)(&arr_size),sizeof(int));
binary_file.write((char*)arr.dataptr(),sizeof(T)*arr_size);
binary_file.close();
return true;
}
}
case WRITE_ASCII_MODE:
{
std::locale::global( std::locale( "",std::locale::all^std::locale::numeric ) );
std::ofstream asc_file(file_path.c_str());
if (asc_file)
{
asc_file<<id<<'\n';
asc_file<<arr;
asc_file.close();
return true;
}
return false;
}
default:
{
return false;
}
}
return false;
}
示例9: read
bool EagleeyeIO::read(DynamicArray<T>& arr,std::string& id,std::string file_path,EagleeyeIOMode iomode)
{
switch(iomode)
{
case READ_BINARY_MODE:
{
std::ifstream binary_file(file_path.c_str(),std::ios::binary);
if (!binary_file)
{
return false;
}
else
{
//write id
int str_len;
binary_file.read((char*)(&str_len),sizeof(int));
char* id_data=new char[str_len];
binary_file.read(id_data,sizeof(char)*str_len);
id=std::string(id_data);
delete[] id_data;
//write array data
int arr_size=arr.size();
binary_file.read((char*)(&arr_size),sizeof(int));
arr=DynamicArray(arr_size);
binary_file.read((char*)(arr.dataptr()),sizeof(T)*arr_size);
binary_file.close();
return true;
}
}
case READ_ASCII_MODE:
{
std::locale::global( std::locale( "",std::locale::all^std::locale::numeric ) );
std::ifstream ascii_file(file_path.c_str());
file_path>>id;
file_path>>arr;
ascii_file.close();
return false;
}
default:
{
return false;
}
}
return false;
}
示例10:
NODE_IMPLEMENTATION(IStreamType::readBytes, int)
{
IStream* stream = NODE_ARG_OBJECT(0, IStream);
DynamicArray* array = NODE_ARG_OBJECT(1, DynamicArray);
size_t n = NODE_ARG(2, int);
size_t size = array->size(); // we know its bytes
array->resize(size + n);
size_t nread = 0;
#if COMPILER == GCC2_95
stream->_istream->read(array->data<char>() + size, n);
nread = n; // bogus return value here when using 2.95!
#else
nread = stream->_istream->readsome(array->data<char>() + size, n);
#endif
array->resize(size + nread);
NODE_RETURN(nread);
}
示例11: draw
/**
* This method is called whenever the window gets redrawn.
*/
void ControllerEditor::draw(bool shadowMode){
int flags = SHOW_MESH;
//if we are drawing shadows, we don't need to enable textures or lighting, since we only want the projection anyway
if (shadowMode == false){
flags |= SHOW_COLOURS;
glEnable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
if (Globals::drawCollisionPrimitives)
flags |= SHOW_CD_PRIMITIVES | SHOW_FRICTION_PARTICLES;
if (Globals::drawJoints){
flags |= SHOW_JOINTS | SHOW_BODY_FRAME;
}
if (Globals::drawContactForces){
//figure out if we should draw the contacts, desired pose, etc.
glColor3d(1, 0, 0);
DynamicArray<ContactPoint>* cfs = conF->getWorld()->getContactForces();
for (uint i=0;i<cfs->size();i++){
ContactPoint *c = &((*cfs)[i]);
GLUtils::drawCylinder(0.01, c->f * 0.09, c->cp);
GLUtils::drawCone(0.03, c->f * 0.01, c->cp+c->f*0.09);
}
}
}
else{
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
}
if (conF == NULL)
return;
AbstractRBEngine* rbc = conF->getWorld();
if (rbc)
rbc->drawRBs(flags);
if (shadowMode == false){
//draw the pose if desirable...
if (Globals::drawDesiredPose && conF && conF->getWorld())
drawDesiredTarget();
}
}
示例12: async_send
void UDPServer::async_send(boost::asio::ip::udp::endpoint& ep, DynamicArray<char>& arr) {
this->getUDPSocket().async_send_to(boost::asio::buffer(arr.data(), arr.size()), ep,
std::bind(&UDPServer::handle_write, this, ep, arr, std::placeholders::_1, std::placeholders::_2));
}
示例13: main
int main()
{
// print my name and this assignment's title
cout << "Lab 5a, The \"Applying A Data Structure To A Big Data Application\" Program \n";
cout << "Programmer: Licong Wang\n";
cout << "Editor(s) used: Visual studio 2013\n";
cout << "Compiler(s) used: Microsoft c++ complier\n";
cout << "File: " << __FILE__ << endl;
cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
// for parsing the inputfile
char* token;
char buf[1000];
const char* const tab = "\t";
clock_t startTime = clock();
// open the input file
ifstream fin;
fin.open("dvc-schedule.txt");
if (!fin.good()) throw "I/O error";
int n = 0;
int dup = 0;
bool duplicate;
bool stored;
DynamicArray <Info> courseInfo(70000);
DynamicArray <Class> subjects;
// read the input file
while (fin.good())
{
// set the check to false
duplicate = false;
stored = false;
if (++n % 1000 == 0)
{
cout << '.';
cout.flush();
}
// read the line
string line;
getline(fin, line);
strcpy(buf, line.c_str());
if (buf[0] == 0) continue;
// parse the line
const string term(token = strtok(buf, tab));
const string section(token = strtok(0, tab));
const string course((token = strtok(0, tab)) ? token : "");
const string instructor((token = strtok(0, tab)) ? token : "");
const string whenWhere((token = strtok(0, tab)) ? token : "");
if (course.find('-') == string::npos) continue; // invalid line
const string subjectCode(course.begin(), course.begin() + course.find('-'));
// check duplicate, continue if does
for (int i = 0; i < courseInfo.size(); i++)
{
if (term == courseInfo[i].term && section == courseInfo[i].section)
{
dup++;
duplicate = true;
break;
}
}
if (duplicate == true)
continue;
Info newInfo;
newInfo.term = term;
newInfo.section = section;
courseInfo[courseInfo.size()] = newInfo;
// check already stored
for (int i = 0; i < subjects.size(); i++)
{
if (subjects[i].subjectCode == subjectCode)
{
subjects[i].count++;
stored = true;
break;
}
}
if (stored == true)
continue;
Class y;
y.subjectCode = subjectCode;
y.count = 1;
subjects[subjects.size()] = y;
}
cout << endl;
fin.close();
//.........这里部分代码省略.........
示例14: getNumComponents
unsigned getNumComponents() const { return components.size(); }
示例15: getNumChildren
unsigned getNumChildren() const { return children.size(); }