102 Solved Topics

Remove Filter
Member Avatar for daviddoria

The problem is on the "MyIter = " line: [code] class OrientedPoint { .... class variables ... std::map<std::string, double> DoubleValues; ..... bool OrientedPoint::getDoubleValue(const std::string &ValueName, double &Value) const { std::map<std::string, double>::iterator MyIter; MyIter = DoubleValues.find(ValueName); [/code] The error produced is: [code] In member function 'bool OrientedPoint::getDoubleValue(const std::string&, double&) const': error: …

Member Avatar for daviddoria
0
6K
Member Avatar for daviddoria

Is there a way (without overloading) to call a function like this [code=cplusplus] GetValue("one"); //AND std::string test("one"); GetValue(test); [/code] The function is simply: [code=cplusplus] int GetValue(const std::string &MyString) { return MyMap[MyString]; } [/code] This overload does the job: [code=cplusplus] int GetValue(const char* MyString) { return MyMap[MyString]; } [/code] But that …

Member Avatar for daviddoria
0
114
Member Avatar for daviddoria

I don't understand why can you do this: [code] Employee *emp; if (condition1) emp = new Employee(); else if (condition2) emp = new Manager(); [/code] but not this: [code] Employee emp; if (condition1) emp = Employee(); else if (condition2) { emp = Manager(); [/code] Maybe this is a TERRIBLE idea, …

Member Avatar for Ancient Dragon
0
96
Member Avatar for daviddoria

I'm trying to start writing tests for all of my functions as per Test Driven Development. My question is, say I construct a test for "rotate vector". It would be something like this: [code] int TestRotateVector(const Vector &V) { Vector Original(1.0, 2.0); Vector Rotated = Original.Rotate(10); //rotate 10 degrees if(Rotated …

Member Avatar for StuXYZ
0
186
Member Avatar for daviddoria

i.e. [code] class A { int x = 5; }; [/code] I saw a mailing list post from October 08 where a guy asked if this was going to be added. gcc 4.4 was released April 09, so I would assume it would have been added by then? I haven't …

Member Avatar for Ancient Dragon
0
162
Member Avatar for daviddoria

If I do something like this: [code] print "%08d" % 2 [/code] It will print '00000002'. However, I want to change the "8" to a "3" at runtime (to get '002' instead). I tried this: [code] MyLength = 3 print "%0" + str(MyLength) + "d" % 2 [/code] but I …

Member Avatar for daviddoria
0
138
Member Avatar for daviddoria

I'm just starting python and it seemed reasonable to go ahead and learn the new version. I read that numpy wont be available for python3 until at least 2010. All I need is a basic "vector", "matrix", and some basic functions like matrix/vector multiplication. Is anything like this available for …

Member Avatar for sneekula
0
136
Member Avatar for daviddoria

If I have /home/doriad/Scripts/Python/ and inside I have a bunch of folders, ie Geometry, Math, Other, etc that each contain scripts (.py files), is there a way I can just add /home/doriad/Scripts/Python to PYTHONPATH and then somehow [code] from Geometry/Spherical import * [/code] rather than having to add every subdirectory …

Member Avatar for vegaseat
0
2K
Member Avatar for daviddoria

I want to make an input stream parser capable of handling input in any of the following forms: [code] x y z x,y,z x, y, z (x,y,z) (x, y, z) [/code] Is there a clever way to do this? Or do I have to check the first character, if it …

Member Avatar for ArkM
0
86
Member Avatar for daviddoria

Is it possible to indicate that a class function you are calling is static? [code] class Point { std::string name; public: Point(){} static void DisplayName() { std::cout << "Point" << std::endl;} }; int main() { Point.DisplayName(); //this doesn't indicate the the member function is static //maybe something like this: //static_call(Point.DisplayName()); …

Member Avatar for siddhant3s
0
100
Member Avatar for daviddoria

I have a "Tools" class which contains a lot of functions I commonly use. One is a parallel sort. I pass it a vector of Objects and a vector of indices, and it sorts the Objects and sorts the indices the same way (so the corresponding index is in the …

Member Avatar for Ancient Dragon
0
86
Member Avatar for daviddoria

I was looking at this: [url]http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18[/url] I don't understand [code] File f = OpenFile("foo.txt"); [/code] It seems like File is one class, and OpenFile is a separate class, so how can you assign an OpenFile to a File? Also, is it necessary to have this second class? Why not something …

Member Avatar for Ancient Dragon
0
294
Member Avatar for daviddoria

To redirect clog, I have been using this: [code] std::streambuf* clog_save; std::ofstream ofs; clog_save = std::clog.rdbuf(); ofs.open(LogFilename.c_str()); std::clog.rdbuf(ofs.rdbuf()); cout << "Test cout." << endl; std::clog << "Test log." << endl; std::clog.rdbuf(clog_save); ofs.close(); [/code] However, it seems like bad "code reuse" practice to have to put this in every program I …

Member Avatar for ArkM
0
178
Member Avatar for daviddoria

I usually make a matrix like this [code] from Numeric import * A=zeros([3,3]) print str(A[0,1]) #access an element [/code] I would like to store a pair of values in each element, that is have a matrix where the (0,0) element is (2.3, 2.4), the (0,1) element is (5.6,6.7), etc. Is …

Member Avatar for vegaseat
0
103
Member Avatar for daviddoria

I found some code to parse command line arguments (is there an easier way? sed always seems so complicated...) [code] #!/bin/bash for i in $* do case $i in --files=*) FILES=`echo $i | sed 's/[-a-zA-Z0-9]*=//'` ;; --default) DEFAULT=YES ;; *) # unknown option ;; esac done echo $FILES echo "File …

Member Avatar for hexram
0
109
Member Avatar for daviddoria

I need to get an unknown number of file names from the command line, ie ./python MyScript.py --Files 1.txt 2.txt 3.txt [code] parser.add_option("-n", "--NumFiles", type="int", help="Number of files") parser.add_option("--Files", nargs=options.NumFiles, help="a triple") (options, args) = parser.parse_args() [/code] Clearly this will not work because options.NumFiles is not available until after parse_args() …

Member Avatar for daviddoria
0
197
Member Avatar for daviddoria

I want to parse some simple arguments from the command line. This shows all of the arguments: [code] #!/usr/bin/python import sys #print all of the arguments for arg in sys.argv: print arg [/code] but I want to handle something like [code] --file a.txt [/code] or [code] --x 12 --y 13 …

Member Avatar for jlm699
0
111
Member Avatar for daviddoria

I tried to do this to redirect the clog output to a file: [code] ofstream ofs("file.log"); clog.rdbuf(ofs.rdbuf()); clog << "Logged." << endl; ofs.close(); [/code] It worked (the file contains the text), but the program segfaults. I read that you have to "restore" the original buffer, so I tried this [code] …

Member Avatar for Narue
0
120
Member Avatar for daviddoria

A friend of mine said that python could be used to make simple GUIs (ie. a couple of buttons and a text box). I googled "python gui" and it looks like there are 30934 libraries to make GUIs. Is there a "standard" or "built in" one? Thanks, Dave

Member Avatar for jlm699
0
109
Member Avatar for daviddoria

Does anyone have a good 2 line summary of WHEN to use perl/python/bash/etc? To do easy-ish things, they can clearly all be used, but there is likely an ideology behind each that indicates WHEN/WHY to use them. For example, I use VB if I want easy GUI, c++ if I …

Member Avatar for leegeorg07
0
136
Member Avatar for daviddoria

I am trying to do this [code] #!/bin/bash for i in 1 2 3 4 5; do File1="$i.txt" File2="$i.obj" ./Test $File1 $File2 #save i and the result of the program somehow done; [/code] For example, at the end I would like to have a file like this [code] 1 3.4 …

Member Avatar for nucleon
0
162
Member Avatar for daviddoria

I have used boost's progress bar (it outputs ***** from 0 to 100% complete) to track the progress of long loops. It would also be nice to be able to see a counter along with that, like if I run 1000 tests, the *'s will go from 0 to 100%, …

Member Avatar for daviddoria
0
115
Member Avatar for daviddoria

I am trying to write a pretty straight forward algorithm (agglomerative clustering), but the details are getting pretty hairy. (A cluster is simply a group of points. The idea is to take a list of points and decide which are "grouped" or "clustered" close together.) Here is the outline: Input: …

Member Avatar for daviddoria
0
118
Member Avatar for daviddoria

Currently, my index.html is like this [code] <html> <head> <title>EngineeringNotes.net</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div class="header"> <div id="logo"> <h1>EngineeringNotes.net</h1> </div> <div class="menu"> <ul> <li><a href="mailto:daviddoria@gmail.com">Contact Me</a></li> <li><a href="phpBB3">Forums</a></li> <li><a href="Ideology.html">Ideology</a></li> </ul> </div><!-- end menu --> </div><!-- end header --> <div class="page"><!-- start page --> <div class="sidebar"><!-- …

Member Avatar for daviddoria
0
181
Member Avatar for daviddoria

To remove duplicates from a vector, my first thought was to insert them all into a set, it would take care of the uniqueness of the elements, and then read them back out into my vector. However, I have a vector<Point>, where Point is a point in 3d space (ie. …

Member Avatar for daviddoria
0
213
Member Avatar for daviddoria

I often have this situation [code] class OrientedPoint { private: Point P; Vector N; Color C; bool valid; public: //////////// Constructors ////////// OrientedPoint() {} OrientedPoint(const Point &Coord); OrientedPoint(const Point &Coord, const Vector &Normal); OrientedPoint(const Point &Coord, const Color &C); OrientedPoint(const Point &Coord, const Vector &Normal, const Color &C); [/code] where …

Member Avatar for daviddoria
0
122
Member Avatar for daviddoria

I am trying to use the for_each from stl algorithm. [url]http://www.cplusplus.com/reference/algorithm/for_each.html[/url] [code] #include <algorithm> #include <vector> #include <iostream> template <typename T> void OutputObject(const T &obj) { cout << obj << endl; } template <typename T> void OutputVector(const vector<T> &V) { for_each (V.begin(), V.end(), OutputObject); cout << endl; } [/code] I …

Member Avatar for daviddoria
0
576
Member Avatar for daviddoria

I found this while googling for something [url]http://msdn.microsoft.com/en-us/library/ms177203(VS.80).aspx[/url] I tried it (with g++) and it seems to be a syntax error - is this like something specific to Visual Studio or something? Dave

Member Avatar for Narue
0
92
Member Avatar for daviddoria

Is there a reason to use [code] cout << static_cast<int>(thing); [/code] instead of [code] cout << (int)thing; [/code] ? Thanks, Dave

Member Avatar for Narue
0
102
Member Avatar for daviddoria

If I make an array like this [code] GLubyte bufImage[100][100][3]; [/code] I can pass bufImage to a function and then get the values using: [code] r = bufImage[im_x][im_y][0]; g = bufImage[im_x][im_y][1]; b = bufImage[im_x][im_y][2]; [/code] However, if I don't know Width and Height at runtime, this does not work. I …

Member Avatar for Narue
0
311
Member Avatar for daviddoria

I've seen a few questions about this floating around here (mostly from me :) ) but I finally got this is into a nice working form - maybe it will be useful for someone. It is called like this: [code] void TestParallelSort() { vector<double> Numbers; Numbers.push_back(3.4); Numbers.push_back(4.5); Numbers.push_back(1.2); vector<string> Names; …

0
230
Member Avatar for daviddoria

It seems like SO often I need to attach a "valid" flag to a standard type. For example - I have a function called "CalculateLunchTime" that I pass a vector of times. If the vector has 0 elements, they did not take a lunch, so the duration is 0 minutes. …

Member Avatar for Rashakil Fol
0
598
Member Avatar for daviddoria

If I use the uncommented 3 lines for getting an int out of a stringstream, the value in MPV is wrong. However, if I make a new stringstream, then it works fine. I thought setting .str("") was essentially resetting the stringstream? [code] line = ""; getline(fin, line); //get fourth line …

Member Avatar for daviddoria
0
469
Member Avatar for daviddoria

I have a delete button which does this: [code] TTDataSet.PunchEventTable.Rows(dgvData.SelectedRows(0).Index).Delete() [/code] The problem is that if I delete row 0 (the 0th index in the DataGridView and in the underlying table, all is well. But now row 1 in the table corresponds to row 0 in the DataGridView, so if …

Member Avatar for rapture
0
895
Member Avatar for daviddoria

I put together this little example to test my sanity, and it failed! [code] #include <iostream> #include <fstream> #include <vector> #include <string> #include <sstream> using namespace std; /* Example.txt 23 test 4.5 */ int main(int argc, char *argv[]) { string Filename = argv[1]; cout << "Filename: " << Filename << …

Member Avatar for Freaky_Chris
0
780
Member Avatar for daviddoria

This problem comes up quite a bit for me. I'll have a project that I work on for a couple months (the point is that it is a large project with multiple classes, etc). As an example, say I made a program that draws a square. So I have this …

Member Avatar for daviddoria
0
100
Member Avatar for daviddoria

I have seen some examples like this [code] p.class1 { some stuff } p.class2 {some stuff } [/code] and some like this [code] class1.p {stuff} class2.p {stuff} [/code] In one case, the class name is before the dot, in the other case the class name is after the dot. What …

Member Avatar for daviddoria
0
71
Member Avatar for daviddoria

I am very new to css. I was looking at a css file I found online and trying to figure out what everything does. I am confused with the following couple of things. Please let me know if anything I say is wrong! This on sets up some properties of …

Member Avatar for daviddoria
0
147
Member Avatar for daviddoria

I am trying to output 00001 instead of just 1, so I do this: char pos[5]; sprintf(pos, "%05d", 1); string Index = (string) pos; It works just as I'd expect - if I cout << Index it says 00001 However, it is breaking something totally unrelated. On the next line, …

Member Avatar for grumpier
0
224
Member Avatar for daviddoria

I have a base class called "ModelFile" which I derive several types of 3D model file classes from. Many of these types of files are just a set of points, so in the base class I have a vector<Point> member. Some of the derived file classes also have vector<Triangle> members. …

Member Avatar for grumpier
0
143
Member Avatar for daviddoria

I have a Triangle class which has members [code] Point P1, P2, P3; [/code] So generally I pass the constructor 3 points. [code] Point A(1,1,1); Point B(1,1,0); Point C(0,0,1); Triangle T(A,B,C); [/code] Then I have a bunch of functions that I can pass point's to such as to find intersections …

Member Avatar for Narue
0
116
Member Avatar for daviddoria

I need to do something like this: [code] ifstream infile(Filename.c_str()); //ifstream infile(Filename.c_str(), ios::binary); string line; ///////////// Read Header //////////// //read magic number getline(infine, line); while(line[0] == "#") getline(infile, line); MagicNumber_ = line; //more ascii stuff ...... //start reading binary data int m; infile.read(reinterpret_cast < char * > (&m), sizeof(m)); [/code] …

Member Avatar for Narue
0
125
Member Avatar for daviddoria

I want to be able to do this: Pass a parameter to my main program like "parallel = yes" and then many functions down in the hierarchy (ie main calls "Function1" which calls "Function2" which calls "Function3", etc) I need to see the value of "parallel". I'd hate to have …

Member Avatar for Radical Edward
0
99
Member Avatar for daviddoria

Right now this is my setup: I have these classes Point2 Point3 Vector2 Vector3 Ray2 Ray3 Both Point classes and both Vector are independent. Ray2 contains a Point2 and a Vector2 object, and Ray3 contains a Point3 and a Vector3 object. I have two questions. 1) Should I somehow just …

Member Avatar for Radical Edward
0
115
Member Avatar for daviddoria

I want to do something like this [code] #include <string.h> #include <iostream> using namespace std; int main() { MyFunc("test"); return 0; } void MyFunc(const char* Filename) { cout << strcat(Filename, ".tst") << endl; } [/code] but it tells me that my const char* cannot be used where it is expecting …

Member Avatar for Narue
0
106
Member Avatar for daviddoria

This doesn't seem to behave as I would expect (as it does in matlab, for example). I want to execute a command, but give some readable output instead of the often very messy auto-generated error (index out of range or something). [code] try { MyFunction(1,2); } catch(char* str) { cout …

Member Avatar for daviddoria
0
93
Member Avatar for daviddoria

I have to call a function in the form f(void* params) I would like to pass two vector<double> to this function. I suppose I should make a struct struct MyParam_t { vector<double> myvector1; vector<double> myvector2; }; and then somehow fill it and pass it to the function. Someone recommended that …

Member Avatar for Ancient Dragon
0
107
Member Avatar for daviddoria

I ran this: [code] cout << "has nan q?" << numeric_limits<int>::has_quiet_NaN << endl; cout << "has nan s?" << numeric_limits<int>::has_signaling_NaN << endl; cout << "has nan q?" << numeric_limits<double>::has_quiet_NaN << endl; cout << "has nan s?" << numeric_limits<double>::has_signaling_NaN << endl; [/code] and I get 0 0 1 1 why would …

Member Avatar for Salem
0
183
Member Avatar for daviddoria

I have some code like this: [code] vector<double> Saved; for(int i = 0; i<10; i++) { if(some condition on i) Saved.push_back(i); } [/code] Then I want to see what order the things were saved... so naturally I do cout << Saved.at(0) << endl << Saved.at(1) << endl; But to my …

Member Avatar for mitrmkar
0
192
Member Avatar for daviddoria

I had a global variable that could be seen by all of my functions. I was getting too many functions in the same file, so I made functions.h and functions.cpp. I put the function definitions in functions.cpp and the declarations in functions.h. In main.cpp, I include functions.h. The problem is, …

Member Avatar for daviddoria
0
273

The End.