本文整理汇总了C++中getElement函数的典型用法代码示例。如果您正苦于以下问题:C++ getElement函数的具体用法?C++ getElement怎么用?C++ getElement使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getElement函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[]){
int i, s, max, min, d, n=35;
List C = newList(); // central vertices
List P = newList(); // peripheral vertices
List E = newList(); // eccentricities
Graph G = NULL;
// Build graph G
G = newGraph(n);
for(i=1; i<n; i++){
if( i%7!=0 ) addEdge(G, i, i+1);
if( i<=28 ) addEdge(G, i, i+7);
}
addEdge(G, 9, 31);
addEdge(G, 17, 13);
addEdge(G, 14, 33);
// Print adjacency list representation of G
printGraph(stdout, G);
// Calculate the eccentricity of each vertex
for(s=1; s<=n; s++){
BFS(G, s);
max = getDist(G, 1);
for(i=2; i<=n; i++){
d = getDist(G, i);
max = ( max<d ? d : max );
}
append(E, max);
}
// Determine the Radius and Diameter of G, as well as the Central and
// Peripheral vertices.
append(C, 1);
append(P, 1);
min = max = front(E);
moveTo(E,0);
moveNext(E);
for(i=2; i<=n; i++){
d = getElement(E);
if( d==min ){
append(C, i);
}else if( d<min ){
min = d;
clear(C);
append(C, i);
}
if( d==max ){
append(P, i);
}else if( d>max ){
max = d;
clear(P);
append(P, i);
}
moveNext(E);
}
// Print results
printf("\n");
printf("Radius = %d\n", min);
printf("Central vert%s: ", length(C)==1?"ex":"ices");
printList(stdout, C);
printf("\n");
printf("Diameter = %d\n", max);
printf("Peripheral vert%s: ", length(P)==1?"ex":"ices");
printList(stdout, P);
printf("\n");
printf("--------------This concludes the given test by professor\n");
// recomputes BFS with source vertex
BFS(G, 2);
clear(C);
clear(P);
getPath(C, G, 35);
getPath(P, G, 2);
// prints out computed paths and distances
printf("The path from source to vertex 35(the source vertex): ");
printList(stdout, C);
printf("\nThe distance from source to vertex 35( the source vertex): ");
printf("%d\n", getDist(G, 35));
printf("\nThe path from source to vertex 2: ");
printList(stdout, P);
printf("\nThe distance from source to vertex 2( the source vertex): ");
printf("%d\n", getDist(G, 2));
printf("\n");
// Free objects
clear(C);
clear(P);
freeGraph(&G);
//re-build graph G
n = 100;
G = newGraph(n);
for(i = 1; i<n; i++){
if(i%10 !=0) addEdge(G,i,i+1);
if(i<=50) addArc(G, i, i+10);
}
//.........这里部分代码省略.........
示例2: getElement
const SkMemberInfo* SkAnimator::getField(const char* elementID, const char* field) {
const SkDisplayable* element = getElement(elementID);
return getField(element, field);
}
示例3: perform
bool perform()
{
showCorrectTab();
getElement()->setFillType (newState, false);
return true;
}
示例4: isScalar
bool vesUniform::get(bool &value) const
{
return isScalar() ? getElement(0, value) : false;
}
示例5: getElementText
const char* ConfigXml::getVersion()
{
return getElementText(getElement("version"));
}
示例6: main
int main (int argc, char* argv[]){
// temporary string holder
char line[MAX_LEN];
// checks for correct command line inputs
if(argc != 3) {
printf("Invalid number of inputs");
exit(1);
}
// opens the file
FILE* input = fopen(argv[1], "r");
FILE* output = fopen(argv[2], "w");
// checks if files have been open and or created
if(input == NULL){
printf("Unable to open file %s for reading\n", argv[1]);
return 1;
} else if (output == NULL){
printf("Unable to open file %s for reading\n", argv[2]);
return 1;
}
// read each line of input file, then count and print tokens
fgets(line, MAX_LEN, input);
int numVertex = 0;
sscanf(line, "%d", &numVertex);
List S = newList();
for (int i = 1; i <= numVertex; i++) append(S, i);
// Graph creation
Graph G = newGraph(numVertex);
while( fgets(line, MAX_LEN, input) != NULL) {
int vert1 = 0;
int vert2 = 0;
sscanf(line, "%d %d", &vert1, &vert2);
if(vert1 == 0 && vert2 == 0) break;
addArc(G, vert1, vert2);
}
DFS(G, S);
fprintf(output, "Adjacency list representation of G:\n");
printGraph(output, G);
Graph T = transpose(G);
DFS(T, S);
//counts the number of Scc
int numScc = 0;
for(moveTo(S, 0); getIndex(S) >= 0; moveNext(S)){
if(getParent(T, getElement(S)) == NIL) numScc ++ ;
}
// puts the components into array list of size # of scc
List Scc[numScc];
int i = numScc;
for(moveTo(S, 0); getIndex(S) >= 0; moveNext(S)){
if(getParent(T, getElement(S)) == NIL){
i--;
Scc[i] = newList();
}
if(i == numScc) break;
append(Scc[i], getElement(S));
}
// prints out scc's
fprintf(output, "\nG contains %d strongly connected components:", numScc);
for(int j = 0; j < numScc; j++){
fprintf(output, "\n");
fprintf(output, "Component %d: ", j + 1);
printList(output, Scc[j]);
freeList(&(Scc[j]));
}
// frees all the necessary items
fprintf(output, "\n");
freeGraph(&G);
freeGraph(&T);
freeList(&S);
fclose(input);
fclose(output);
return(0);
}
示例7: main
int main(int argc, char *argv[])
{
ApplicationsLib::LogogSetup logog_setup;
TCLAP::CmdLine cmd("Query mesh information", ' ', BaseLib::BuildInfo::git_describe);
TCLAP::UnlabeledValueArg<std::string> mesh_arg("mesh-file","input mesh file",true,"","string");
cmd.add( mesh_arg );
TCLAP::MultiArg<std::size_t> eleId_arg("e","element-id","element ID",false,"number");
cmd.add( eleId_arg );
TCLAP::MultiArg<std::size_t> nodeId_arg("n","node-id","node ID",false,"number");
cmd.add( nodeId_arg );
cmd.parse( argc, argv );
const std::string filename(mesh_arg.getValue());
// read the mesh file
auto const mesh = std::unique_ptr<MeshLib::Mesh>(
MeshLib::IO::readMeshFromFile(filename));
if (!mesh)
return EXIT_FAILURE;
auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs");
for (auto ele_id : eleId_arg.getValue())
{
std::stringstream out;
out << std::scientific
<< std::setprecision(std::numeric_limits<double>::digits10);
out << "--------------------------------------------------------" << std::endl;
auto* ele = mesh->getElement(ele_id);
out << "# Element " << ele->getID() << std::endl;
out << "Type : " << CellType2String(ele->getCellType()) << std::endl;
if (materialIds)
out << "Mat ID : " << (*materialIds)[ele_id] << std::endl;
out << "Nodes: " << std::endl;
for (unsigned i=0; i<ele->getNNodes(); i++)
out << ele->getNode(i)->getID() << " " << *ele->getNode(i) << std::endl;
out << "Content: " << ele->getContent() << std::endl;
out << "Neighbors: ";
for (unsigned i=0; i<ele->getNNeighbors(); i++)
{
if (ele->getNeighbor(i))
out << ele->getNeighbor(i)->getID() << " ";
else
out << "none ";
}
out << std::endl;
INFO("%s", out.str().c_str());
}
for (auto node_id : nodeId_arg.getValue())
{
std::stringstream out;
out << std::scientific
<< std::setprecision(std::numeric_limits<double>::digits10);
out << "--------------------------------------------------------" << std::endl;
auto* node = mesh->getNode(node_id);
out << "# Node" << node->getID() << std::endl;
out << "Coordinates: " << *node << std::endl;
out << "Connected elements: " ;
for (unsigned i=0; i<node->getNElements(); i++)
out << node->getElement(i)->getID() << " ";
out << std::endl;
INFO("%s", out.str().c_str());
}
}
示例8: perform
bool perform()
{
showCorrectTab();
getElement()->enableStroke (newState, false);
return true;
}
示例9: KERNAL_ERROR
type_index NEIndexedNodeSet::insert(type_index index, const NENode* const source)
{
if( ! &source)
{
KERNAL_ERROR(" : 주어진 원본이 없습니다.");
return NE_INDEX_ERROR;
}
if(_occupiedset[index])
{
type_result result = setElement(index, source);
if(NEResult::hasError(result))
{
KERNAL_ERROR(" : ");
return result;
}
}
// 가상생성자로 인스턴스 생성:
// 인스턴스 복사 알고리즘:
// 뭐가 문제인가:
// 1. 주어진 source는 _manager를 가지고 있다.
// 2. 주어진 source의 타입은 NEModule로써 이는 ADT이다. 따라서 source의
// 실제 타입이 무엇인지는 알 수 없다.
// 3. source의 실제타입에 상관없이 제대로 복사를 하는 함수로는 현재,
// clone(가상복사생성자)가 유일하다.
// 4. clone은 어떠한 파라메터도 받지 않도록 작성되어있다.
// 5. SuperClass::insert에서는 clone로 생성된 T*를 보관해 두는데,
// source.keyset은 clone을 통해서도 복사가 불가능하다.
// 복사가 되려면, 복사생성된 객체에 manager가 할당되어 있어야 keyset이
// manager 포인터를 갖고 인스턴스를 등록하기 때문이다.
// 6. clone은 원자연산이다.
// 즉, 생성하고->manager를 set하고->복사한다는 식으로 구성할 수 없다.
//
// 어떤 해결방법이 있었는가:
// 기존의 생성과 동시에 복사한다.----> 생성->manager set-> 복사
// 의 형태로 중간에 manager를 set 할 수 있도록 하면 된다.
// 따라서, 생각해보면, "생성과 동시에 set. 이후 복사" 나
// "생성 이후, manager set과 동시에 복사"를 생각해 볼 수 있다.
// 전자의 경우는 생성자에서 manager를 넘겨준 이후에 복사시
// 가상할당자(예를 들면 virtual assign(module))등을 새로 추가하는
// 방법이 되겠다.
// 아니면 기존 virtual clone() 이외에도 virtual clone(manager)로 하나 더
// 만드는 방법도 생각해 볼 수 있다.
// 복사생성자에서 source의 _manager도 같이 복사하는 방법도 생각해 볼 수
// 있겠으나, 이렇게 하면 복사된 인스턴스가 내쪽의 manager가 아닌, source쪽
// manager에 속해있게 되버리므로 적합치 못하다.
// 이러한 방법도 있다. clone을 호출하면 멤버변수(keyset)은 할당되지 않더라도
// source의 모듈은 정확하게 복사 할 수 있다.
// 그 이후에 manager를 set하고, 다시한번 operator=를 하는 방법이다.
// NEModule& cloned = source.clone(); // 모듈의 객체만 가상생성
// cloned.manager is my manager; // 매니져 할당
// cloned.operator=(source) // 이제 멤버변수를 복사
// 다만 이 방법의 가장 큰 단점은 keyset에 속하지 않는 멤버변수는 복사 할 수
// 없다는 제약이 있다는 것이다.
//
// 최종 해결방법은 무엇인가:
// 객체 생성시, 상속계층을 거꾸로 올라가면서 생성자를 호출해간다.
// 그 중간쯤에 manager를 관리하는 클래스가 있을 것이다. 그 생성자가 호출되었
// 을때 외부에서 특정한 manager값을 전달하는 이벤트 핸들러만 있으면 될것이다.
// 그래서 이를 해결하기 위해 static으로 global_manager라는 방법을 사용한다.
// static Manager* getGlobalManager();
// static setGlobalManager(Manager*);
// 의 함수를 이용해서 해당하는 manager 멤버변수를 소유한 클래스가 호출 되었을때
// 특별히 주어진 manager가 없을때 global_manager를 할당하는 방법이다.
// 다만 이 globalmanager를 사용하는 생성자는 복사생성자로 제한한다.
// 일반 생성자는 manager를 할당할 수 있는 함수가 이미 있으므로, 사용자가 manager
// 외부로부터 할당하고 싶었는지 아닌지 의도를 파악할 수 있기 때문이다.
//
// 예상되는 문제점:
// 이 문제에 예상되는 문제점은 다음과 같다.
// 1. static이긴 하나 생성자에서 메소드를 호출한다는 점에서 예상치못한 에러가
// 있을 수 있다. -> push pop의 개념을 적용하여 일정 부분 해결
// 2. 할당한 global manager값을 해제해주지 않으면 전혀다른 객체가 생성될때도
// 내 manager가 할당되버리는 오류가 발생할 것이다. -> 코드 작성에 주의하면
// 안정성 확보 가능
// 3. 내가 소유할 하나의 객체를 위해 global_manager를 할당한다 하더라도 내부적으로
// 다른 manager 영역에 있는 객체를 생성하고자 할때가 있을 수도 있다.
//
// 적용시점:
// SuperClass인 IndexedArrayTemplate에서 clone이 사용되기 직전마다 _setGlobalManager
// 를 해줘야한다. 최종적으로 적용 대상은 다음과 같다.
// 1. insert
// 2. resize
// 3. setElement
// 생성자 핸들러: 보다 자세한 내용은 NEIndexedModuleSet.cpp 참조하라
// 전역 manager 셋:
// 타겟팅:
NEEnlistableManager& push = NEGlobalManagerOffer::getGlobalManager();
// 연산:
NEGlobalManagerOffer::_setGlobalManager(getManager());
// 복사:
type_index inputed_index = SuperClass::insert(index, source);
// 아이디 할당:
// 타겟팅:
NENode& node = getElement(inputed_index);
if(&node)
node._id = _generateId();
//.........这里部分代码省略.........
示例10: main
int main(int argc, char* argv[]){
int i, s, max, min, d, n=35;
List C = newList(); // central vertices
List P = newList(); // peripheral vertices
List E = newList(); // eccentricities
Graph G = NULL;
// Build graph G
G = newGraph(n);
for(i=1; i<n; i++){
if( i%7!=0 ) addEdge(G, i, i+1);
if( i<=28 ) addEdge(G, i, i+7);
}
addEdge(G, 9, 31);
addEdge(G, 17, 13);
addEdge(G, 14, 33);
// Print adjacency list representation of G
printGraph(stdout, G);
// Calculate the eccentricity of each vertex
for(s=1; s<=n; s++){
BFS(G, s);
max = getDist(G, 1);
for(i=2; i<=n; i++){
d = getDist(G, i);
max = ( max<d ? d : max );
}
append(E, max);
}
// Determine the Radius and Diameter of G, as well as the Central and
// Peripheral vertices.
append(C, 1);
append(P, 1);
min = max = front(E);
moveTo(E,0);
moveNext(E);
for(i=2; i<=n; i++){
d = getElement(E);
if( d==min ){
append(C, i);
}else if( d<min ){
min = d;
clear(C);
append(C, i);
}
if( d==max ){
append(P, i);
}else if( d>max ){
max = d;
clear(P);
append(P, i);
}
moveNext(E);
}
// Print results
printf("\n");
printf("Radius = %d\n", min);
printf("Central vert%s: ", length(C)==1?"ex":"ices");
printList(stdout, C);
printf("\n");
printf("Diameter = %d\n", max);
printf("Peripheral vert%s: ", length(P)==1?"ex":"ices");
printList(stdout, P);
printf("\n");
// Free objects
freeList(&C);
freeList(&P);
freeList(&E);
freeGraph(&G);
return(0);
}
示例11: main
int main(int argc, char * argv[]) {
if(argc != 3) {
printf("Usage: %s <input file> <output file>\n", argv[0]);
exit(1);
}
FILE *in, *out;
// read input with fopen "r"
in = fopen(argv[1], "r");
// write to output with fopen "w"
out = fopen(argv[2], "w");
if(in == NULL) {
printf("Unable to open file %s for reading\n", argv[1]);
exit(1);
}
if(out == NULL) {
printf("Unable to open file %s for writing\n", argv[2]);
exit(1);
}
// Count number of lines in file and then reopen file
char line[MAX_LEN];
int lines = 0;
while(fgets(line, MAX_LEN, in) != NULL) {
lines++;
}
fclose(in);
in = fopen(argv[1], "r");
// Initialize the word array
// Read the words into an array while allocating memory for each
// word from the input file
int n = 0;
char **words = (char **)malloc(lines * sizeof(char*));
char* word;
while(fgets(line, MAX_LEN, in) != NULL) {
word = malloc((strlen(line)+1) * sizeof(char));
strcpy(word, line);
words[n++] = word;
free(word);
}
// Insertion Sort to alphabetize file
List sorted = newList();
append(sorted, 0);
char* current;
int j;
int flag;
// Insertion Sort on the String array of words into List
for(int i=1; i<lines; i++) {
flag = 0;
current = words[i];
moveTo(sorted, 0);
j = 0;
while(!flag && j<i) {
printf("%s", current);
if(strcmp(current, words[getElement(sorted)])<0) {
insertBefore(sorted, i);
flag = 1;
} else {
moveNext(sorted);
j++;
}
}
if(!flag) {
append(sorted, i);
}
}
// Print words alphabetically to output file
for(int i=0; i<lines; i++) {
moveTo(sorted, i);
fprintf(out, "%s", words[getElement(sorted)]);
}
// free memory
free(words);
freeList(&sorted);
// close files
fclose(in);
fclose(out);
return(0);
}
示例12: operator
/// Returns value for row rowName and column columnName
inline double operator()(const char *rowName, const char *columnName) const
{
return getElement(rowName, columnName);
}
示例13: undo
bool undo()
{
showCorrectTab();
getElement()->setPosition (oldState, false);
return true;
}
示例14: undo
bool undo()
{
showCorrectTab();
getElement()->enableStroke (oldState, false);
return true;
}
示例15: catch
bool
MediaSink::linkPad (std::shared_ptr<MediaSrc> mediaSrc, GstPad *src)
{
std::shared_ptr<MediaSrc> connectedSrcLocked;
GstPad *sink;
bool ret = false;
mutex.lock();
try {
connectedSrcLocked = connectedSrc.lock();
} catch (const std::bad_weak_ptr &e) {
}
if ( (sink = gst_element_get_static_pad (getElement(), getPadName().c_str() ) ) == NULL)
sink = gst_element_get_request_pad (getElement(), getPadName().c_str() );
if (gst_pad_is_linked (sink) ) {
unlink (connectedSrcLocked, sink);
}
if (mediaSrc->parent == parent) {
GstBin *container;
GstElement *filter, *parent;
GstPad *aux_sink, *aux_src;
GST_DEBUG ("Connecting loopback, adding a capsfilter to allow connection");
parent = GST_ELEMENT (GST_OBJECT_PARENT (sink) );
if (parent == NULL)
goto end;
container = GST_BIN (GST_OBJECT_PARENT (parent) );
if (container == NULL)
goto end;
filter = gst_element_factory_make ("capsfilter", NULL);
aux_sink = gst_element_get_static_pad (filter, "sink");
aux_src = gst_element_get_static_pad (filter, "src");
g_signal_connect (G_OBJECT (aux_sink), "unlinked", G_CALLBACK (sink_unlinked), filter );
g_signal_connect (G_OBJECT (aux_src), "unlinked", G_CALLBACK (src_unlinked), filter );
gst_bin_add (container, filter);
gst_element_sync_state_with_parent (filter);
if (gst_pad_link (aux_src, sink) == GST_PAD_LINK_OK) {
if (gst_pad_link (src, aux_sink) == GST_PAD_LINK_OK)
ret = true;
else
gst_pad_unlink (aux_src, sink);
}
g_object_unref (aux_sink);
g_object_unref (aux_src);
gst_debug_bin_to_dot_file_with_ts (GST_BIN (container), GST_DEBUG_GRAPH_SHOW_ALL, "loopback");
} else {
if (gst_pad_link (src, sink) == GST_PAD_LINK_OK)
ret = true;
}
if (ret == true) {
connectedSrc = std::weak_ptr<MediaSrc> (mediaSrc);
} else {
gst_element_release_request_pad (getElement(), sink);
}
end:
g_object_unref (sink);
mutex.unlock();
return ret;
}