示例#1
0
/**
	Copy for duplicating a branch
*/
void copy_branch(tree<AstNode>::iterator where, tree<AstNode>::iterator from,  tree<AstNode>& tr_where)
{
	if (tr_where.number_of_children(from) == 0) {
		// simply add the node to it
		tr_where.append_child(where, *from);
	}
	else {
		where = tr_where.append_child(where, *from);
		tree<AstNode>::sibling_iterator cter;
		for (cter = tr_where.begin(from); cter != tr_where.end(from); ++cter) {
			copy_branch(where, cter, tr_where);
		}
	}
}
示例#2
0
void treeFromJava(JNIEnv * env, const jobject & jnode, tree<J_NVItem>::iterator_base & it, const JMultiTreeNode & fields, tree<J_NVItem> & tre)
{
//	LOGI("Enter %s %p\n",__FUNCTION__, &it);
	//转换当前节点
	fields.java2Cpp(env, jnode, *it);	
	
	//处理子节点
	jobject childList = env->GetObjectField(jnode, fields.m_Childs_id);
	jclass clsArrayList = env->FindClass(JCLSNAME_ArrayList);
	jmethodID sizeList_mid = env->GetMethodID(clsArrayList, "size", "()I");

	jmethodID getList_mid = env->GetMethodID(clsArrayList, "get", "(I)Ljava/lang/Object;");

	int childCount = env->CallIntMethod(childList, sizeList_mid);
	J_NVItem item;
	for(int i = 0; i < childCount; i++)
	{
		jobject jchild = env->CallObjectMethod(childList, getList_mid, i);	

		tree<J_NVItem>::iterator_base itchild = tre.append_child(it, item);
		treeFromJava(env, jchild, itchild, fields, tre);

		env->DeleteLocalRef(jchild);
	}

//	LOGI("Leave %s %p\n",__FUNCTION__, &it);
}
示例#3
0
FILE_ITEM CFileTree::AddItem(char *absolutePath, unsigned char* handle)
{
	FILE_ITEM item;
	item.handle = handle;
	item.bCached = false;

	if (filesTree.empty()) {
		item.path = new char[strlen(absolutePath) + 1];
		strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
		item.nPathLen = strlen(item.path);

		filesTree.set_head(item);
		topNode = filesTree.begin();
	}
	else {
		std::string sPath(absolutePath);
		tree_node_<FILE_ITEM>* parentNode = findParentNodeFromRootForPath(absolutePath);
		std::string splittedPath = sPath.substr(sPath.find_last_of('\\') + 1);
		item.path = new char[splittedPath.length() + 1];
		strcpy_s(item.path, (splittedPath.length() + 1), splittedPath.c_str());
		if (parentNode) {
			filesTree.append_child(tree<FILE_ITEM>::iterator_base(parentNode), item);
		} else {
			//printf("Parent node found for %s", absolutePath);
		}
	}

	DisplayTree(topNode.node, 0);

	return item;
}
示例#4
0
    void WeaveNet(SQcont<T> const &incont, tree<T> &outnet)
    {
      outnet.clear();
      auto top(outnet.begin());
      auto now(outnet.insert(top, *incont.cbegin()));
      for(auto c = incont.cbegin()+1;c != incont.cend();++c)
	now = outnet.append_child(now, *c);
    }
示例#5
0
    void WeaveNets(SQcont<SQcont<T> > &incont, tree<T> &outnet)
    {
      outnet.clear();
      auto top(outnet.begin());
      for(auto c = incont.begin();c != incont.end();++c){
	if(c->size()){
	  auto now(outnet.insert(top, c->at(0)));
	  for(size_t num = 1;num < c->size();++num)
	    now = outnet.append_child(now, c->at(num));
	} // End if
      } // End c
    }
示例#6
0
/**
	Insert a new statement.
	- Create a new inner_statement_list
	- Add the statement under it
*/
bool insert_statement(const tree<AstNode>::iterator& where, const tree<AstNode>::iterator& what, tree<AstNode>& tr)
{
	if (where->getType() == "text" && where->getValue() == "$enter_the_new_statement") {
		// rewind to the inner_statement_list
		tree<AstNode>::iterator top = where;
		do {
			top = tr.parent(top);
		} while (top->getType() != "inner_statement" && tr.child(top,0)->getType() != "statement");
		top = tr.parent(top);
		if (top->getType() != "inner_statement_list")
			return false;
		else {
			top = tr.append_child(top, AstNode("inner_statement_list"));
			top = tr.append_child(top, AstNode("inner_statement"));
			if (what->getType() == "statement") {
				top = tr.append_child(top, AstNode("statement"));
				//cout << "Seems to be okay..." << endl;
				move_branch(top, what, tr);
			}
		}
		return true;
	}
	return false;
}
示例#7
0
FILE_ITEM CFileTree::AddItem(char *absolutePath, unsigned char* handle)
{
	FILE_ITEM item;
	item.handle = handle;
	item.bCached = false;

	// If the tree is empty just add the new path as node on the top level.
	if (filesTree.empty()) {
		item.path = new char[strlen(absolutePath) + 1];
		strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
		item.nPathLen = strlen(item.path);

		filesTree.set_head(item);
		topNode = filesTree.begin();
	}
	else {
		// Check if the requested path belongs to an already registered parent node.
		std::string sPath(absolutePath);
		tree_node_<FILE_ITEM>* parentNode = findParentNodeFromRootForPath(absolutePath);
		std::string splittedPath = _basename_932(sPath);
		//printf("spl %s %s\n", splittedPath.c_str(), absolutePath);
		item.path = new char[splittedPath.length() + 1];
		strcpy_s(item.path, (splittedPath.length() + 1), splittedPath.c_str());
		// If a parent was found use th parent.
		if (parentNode) {
			//printf("parent %s\n", parentNode->data.path);
			filesTree.append_child(tree<FILE_ITEM>::iterator_base(parentNode), item);
		} else {
			// Node wasn't found - most likely a new root - add it to the top level.
			//printf("No parent node found for %s. Adding new sibbling.", absolutePath);
			item.path = new char[strlen(absolutePath) + 1];
			strcpy_s(item.path, (strlen(absolutePath) + 1), absolutePath);
			item.nPathLen = strlen(item.path);
			
			filesTree.insert(tree<FILE_ITEM>::iterator_base(topNode), item);
			topNode = filesTree.begin();
		}
	}

	DisplayTree(topNode.node, 0);

	return item;
}
示例#8
0
void CFileTree::RenameItem(char *absolutePathFrom, char *absolutePathTo)
{
	tree_node_<FILE_ITEM>* node = findNodeFromRootWithPath(absolutePathFrom);
	tree_node_<FILE_ITEM>* parentNode = findParentNodeFromRootForPath(absolutePathTo);

	if (parentNode != NULL && node != NULL) {
		if (filesTree.number_of_children(parentNode) < 1) {
			FILE_ITEM emptyItem;
			emptyItem.nPathLen = 0;
			emptyItem.path = const_cast<char*>("");
			filesTree.append_child(tree<FILE_ITEM>::iterator_base(parentNode), emptyItem);
		}
		tree<FILE_ITEM>::iterator firstChild = filesTree.begin(parentNode);
		filesTree.move_after(firstChild, tree<FILE_ITEM>::iterator(node));

		std::string sPath(absolutePathTo);
		std::string splittedPath = sPath.substr(sPath.find_last_of('\\') + 1);
		node->data.path = new char[splittedPath.length() + 1];
		strcpy_s(node->data.path, (splittedPath.length() + 1), splittedPath.c_str());

	}
	DisplayTree(topNode.node, 0);
}
示例#9
0
/**
* This is the method for retrieving data from a file. The whole
* tree will be written to the new file immediately after being
* called. Interpreting the string is made by command_parser method.
*/
void EdfRetriever::getData(const string &location, tree<Node> &tr){

    char key[256];//variable for holding variable name
    int label_case = command_parser(location, key);//parse location, and check for case with label
    //
    //case for single label  
    //
    if(label_case==1){
        double double_value;    
        string string_value;
        int dims[1]={0};
        edf_reader Edf = edf_reader(infile);//parse edf file and built object with header values
	string key_string(key);//built string from the name of variable
	//
	//go thru the whole double value dictionary and look for key
	//if key exists read double value, and store in the NeXus file in the place from which it was invoked
	//
	if(Edf.double_by_key(key_string, double_value)){
            
	    double valueD[1]={double_value}; 	
	    dims[0] = 1;	
	    Node node(key, (void*)valueD, 1, dims, NX_FLOAT64);
            tr.insert(tr.begin(),node);
	}
	else {
	
	//
	//go thru the whole string dictionary and look for key
	//if key exists read string value, and store in the NeXus file in the place from which it was invoked
	//    
	    if(Edf.string_by_key(key_string, string_value)){
		
	        const int size=string_value.size();//check size of string
	        std::vector<char> valueS(size);
		for(int i=0; i<size; i++){
		    valueS[i]=string_value[i];//translate C++ string into C-style string, NXtranslate convetion
		}
		dims[0]=size;
		Node node(key, (void*)&(valueS[0]), 1, dims, NX_CHAR);
                tr.insert(tr.begin(),node);	        
	    }
	    //
	    //key does not exist in any of both dictionaries, store empty string
	    //
	    else{
	    
	        cout<<" Key "<<key_string<<" does not exist in the header. Empty string is saved.\n";
	        char empty[1];
		Node node(key, (void*)empty, 1, dims, NX_CHAR);
                tr.insert(tr.begin(),node);	    
	    
	    }    	
	}
    }
    //
    //case of single Image(I letter)
    //
    else if(label_case==2){
        //
	//read EDF file and create object with header values and image
	//
	edf_reader Edf = edf_reader(infile);
	//
	//check the size of image
	//
	int image_dim[1]={Edf.get_image_size()};
        //
	//store image in the place of the NeXus hierarchy from the command was invoked in .xml file
	//
	Node node_data("Image", (void*)Edf.get_image(), 1, image_dim, NX_INT8);
	tr.insert(tr.end(),node_data);        
    
    }
    //
    //case for storing every keys from header with an image
    //
    else{
        
        double valueD[1];
        double double_value;    
        string string_value;
	int dims1[1]={1};
        //
	//create object with header values and Image
	//
	edf_reader Edf = edf_reader(infile);
	string key;
	//
	//get size of both dictionaries
	//
	int double_map_size = Edf.size_map_double();
        int string_map_size = Edf.size_map_string();
	//
	//iterators used for creation of hierarchical subtree
	//
	tree<Node>::iterator root, log, data;
	//
	//create NXentry root group, in the place where command was invoked,  
	//
	Node node("empty", "NXentry"); 
	root = tr.insert(tr.end(),node);//insert root to the tree
	//
	//create NXlog group for storing header values
	//group is a sub group of NXentry root group
	//
	Node log_node("EDF_log", "NXlog"); 
	log = tr.append_child(root,log_node);
        //
	//create NXdata group for storing EDF image
	//group is a sub group of NXentry root group		
	//
	Node data_node("EDF_image", "NXdata"); 
	data = tr.append_child(root,data_node);	
	//
	//get every keys and values from dicitonary of double values
	//
	for(int i=1; i<double_map_size+1; i++){
	    key=Edf.get_key_double(i, double_value);
	    valueD[0]=double_value;
	    //
	    //store pairs key-double value in NXlog group
	    //
	    Node node_child(key, (void*)valueD, 1, dims1, NX_FLOAT64);
            tr.append_child(log,node_child);	    
	}
        //
	//get every keys and values from dicitonary of string values
	//
	for(int i=1; i<string_map_size+1; i++){
	    key=Edf.get_key_string(i, string_value);
	    int size=string_value.size();
	    dims1[0]=size;
	    std::vector<char> valueS(size);
	    //  
	    //convert C++ string into C-style string, NXtranslate convention
	    //
	    for(int i=0; i<size; i++){
	        valueS[i]=string_value[i];
            }
	    //
	    //store pairs key-string value in NXlog group
	    //
	    Node node_child(key, (void*)&(valueS[0]), 1, dims1, NX_CHAR);
            tr.append_child(log,node_child);	    
	}
	//
	//prepare image size 
	//
	int image_dim[1]={Edf.get_image_size()};
        //
	//store edf-image in NXdata group
	//
	Node node_data("Image", (void*)Edf.get_image(), 1, image_dim, NX_INT8);
	tr.append_child(data,node_data);
    }
}