Monday, March 08, 2010

c++ copy constructor

#include

using namespace std;

class obj
{
public:
obj(int);
obj(const obj &);
int getvalue(void);
private:
int value;
};

obj::obj(int a)
{
value = a;
cout << "this is constructor" << endl;
}

obj::obj(const obj & ab) // <-- this is copy constructor format
{
value = ab.value; // <-- surprise!, in copy constructor you can use other obj's private value. real no surprise, thus other object is the same type. use a function will ruin the const prefix.
cout << "this is copy constructor" << endl;
}

int obj::getvalue(void)
{
return value;
}

int main(void)
{
obj obj1 = obj(1); // <-- this calls constructor
obj obj2(obj1); // <-- this calls copy constructor
return 0;
}

Sunday, March 07, 2010

graph work flow in latex document preparation under linux

Graphs make document illustrative.

Eps or pdf can be used in latex document preparation. But not both. Eps is great at vector graph and so is pdf while pdf can handle nature image as well but not for eps. So the choice is to use pdf as the output format for our document.

Use
\usepackage[pdftex]{graphicx}
in the latex header part, and in the body part, use
\includegraphics[width=2in]{graphname}
graphname is the file name for the graph without the tail .pdf.

There are two source of graph. One is computer generated, the other is natural image.
For compute generated, we take diagram as example.

1. Open Dia to draw the diagram.
2. Save as .dia so we can modify the diagram later.
3. Save as .eps so we still know the boundary.
4. use convert to convert eps to pdf.
5. Open the .pdf file in Inkscape. In page setup, use fit size to selected option after select the content box.
6. Save the output .pdf from Inkscape.

For the natural image
1. Use convert command to convert other format to pdf.
2. Use Inkscape again to trim the pdf to proper size.

Friday, March 05, 2010

emacs windows command and work flow

we cant split windows to have more windows and we can have different windows to have the same buffer or different buffers.

splitting windows:
cx 2 split vertically
cx 3 split horizontally

Using other windwos
cx o select next window

Displaying in another window
cx 4 b select buffer in next window and move to the next window
cx 4 co select buffer in next window
cx 4 f open file in next window
cx 4 d open dir in next window
cx 4 m start composing a mail message in another window
cx 4 . find a tag in the current tag table in another window
cx 4 r open a file readonly in the next window.

Deleting and Rearranging Windows
cx 0 kill the current window
cx 1 maximize the current window
cx ^ make selected window taller
cx } make selected window wider

Thursday, March 04, 2010

emacs buffer command and work flow

every content part in emacs is in a buffer, it's not necessary to have a buffer corresponding to a file. Usually we have a lisp interpreter buffer, text buffer and help buffer. Here a list of command around buffer is listed.

cx b switch buffers
cx k close buffer
cx 2 split buffer
cx 1 make the buffer where cursor in the only visible buffer
cx o Switch between the buffers on-screen
cx 4 b select a buffer but open in another window.
cx cb list existing buffer
cx cq toggle read only of the buffer
mx rename-buffer change the buffer name
mx view-buffer scroll through the buffer
cx k kill the buffer
mx kill-some-buffers offer kill buffer one by one
mx buffer-menu begin editing a buffer listing all emacs buffers, commands are:
d delete and move down, cd delete and move up, s save the buffer, ~ make buffer unmodified, x perform operation, u remove operation on current line and move down,

1 Select the buffer in a full-screen window.
2 set up two windows, with this buffer in one, and the previously selected buffer
f select the buffer in place of the `*Buffer List*' buffer.
o select the buffer in another window as if by C-x 4 b, leaving `*Buffer List*' visible.
q select this buffer, and also display in other windows any buffers previously flagged with the m command. If there are no such buffers, this command is equivalent to 1.
m Flag this buffer to be displayed in another window if the q command is used. The request shows as a `>' at the beginning of the line. The same buffer may not have both a delete request and a display request.

The following are some common work flow related to the buffer operation in the emacs.

I have read a file and want to look if there is other buffer opened: cx cb
then i want to switch back to let the working window has the full screen: cx 1
if I get other file to open, and want to switch to other buffer: cx b

learning emacs

Learning Emacs, get to know the following command:

program control:
cx cf open or create a file
cx cs save file
cx s save all open buffers
cx cw save file as
cx cc exit
cg cancel current command
cl redisplay screen and center on cursor
c/ undo action
cx d open directory

cursor movement
cn next line
cp previous line
cf forward a line
cb back a line
ca beginning of line
ce end of line
cv page down
av page up
a< move to beggining of file
a> move to end of file
ax goto-line n go to line n

Editing
ck kill line
cd erase next char
ad drase word
delete delete
c begin marking
cw delete region from begin of mark to current cursor position. content is moved to kill ring buffer
cy insert content of kill ring buffer at cursor position
ay if typed after a cy, it goes through nay entries in the kill ring and replaces the cy insert with the next former kill ring entry
aw copy content of region from marked begging to current cursor location into the kill ring buffer
ct transpose characters on either side of cursor
at transpose words on either side of cursor
cq escape the special meaning of the next char, if want to insert a control into the code, you type cq cc.
cc cc comment out a marked region
cu cc cc uncomment out the marked region.

Search and replace
cs search for string starting at the cursor. The line at the botton of the window hs you type in the string you search for. The search is donw as you type. To look for the next occurannce, hit cs again, and your last entry is used as the default search string. if you hist the bottom of the buffer, you type cs again to go back to the top.
cr reverse search. same as cs above, excpet it seraches backward from the cursor.
ax replace-string works from current cursor locatin. begins a two part dialog, the bottom of the it first asks for the string you want to search for, and then asks for what you want to replace it with. This operation immediately works on the entire buffer.
a% query replace string. works from current cursor location. begins a two part dialog, at the botton of the window it asks you waht you want to search for and then waht you want to search for and then waht want to replace it with. It then searches for each occurance of the string and highlights the match. If you want the replacement to occur, hit the space bar, if you want it to skip this match , hit the delete key.

Buffers, Regions, Windows
cx 2 split window into two equal sized buffers, one on top of the other
cx 3 split window into two equal sized buffers, on to the left/right of the other.
cx o move the cursor to the next buffer in the visible window
cx 5 2 create a new window, with the contents of the current buffer in the new window as well.
cx 1 if in a two buffer window, have the buffer that the cursor is in take up the entire window.
cx 0 if in a two buffer window, have the buffer that the cursor is not in take up the entire window
cx b shift back to the most recent buffer you were visiting prior to your current buffer
cx b filename shift to the named filename bufer
cx cb list all of the buffers currently perned. if the curosr is on a linein this buffer window, type an e will open that buffer in the current buffer, typing an o will open it in a second buffer in the current window.
cx k kill the current buffer. If the buffer is not saved you will be prompted to save it.

Printing
ax print-buffer prints the current buffer
ax print-region prints the current marked region

Command Shell
ax shell creates a command shell on the native os. all of emacs commands work within this shell for cutting and pasting.
ap yank command from prior command history
an next command from prior command history
cx k kill buffer and the shell along with it.

Blog Archive