本文整理汇总了C++中TreeNode类的典型用法代码示例。如果您正苦于以下问题:C++ TreeNode类的具体用法?C++ TreeNode怎么用?C++ TreeNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TreeNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ACE_ERROR
void
Monitor::MonitorDataStorage::manageTransportLink(
TreeNode* node,
int transport_id,
bool& create
)
{
// Start by finding the participant node.
TreeNode* processNode = node->parent();
if( processNode) {
// And follow it to the actual process node.
processNode = processNode->parent();
} else {
// Horribly corrupt model, something oughta been done about it!
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: MonitorDataStorage::manageTransportLink() - ")
ACE_TEXT("unable to locate the ancestor process node!\n")
));
return;
}
// Then finds its key in the maps.
ProcessKey processKey;
std::pair< bool, ProcessKey> pResult
= this->findKey( this->processToTreeMap_, processNode);
if( pResult.first) {
processKey = pResult.second;
} else {
// Horribly corrupt model, something oughta been done about it!
ACE_ERROR((LM_ERROR,
ACE_TEXT("(%P|%t) ERROR: MonitorDataStorage::manageTransportLink() - ")
ACE_TEXT("unable to locate the process node in the maps!\n")
));
return;
}
// Now we have enough information to build a TransportKey and find or
// create a transport node for our Id value.
TransportKey transportKey(
processKey.host,
processKey.pid,
transport_id
);
TreeNode* transportNode = this->getTransportNode( transportKey, create);
if( !node) {
return;
}
// Transport Id display.
QString label( QObject::tr( "Transport"));
int row = node->indexOf( 0, label);
if( row == -1) {
// New entry, add a reference to the actual transport node.
QList<QVariant> list;
list << label << QString( QObject::tr("<error>"));;
TreeNode* idNode = new TreeNode( list, node);
idNode->setColor( 1, QColor("#bfbfff"));
node->append( idNode);
transportNode->addValueRef( idNode);
transportNode->setColor( 1, QColor("#bfffbf"));
create = true;
}
}
开发者ID:Fantasticer,项目名称:OpenDDS,代码行数:65,代码来源:MonitorDataStorage.cpp
示例2: TreeNode
// -----------------------------------------------------------------------------
TreeNode* bTree::TreeInsert(HTTPCSTR str, TreeNode *ParentItem) {
if (ParentItem == NULL) {
if (root == NULL) {
TreeNode *newnode = new TreeNode(str, NULL);
newnode->SetTreeNodeParentTree(this);
root = newnode;
count++;
return (root);
}
else {
TreeNode *y = NULL;
TreeNode *x = root;
while (x != NULL) {
if (_tcscmp(x->GetTreeNodeName(), str) == 0) {
/* already Exists */
return (x);
}
y = x;
if (_tcscmp(str, x->GetTreeNodeName()) < 0)
x = x->GetTreeNodeLeft();
else
x = x->GetTreeNodeRight();
}
/* str doesn't yet exist in tree - add it in */
TreeNode *newnode = new TreeNode(str, y);
newnode->SetTreeNodeParentTree(this);
if (_tcscmp(str, y->GetTreeNodeName()) < 0) {
y->SetTreeNodeLeft(newnode);
}
else {
y->SetTreeNodeRight(newnode);
}
this->count++; /* Add an additional element to the tree counter */
return (newnode);
}
}
else {
TreeNode*newnode = ParentItem->GetTreeNodeChildTree()->TreeInsert(str, NULL);
return (newnode);
}
}
开发者ID:rumjack,项目名称:fhscanhttplibrary,代码行数:44,代码来源:Tree.cpp
示例3: extent
void TreeDustGridStructure::setupSelfBefore()
{
GenDustGridStructure::setupSelfBefore();
Log* log = find<Log>();
// Validate attribute values
if (_xmax <= 0.0 || _ymax <= 0.0 || _zmax <= 0.0) throw FATALERROR("The maximum extent should be positive");
if (_minlevel < 0) throw FATALERROR("The minimum tree level should be at least 0");
if (_maxlevel < 2) throw FATALERROR("The maximum tree level should be at least 2");
if (_maxlevel <= _minlevel) throw FATALERROR("Maximum tree level should be larger than minimum tree level");
if (_Nrandom < 1) throw FATALERROR("Number of random samples must be at least 1");
if (_maxOpticalDepth < 0.0) throw FATALERROR("The maximum mean optical depth should be positive");
if (_maxMassFraction < 0.0) throw FATALERROR("The maximum mass fraction should be positive");
if (_maxDensDispFraction < 0.0) throw FATALERROR("The maximum density dispersion fraction should be positive");
// If no assigner was set, use an IdenticalAssigner as default (each process builds the entire tree)
if (!_assigner) setAssigner(new IdenticalAssigner(this));
// Cache some often used values
// A Parallel instance is created with a limited amount of threads (4) for performance reasons
_parallel = find<ParallelFactory>()->parallel(4);
_dd = find<DustDistribution>();
_dmib = _dd->interface<DustMassInBoxInterface>();
_useDmibForSubdivide = _dmib && !_maxDensDispFraction;
_totalmass = _dd->mass();
_eps = 1e-12 * extent().widths().norm();
// Create the root node
_tree.push_back(createRoot(extent()));
// Recursively subdivide the root node until all nodes satisfy the
// necessary criteria. When finished, set the number _Nnodes.
int currentlevel = -1;
unsigned int l = 0;
while (true)
{
TreeNode* node = _tree[l];
int level = node->level();
if (level>currentlevel)
{
log->info("Starting subdivision of level " + QString::number(level) + "...");
currentlevel = level;
}
if (l%50000 == 0)
log->info("Subdividing node number " + QString::number(l) + "...");
if (node->ynchildless())
subdivide(node);
l++;
if (l>=_tree.size()) break;
}
_Nnodes = _tree.size();
// Construction of a vector _idv that contains the node IDs of all
// leaves. This is the actual dust cell vector (only the leaves will
// eventually become valid dust cells). We also create a vector
// _cellnumberv with the cell numbers of all the nodes (i.e. the
// rank m of the node in the vector _idv if the node is a leaf, and
// -1 if the node is not a leaf).
int m = 0;
_cellnumberv.resize(_Nnodes,-1);
for (int l=0; l<_Nnodes; l++)
{
if (_tree[l]->ynchildless())
{
_idv.push_back(l);
_cellnumberv[l] = m;
m++;
}
}
_Ncells = _idv.size();
// Log the number of cells
log->info("Construction of the tree finished.");
log->info(" Total number of nodes: " + QString::number(_Nnodes));
log->info(" Total number of leaves: " + QString::number(_Ncells));
vector<int> countv(_maxlevel+1);
for (int m=0; m<_Ncells; m++)
{
TreeNode* node = _tree[_idv[m]];
int level = node->level();
countv[level]++;
}
log->info(" Number of leaf cells of each level:");
for (int level=0; level<=_maxlevel; level++)
log->info(" Level " + QString::number(level) + ": " + QString::number(countv[level]) + " cells");
// Determine the number of levels to be included in 3D grid output (if such output is requested)
if (writeGrid())
{
int cumulativeCells = 0;
for (_highestWriteLevel=0; _highestWriteLevel<=_maxlevel; _highestWriteLevel++)
{
cumulativeCells += countv[_highestWriteLevel];
if (cumulativeCells > 1500) break; // experimental number
//.........这里部分代码省略.........
开发者ID:DukhangLee,项目名称:SKIRT,代码行数:101,代码来源:TreeDustGridStructure.cpp
示例4: Node
void
Monitor::NodeGenerator::generate(TreeNode *t, QGraphicsScene *nodeScene, int w, int h, Node* parent)
{
static int xpos = 0;
static int ypos = 0;
if (t == 0) {
return;
}
Node *node = 0;
QString text;
if (isNodeValid(t, text)) {
xpos = w * 100;
ypos += 50;
node = new Node(text, xpos, ypos, t);
node->setParent(parent);
// populate tooltips with the children
TreeNode *c;
std::ostringstream ttip;
for (int i = 0; i < t->size(); ++i) {
c = t->operator[](i);
std::string k = c->column(0).toString().toLocal8Bit().constData();
std::string v = c->column(1).toString().toLocal8Bit().constData();
ttip << k << " : " << v << std::endl;
}
node->setToolTip(ttip.str().c_str());
// this takes ownership of the node so the nodeScene will
// cleanup all nodes when it's destroyed
// TODO: This make each nodes parent the nodeScene. change this
// so parent is the actual parent node using setParent()
nodeScene->addItem(node);
// connect us to our parent with a dashed line
// connect us to the parent
if (parent && !nodeOpt_.hideParentChild()) {
// give edge an actual parent so that z-order works
Edge *edge = new Edge(parent, node, false, parent);
nodeScene->addItem(edge);
parent->addEdge(edge);
node->addEdge(edge);
}
// store node
if (parent && !nodeOpt_.hidePubSub()) {
nMap_[t] = node;
}
}
// draw the child nodes
++w;
for (int i = 0; i < t->size(); ++i) {
generate(t->operator[](i), nodeScene, w, ++h, node);
}
}
开发者ID:AndroidDev77,项目名称:OpenDDS,代码行数:62,代码来源:NodeGenerator.cpp
示例5: PartialExpansion
bool RamAi::GameMonteCarloTree::NodeNeedsExpanding(const TreeNode &node) const
{
return (node.GetNumberOfChildren() < ConsoleSettings::GetSpecs().GetNumberOfInputCombinations()) && PartialExpansion(node);
}
开发者ID:ipidev,项目名称:RamAi,代码行数:4,代码来源:GameMonteCarloTree.cpp
示例6: debug_print
int QueryParser::parseIt(int sessionId, string query, TreeNode *&qTree, string &tcResultString, bool toBeTypeChecked, bool toBeOptimized) {
QueryParser::setStatEvalRun(0);
ErrorConsole &ec(ErrorConsole::get_instance(EC_QUERY_PARSER));
try{
qTree = parser->parse(query).release();
debug_print(ec, "Query not parsed properly...\n");
debug_print(ec, (ErrQParser | ENotParsed));
} catch (LoximException &ex) {
debug_print(ec, "Query parsed");
return (ErrQParser | ENotParsed);
}
Indexes::QueryOptimizer::optimizeWithIndexes(qTree);
//Nothing more needs to be done, if this is an internal query. (no screen logging, typechecking, optimization)
if (!toBeTypeChecked && !toBeOptimized) {
return 0;
}
if (Deb::ugOn()) {
cout << " Tree before optimization:";
cout << "\n--------------------------------------\n";
qTree->putToString();
cout << "\n--------------------------------------\n";
}
if ((shouldTypeCheck || shouldOptimize) && !qTree->skipPreprocessing()) {
TreeNode *nt = qTree->clone();
bool metadataCorrect = DataScheme::dScheme(sessionId)->getIsComplete();
bool metadataUpToDate = DataScheme::dScheme(sessionId)->getIsUpToDate();
if (!metadataCorrect || !metadataUpToDate) {
debug_print(ec, "Data scheme is not complete or not up to date); optimization and typechecking blocked.");
}
int typeCheckErrCode = 0;
if (shouldTypeCheck && toBeTypeChecked && metadataCorrect && metadataUpToDate) {
if (isTcOffTmp()) { debug_print(ec, "Typechecking turned off temporarily"); tcResultString = "";}
else {
Deb::ug(" \n \n TYPECHECK BEGIN !!! \n \n");
TypeChecker *tc = new TypeCheck::TypeChecker(nt);
typeCheckErrCode = tc->doTypeChecking(tcResultString);
Deb::ug(" \n \n TYPECHECK DONE... \n ");
if ((typeCheckErrCode != 0) && (typeCheckErrCode != (ErrTypeChecker | ETCNotApplicable))) {
debug_print(ec, "TC, Parser: typeCheckErrorCode says general TC error, should return string to user.\n");
return typeCheckErrCode;
}
if (typeCheckErrCode == 0) {
delete qTree;
qTree = nt;
}
}
} else {
if (shouldTypeCheck && toBeTypeChecked && dmlIncompleteAction == DML_AC_RETURN_ERROR) {
if (!metadataCorrect) return (ErrTypeChecker | EIncompleteMetadata);
else return (ErrTypeChecker | EMetadataOutdated);
}
tcResultString = "";
Deb::ug("TypeChecking is disabled.");
}
if (shouldOptimize && toBeOptimized && metadataCorrect && metadataUpToDate) {
Deb::ug(" optimisation is set ON !");
int optres = 0;
int stat_ev_res;
nt = qTree->clone();
if ((stat_ev_res = this->statEvaluate(sessionId, nt)) != 0) {
Deb::ug("static evaluation did not work out ...");
optres = -1;
} else {
int optres = -2;
DeathRmver *rmver = new DeathRmver(this);
rmver->rmvDeath(nt);
if (this->statEvaluate(sessionId, nt) != 0) optres = -1;
/* The main optimisation loop - factor out single independent subqueries *
* as long as ... such exist ! */
while (optres == -2) {
optres = nt->optimizeTree();
while (nt->getParent() != NULL) nt = nt->getParent();
/*one more static eval, to make sure nodes have the right info.. */
fprintf (stderr, "one more stat eval..\n");
if (this->statEvaluate(sessionId, nt) != 0) optres = -1;
}
AuxRmver *auxRmver = new AuxRmver(this);
auxRmver->rmvAux(nt);
JoinRpcer *joinRpcer = new JoinRpcer(this);
joinRpcer->replaceJoin(nt);
}
if (optres != -1) {
Deb::ug("I'll return optimized tree\n");
qTree = nt;
if (Deb::ugOn()) {
cout << "Tree after optimization:\n--------------------------------------\n";
qTree->putToString(); cout << "\n--------------------------------------\n";
}
} else { Deb::ug("I'll return the tree from before static eval..");}
} else {
if (shouldTypeCheck && toBeTypeChecked && dmlIncompleteAction == DML_AC_RETURN_ERROR) {
if (!metadataCorrect) return (ErrTypeChecker | EIncompleteMetadata);
else return (ErrTypeChecker | EMetadataOutdated);
}
//.........这里部分代码省略.........
开发者ID:ptryfon,项目名称:loxim-stats,代码行数:101,代码来源:QueryParser.cpp
示例7: main
int main () {
//create a binary tree first
TreeNode * a = new TreeNode ("A");
TreeNode * b = new TreeNode ("B");
TreeNode * c = new TreeNode ("C");
TreeNode * d = new TreeNode ("D");
TreeNode * e = new TreeNode ("E");
TreeNode * f = new TreeNode ("F");
TreeNode * g = new TreeNode ("G");
TreeNode * h = new TreeNode ("H");
TreeNode * i = new TreeNode ("I");
a->setRight(c);
a->setLeft(b);
b->setRight(d);
c->setRight(f);
c->setLeft(e);
e->setLeft(g);
f->setLeft(h);
f->setRight(i);
vector <string> result = preorderTraversal(a);
for(int i = 0; i < result.size(); i++ ) {
cout << result[i] << endl;
}
return 0;
}
开发者ID:Shuyang1996,项目名称:competitive_programing,代码行数:35,代码来源:preorder.cpp
示例8: QModelIndex
int model::DbContainerModel::rowCount(const QModelIndex& parent /*= QModelIndex()*/) const
{
TreeNode* node = Index2Node(parent);
// Check for root
return (node == nullptr) ? m_rootNodes.size() : node->GetChildrenCount();
}
开发者ID:ElwooD07,项目名称:BdContainer,代码行数:6,代码来源:DbContainerModel.cpp
示例9: extent
void ParticleTreeDustGridStructure::setupSelfBefore()
{
GenDustGridStructure::setupSelfBefore();
// Verify property values
if (_xmax <= 0.0 || _ymax <= 0.0 || _zmax <= 0.0) throw FATALERROR("The maximum extent should be positive");
// Cache some often used values
Log* log = find<Log>();
_eps = 1e-12 * extent().widths().norm();
DustDistribution* dd = find<DustDistribution>();
_dmib = dd->interface<DustMassInBoxInterface>();
DustParticleInterface* dpi = dd->interface<DustParticleInterface>();
if (!dpi) throw FATALERROR("Can't retrieve particle locations from this dust distribution");
int numParticles = dpi->numParticles();
log->info("Constructing tree for " + QString::number(numParticles) + " particles...");
// Create a list, used only during construction, that contains the index of the particle
// contained in each leaf node so far created, or -1 if the node is empty
// (the value is undefined for nonleaf nodes)
vector<int> particlev;
// Create the root node (which at this point is an empty leaf) using the requested type
switch (_treeType)
{
default:
case OctTree:
_tree.push_back(new OctTreeNode(0,0,extent()));
break;
case BinTree:
_tree.push_back(new BinTreeNode(0,0,extent()));
break;
}
particlev.push_back(-1);
int maxlevel = 0;
// Add particles one by one, subdividing if the leaf node containing the new particle
// already contains another particle
for (int i=0; i<numParticles; i++)
{
if (i%50000 == 0) log->info("Adding particle number " + QString::number(i) +
" (" + QString::number(i*100/numParticles) + "%)...");
int level = addParticleToNode(i, root(), dpi, particlev, _tree);
maxlevel = max(maxlevel, level);
}
// Perform additional subdivisions as requested
if (_extraLevels>0)
{
log->info("Performing additional subdivisions...");
maxlevel += _extraLevels;
for (int e=0; e<_extraLevels; e++)
{
int Nnodes = _tree.size();
for (int l=0; l<Nnodes; l++)
{
TreeNode* node = _tree[l];
if (node->ynchildless())
{
node->createchildren(_tree.size());
_tree.insert(_tree.end(), node->children().begin(), node->children().end());
}
}
}
}
// Construction of a vector _idv that contains the node IDs of all
// leaves. This is the actual dust cell vector (only the leaves will
// eventually become valid dust cells). We also create a vector
// _cellnumberv with the cell numbers of all the nodes (i.e. the
// rank m of the node in the vector _idv if the node is a leaf, and
// -1 if the node is not a leaf).
int Nnodes = _tree.size();
int m = 0;
_cellnumberv.resize(Nnodes,-1);
for (int l=0; l<Nnodes; l++)
{
if (_tree[l]->ynchildless())
{
_idv.push_back(l);
_cellnumberv[l] = m;
m++;
}
}
_Ncells = _idv.size();
// Log the number of cells
log->info("Construction of the tree finished.");
log->info(" Total number of nodes: " + QString::number(Nnodes));
log->info(" Total number of leaves: " + QString::number(_Ncells));
vector<int> countv(maxlevel+1);
for (int m=0; m<_Ncells; m++)
{
TreeNode* node = _tree[_idv[m]];
int level = node->level();
countv[level]++;
}
log->info(" Number of leaf cells of each level:");
for (int level=0; level<=maxlevel; level++)
log->info(" Level " + QString::number(level) + ": " + QString::number(countv[level]) + " cells");
//.........这里部分代码省略.........
开发者ID:DukhangLee,项目名称:SKIRT,代码行数:101,代码来源:ParticleTreeDustGridStructure.cpp
示例10: algorithm2
void algorithm2(int n, int m, int k, AdjacencyList &Graph, int** &Groups) {
Tree* T = new Tree;
Tree* C = NULL;
Tree* R_i = NULL;
Tree* current_path = NULL;
TreeNode* ptr = NULL;
int current_weight, i, j, current_t_i, t_i, real_weight;
long int d_i = 1000000000;
int group = 1000;
// Add vertex in Groups[0] to T
// and mark as reached
T->insert(Groups[0][2], 0);
Groups[0][0] = 1;
cout << "0\n";
while(1) {
// check if there is at least one group that is unreached
for(i = 0; i < k; i++) {
if (!Groups[i][0]) // if there is a group unreached
break;
}
if (i == k) // if i == k, then all groups are reached and we are done
break;
d_i = 1000000000;
t_i = 1;
group = 1000;
for(i = 0; i < k; i++) {
if (Groups[i][0] == 1)
continue;
// find a shortest path from vertex in g_i to vertex in T
for (j = 2; j < Groups[i][1] + 2; j++) {
// find a shortest path from vertex j in g_i to vertex in T
current_path = Dijkstra(n, Groups[i][j], T, Graph);
current_weight = current_path->get_last()->get_vertex_weight();
current_path->set_total_weight(current_weight);// path_into_tree sums them at the end!
current_t_i = num_groups_in_path(current_path, Groups, k);
// the number of "not reached" groups that current_path visits
// now comapre based off of d_i/t_i
if ((double)current_weight/current_t_i < (double)d_i/t_i) {
R_i = current_path;
d_i = current_weight;
t_i = current_t_i;
group = i;
} else if ((double)current_weight/current_t_i == (double)d_i/t_i) {
if (i < group) {
R_i = current_path;
d_i = current_weight;
t_i = current_t_i;
group = i;
} else if (i == group) { // if the distances AND groups are equal, lexicographic
if (!lexicographic(current_path, R_i)) {
R_i = current_path;
d_i = current_weight;
group = i;
}
}
}
}
}
// add R_i to T and mark group as reached
T->insert(R_i);
// create C - a collection of all the groups visited by path R_i that are not currently reached
C = groups_in_path(R_i, Groups, k);
// mark all the groups in C as marked
for (ptr = C->get_first(); ptr != NULL; ptr = ptr->get_next()) {
Groups[ptr->get_vertex_id()][0] = 1;
}
// create array from nodes in C, then sort the array
int* C_array = new int[C->get_tree_size()];
int* temp = new int[C->get_tree_size()];
int step = 0;
TreeNode* array_c;
for(array_c = C->get_first(); array_c != NULL; array_c = array_c->get_next()) {
C_array[step] = array_c->get_vertex_id();
step++;
}
merge_sort(C_array, temp, 0, C->get_tree_size()-1);
for (step = 0; step < C->get_tree_size(); step++) {
cout << C_array[step] << "\n";
}
delete[] C_array;
delete[] temp;
}
// print all vertices in T from smallest values to largest per line
// create array from nodes in T, then sort the array
// print sum of the weight of all the endges in T in one line
int* final_array = new int[T->get_tree_size()];
int* temp = new int[T->get_tree_size()];
int step = 0;
TreeNode* final_p;
//.........这里部分代码省略.........
开发者ID:emlittleworth,项目名称:cs130b_project1,代码行数:101,代码来源:algorithm2.cpp
示例11: main
int main(int argc, char *argv)
{
int i, j;
float data[10];
float currData[2];
#if 0
int socket;
/* Connect to MDSplus */
socket = MdsConnect (SERVER_ADDR);
if ( socket == -1 ) {
fprintf(stderr,"Error connecting to Atlas.\n");
return EXIT_FAILURE;
}
printf ("after MdsConnect\n");
#endif
try {
#if 0
Connection *conn = new Connection (SERVER_ADDR);
if (!conn) {
printf ("Connection failed \n");
}
printf ("after Connection\n");
#endif
/* Open pulse file, shot # */
Tree *t = new Tree(TREE_NAME, SHOT_NUM);
printf ("after Tree\n");
/* Get node */
TreeNode *node = t->getNode(TAG_NAME);
printf ("after getNode\n");
/* Make sure no data is contained */
// Segmentation fault => 3.0 library & header is ok
node->deleteData();
//float stime = -5;
float stime = -5;
Data *start = new Float64(10.);
Data *end = new Float64(11.);
Data *rate = new Float64(0.1);
Data *dimension = new Range(start, end, rate);
memset (data, 0x00, sizeof(data));
Array *dataArray = new Float32Array(data, 2);
for (i = 0; i < 5; i++) {
start = new Float64(stime + i);
end = new Float64(stime + 0.1 + i);
rate = new Float64(0.1);
dimension = new Range(start, end, rate);
node->beginSegment (start, end, dimension, dataArray);
for(j = 0; j < 2; j++) {
currData[j] = i+1;
}
printf ("[%02d] putSegment ... \n", i);
Array *subArr = new Float32Array(currData, 2);
node->putSegment (subArr, -1);
Event::setEvent (EVENT_NAME);
cout << "Data (" << node->getNumSegments() << ") : " << node->getData() << endl;
/* Free stuff */
//deleteData(start);
//deleteData(end);
//deleteData(rate);
deleteData(dimension);
delete(subArr);
sleep (2);
}
delete(t);
}
catch(MdsException *exc) {
cout << "Error appending segments: " << exc->what();
}
}
开发者ID:Sangil-Lee,项目名称:RefCode,代码行数:88,代码来源:mdsobjex.cpp
示例12: name
void
Monitor::MonitorDataStorage::displayNvp(
TreeNode* parent,
const OpenDDS::DCPS::NVPSeq& data,
bool layoutChanged,
bool dataChanged
)
{
// NAME / VALUE DATA
int size = data.length();
for( int index = 0; index < size; ++index) {
QString name( data[ index].name);
int row = parent->indexOf( 0, name);
if( row == -1) {
// This is new data, insert it.
QList<QVariant> list;
list << name;
switch( data[ index].value._d()) {
case OpenDDS::DCPS::INTEGER_TYPE:
list << QString::number( data[ index].value.integer_value());
break;
case OpenDDS::DCPS::DOUBLE_TYPE:
list << QString::number( data[ index].value.double_value());
break;
case OpenDDS::DCPS::STRING_TYPE:
list << QString( data[ index].value.string_value());
break;
case OpenDDS::DCPS::STATISTICS_TYPE:
case OpenDDS::DCPS::STRING_LIST_TYPE:
list << QString( QObject::tr("<display unimplemented>"));
break;
}
TreeNode* node = new TreeNode( list, parent);
parent->append( node);
layoutChanged = true;
} else {
// This is existing data, update the value.
TreeNode* node = (*parent)[ row];
switch( data[ index].value._d()) {
case OpenDDS::DCPS::INTEGER_TYPE:
node->setData( 1, QString::number( data[ index].value.integer_value()));
break;
case OpenDDS::DCPS::DOUBLE_TYPE:
node->setData( 1, QString::number( data[ index].value.double_value()));
break;
case OpenDDS::DCPS::STRING_TYPE:
node->setData( 1, QString( data[ index].value.string_value()));
break;
case OpenDDS::DCPS::STATISTICS_TYPE:
case OpenDDS::DCPS::STRING_LIST_TYPE:
break;
}
dataChanged = true;
}
}
// Notify the GUI if we have changed the underlying model.
if( layoutChanged) {
/// @TODO: Check that we really do not need to do updated here.
this->model_->changed();
} else if( dataChanged) {
this->model_->updated( parent, 1, (*parent)[ parent->size()-1], 1);
}
}
开发者ID:Fantasticer,项目名称:OpenDDS,代码行数:72,代码来源:MonitorDataStorage.cpp
示例13: nameLabel
void
Monitor::MonitorDataStorage::manageTopicLink(
TreeNode* node,
const OpenDDS::DCPS::GUID_t& dp_id,
const OpenDDS::DCPS::GUID_t& topic_id,
bool& create
)
{
// This gets a bit tedious. Here are the cases:
// 1) We currently have no reference, and found a Topic node to
// reference:
// - attach a reference to the topic node;
// 2) We currently have no reference, and found a Name node to
// reference:
// - attach a reference to the name node;
// 3) We currently have a Topic node referenced, and found the same
// topic node to reference:
// - nothing to do;
// 4) We currently have a Topic node referenced, and found a different
// Topic node to reference:
// - detach previous reference and reattach to new topic node;
// 5) We currently have a Topic node referenced, but were able to find
// a name node to reference:
// - detach previous reference and reattach to new name node;
// 6) We currently have a Name node referenced, and found the same name
// node to reference:
// - nothing to do;
// 7) We currently have a Name node referenced, and found a different
// name node to reference:
// - detach previous reference and reattach to new name node;
// 8) We currently have a Name node referenced, and found a different
// Topic node to reference:
// - detach previous reference and reattach to new topic node.
//
// Note that cases (4), (7), and (8) indicate inconsistent data reports
// and are error conditions. We chose to not handle these cases.
// Cases (3) and (6) require no action, so the only code paths we need
// to consider are for cases (1), (2), and (5).
// Find the actual topic.
TreeNode* topicNode = this->getNode(
std::string( "Topic"),
dp_id,
topic_id,
create
);
if( !topicNode) {
return;
}
// Find the topic name to reference instead of the GUID value.
TreeNode* nameNode = 0;
QString nameLabel( QObject::tr( "Topic Name"));
int row = topicNode->indexOf( 0, nameLabel);
if( row != -1) {
nameNode = (*topicNode)[ row];
}
// Check for an existing Topic entry.
QString topicLabel( QObject::tr( "Topic"));
int topicRow = node->indexOf( 0, topicLabel);
if( nameNode && topicRow != -1) {
// Case 5: We have a topic reference and found a name reference,
// remove the existing topic reference
TreeNode* topicRef = (*node)[ topicRow];
if( topicRef && topicRef->valueSource()) {
topicRef->valueSource()->removeValueRef( topicRef);
}
// node->removeChildren( topicRow, 1); // DEVELOPMENT: don't delete to show stale data.
}
// The node to install.
TreeNode* refNode = nameNode;
if( !refNode) {
refNode = topicNode;
}
// Check to see if we need to create a name entry.
int nameRow = node->indexOf( 0, nameLabel);
if( nameRow == -1) {
// New entry, add a reference to the topic or its name.
QList<QVariant> list;
list << topicLabel << QString( QObject::tr("<error>"));
TreeNode* idNode = new TreeNode( list, node);
idNode->setColor( 1, QColor("#bfbfff"));
node->append( idNode);
refNode->addValueRef( idNode);
refNode->setColor( 1, QColor("#bfffbf"));
create = true;
}
}
开发者ID:Fantasticer,项目名称:OpenDDS,代码行数:91,代码来源:MonitorDataStorage.cpp
示例14: SetSelected
void TreeNode::iterate(int action, int* curIndex, int* targetIndex)
{
Gwen::String name = Gwen::Utility::UnicodeToString(m_Title->GetText());
// int actualIndex = curIndex? *curIndex : -1;
//printf("iterated over item %d with name = %s\n", actualIndex, name.c_str());
if (action==ITERATE_ACTION_SELECT)
{
if (curIndex && targetIndex)
{
if ((*curIndex)==(*targetIndex))
{
SetSelected(true);
*targetIndex=-1;
}
}
}
if (IsSelected())
{
//printf("current selected: name = %s\n", name.c_str());
switch (action)
{
case ITERATE_ACTION_DESELECT_INDEX:
{
if (targetIndex && curIndex)
{
if (*targetIndex == *curIndex)
SetSelected(false);
}
break;
}
case ITERATE_ACTION_FIND_SELECTED_INDEX:
{
if (targetIndex && curIndex)
{
*targetIndex = *curIndex;
}
break;
}
case ITERATE_ACTION_OPEN:
{
Open();
break;
}
case ITERATE_ACTION_CLOSE:
{
//either close or select parent
if (this->GetChildren().size())
{
if (m_ToggleButton && m_ToggleButton->GetToggleState())
{
Close();
} else
{
TreeNode* pChild = (GetParent())->DynamicCastTreeNode();
TreeControl* pChild2 = (GetParent())->DynamicCastTreeControl();
if (pChild && !pChild2)
{
SetSelected(false);
pChild->SetSelected(true);
}
}
}
else
{
TreeNode* pChild = (GetParent())->DynamicCastTreeNode();
TreeControl* pChild2 = (GetParent())->DynamicCastTreeControl();
if (pChild && !pChild2)
{
SetSelected(false);
pChild->SetSelected(true);
}
}
break;
}
default:
{
}
};
}
if (curIndex)
(*curIndex)++;
bool needsRecursion = true;
if (action == ITERATE_ACTION_FIND_SELECTED_INDEX || action==ITERATE_ACTION_SELECT || action==ITERATE_ACTION_DESELECT_INDEX)
{
if (m_ToggleButton && !m_ToggleButton->GetToggleState())
{
needsRecursion=false;
//.........这里部分代码省略.........
开发者ID:Aatch,项目名称:bullet3,代码行数:101,代码来源:TreeNode.cpp
示例15: read_this
Tree<_DATA>& Tree<_DATA>::
read_this(const char* dir) {
char path[SIZEOF_PATH], * filename, line_str[SIZEOF_PATH], * filename_str;
std::strcpy(path, dir);
std::size_t dir_len = std::strlen(path);
std::size_t file_len;
if (dir_len > 0 && (path[dir_len - 1] != '/' && path[dir_len - 1] != '\\'))
path[dir_len++] = '/';
filename = path + dir_len;
file_len = SIZEOF_PATH - dir_len;
std::strcpy(filename, "Tree");
std::ifstream file(path);
if (!file.is_open()) {
std::cerr << "\nFailed opening file: " << path << std::endl;
return *this;
}
while(file.getline(line_str, SIZEOF_LINE) && !line_str[0]);
if (!line_str[0]) {
std::cerr << "\nFailed finding file for root." << std::endl;
return *this;
}
file.close();
filename_str = strtostr(line_str);
std::strcpy(filename, filename_str);
file.open(path);
if (!file.is_open()) {
std::cerr << "\nFailed opening file: " << path << std::endl;
return *this;
}
unsigned long node_num;
_DATA* data;
std::queue<unsigned long> node_name;
std::queue<TreeNode*> node_parent_pointer;
file.getline(line_str, SIZEOF_LINE);
file.getline(line_str, SIZEOF_LINE);
file.getline(line_str, SIZEOF_LINE);
unsigned int n_child = strto<unsigned int>(line_str, 10);
root_ = new TreeNode(NULL, NULL, n_child);
for (unsigned int i = 0; i < n_child; ++i) {
file.getline(line_str, SIZEOF_LINE);
node_num = strto<unsigned long>(line_str, 10);
node_name.push(node_num);
node_parent_pointer.push(root_);
}
data = new _DATA();
file >> *data;
file.close();
root_->pcontent(data);
while (!node_name.empty()) {
unsigned long name = node_name.front();
TreeNode* parent = node_parent_pointer.front();
std::snprintf(filename, file_len, "%016lu.node", name);
file.open(path);
if (!file.is_open()) {
std::cerr << "\nFailed opening file: " << path << std::endl;
node_name.pop();
node_parent_pointer.pop();
continue;
}
file.getline(line_str, SIZEOF_LINE);
file.getline(line_str, SIZEOF_LINE);
file.getline(line_str, SIZEOF_LINE);
unsigned int n_child = strto<unsigned int>(line_str, 10);
TreeNode* node = new TreeNode(NULL, parent, n_child);
parent->attach_child(node);
for (unsigned int i = 0; i < n_child; ++i) {
file.getline(line_str, SIZEOF_LINE);
node_num = strto<unsigned long>(line_str, 10);
node_name.push(node_num);
node_parent_pointer.push(node);
}
data = new _DATA();
file >> *data;
file.close();
node->pcontent(data);
node_name.pop();
node_parent_pointer.pop();
}
return *this;
}
开发者ID:Raychee,项目名称:SoftLabelForest,代码行数:80,代码来源:Tree.hpp
示例16: switch
TreeNode* Parser::Factor()
{
TreeNode* node;
Token rememberedToken = currentToken;
switch (currentToken.type)
{
case tokBraceOpen:
matchToken(tokBraceOpen);
node = Expression();
matchToken(tokBraceClose);
break;
case tokUnknown:
node = getId();
if (learnedFunctionList.contains(rememberedToken.look) > 0) // is function call
{
delete node;
node = FunctionCall(rememberedToken);
node->setType(funcReturnNode); // expect returned value on stack
}
break;
case tokString:
node = new TreeNode(currentToken, constantNode);
{ // extra scope to localize the QString 'str'
QString str = currentToken.look;
if ( currentToken.look.endsWith("\"") )
{
// cut off the quotes and store the value
str.remove(0, 1).truncate( currentToken.look.length() - 2 );
}
else // problems but we need to keep it moving
{
str.remove(0, 1); // cut off the first quote only
Error(currentToken, i18n("String text not properly delimited with a ' \" ' (double quote)"), 1060);
}
node->setValue(str);
}
matchToken(tokString);
break;
case tokNumber:
node = new TreeNode(currentToken, constantNode);
node->setValue(currentToken.value);
matchToken(tokNumber);
break;
case tokRun:
node = ExternalRun();
break;
case tokInputWindow:
node = InputWindow();
break;
case tokRandom:
node = Random();
break;
case tokEOL:
node = new TreeNode(currentToken, Unknown);
break;
default:
QString s = currentToken.look;
if ( s.isEmpty() || currentToken.type == tokEOF )
{
Error(currentToken, i18n("INTERNAL ERROR NR %1: please sent this Logo script to KTurtle developers").arg(1), 1020);
// if this error occurs the see the Parser::Repeat for the good solution using 'preservedToken'
}
else
{
Error(currentToken, i18n("Cannot understand '%1', expected an expression after the '%2' command").arg(s).arg(preservedToken.look), 1020);
}
node = new TreeNode(currentToken, Unknown);
getToken();
break;
}
return node;
}
开发者ID:,项目名称:,代码行数:80,代码来源:
示例17: TreePath
void AVLTree::Delete(TreeNode * &node, int x, QAnimationGroup *group)
{
if (node == NULL)
return;
if (group&& node->parent)
group->addAnimation(node->parent->getTurnRedAnim());
TreePath *path;
if (group && node->parent)
{
path = new TreePath(node->parent, node, view);
group->addAnimation(path->getToSonAnim());
}
TreeNode* parent = node->parent;
if (x < node->data)
{
//如果x小于节点的值,就继续在节点的左子树中删除x
Delete(node->Lson, x, group);
if (group && node->parent)
group->addAnimation(path->getToParentAnim());
if (2 == height(node->Rson) - height(node->Lson))
{
if (node->Rson->Lson != NULL &&
(height(node->Rson->Lson)>height(node->Rson->Rson)))
RL(node, group);
else
RR(node, group);
}
}
else if (x > node->data)
{
Delete(node->Rson, x, group);//如果x大于节点的值,就继续在节点的右子树中删除x
if (group && node->parent)
group->addAnimation(path->getToParentAnim());
if (2 == height(node->Lson) - height(node->Rson))
{
if (node->Lson->Rson != NULL &&
(height(node->Lson->Rson)>height(node->Lson->Lson)))
LR(node, group);
else
LL(node, group);
}
}
else//如果相等,此节点就是要删除的节点
{
if (group)
group->addAnimation(node->getPopAnim());
else
node->getPopAnim()->start(QAbstractAnimation::DeleteWhenStopped);
if (node->Lson && node->Rson)//此节点有两个儿子
|
请发表评论