토요일, 2월 27, 2010

Registry Tip



Registry Tip
 - These code are let you show how to use API which relevant Windows Registry.
 - Registry 에 관련된 것은 이곳에 정리를 해놓는다.


//
// Registry Usage
//

// Visual C++
// ...

// Delphi
uses
..., Registry;

procedure TEST_RegistryRW;
var
    __REG: TRegistry;
    str: string;
    strREGKeyVal: string;
    strNewKey: string;
begin
    str := 'SOFTWARE\TEST' + '\REG_TEST';
    strNewKey := 'TestKey';

    __REG := TRegistry.Create( KEY_WRITE );
    try
        //__REG.RootKey := HKEY_LOCAL_MACHINE;
        __REG.RootKey := HKEY_CURRENT_USER;
        __REG.OpenKey( str, True );
        __REG.WriteString( strNewKey, 'can you see this?' );
    finally
        __REG.Free;
        ShowMessage( 'WRITE: finish' );
    end;

    __REG := TRegistry.Create( KEY_READ );
    try
        //__REG.RootKey := HKEY_LOCAL_MACHINE;
        __REG.RootKey := HKEY_CURRENT_USER;  
        __REG.OpenKey( str, True );
        strREGKeyVal := __REG.ReadString( strNewKey );

        if( strREGKeyVal <> '' ) then ShowMessage( 'String: ' + strREGKeyVal );
    finally
        __REG.Free;
        ShowMessage( 'READ: finish' );
    end;
end;

// ---------------------------------------------------

//
// Checks Registered Object
//


// Visual C++
#include // Ole32.lib, Ole32.dll
CLSID ClsID;
char* pStrProgID = "Object.InterfaceName"; // Hello.Application
RESULT hr = CLSIDFromProgID( pStrProgID, &ClsID);
if( hr == S_OK )
// Registered
else
// Not Registered



// Delphi
uses
..., ActiveX;
procedure TEST_ChecksRegisteredObject
var
    ClassID: TGUID;
    strObject: string;
begin
    strObject := 'Object.InterfaceName'; // Hello.Application
    if( CLSIDFromProgID(PWideChar(WideString(strObject)), ClassID) = S_OK ) then begin
      ShowMessage( 'Registered' );
    end
    else begin
      ShowMessage( 'Not Registered' );
    end;
end;



-----
Cheers,
June

일요일, 2월 21, 2010

Fingerprint Requirement For a Work-Study Job?

Fingerprint Requirement For a Work-Study Job?
Source: http://ask.slashdot.org/story/10/02/20/233200/Fingerprint-Requirement-For-a-Work-Study-Job

BonesSB writes:
QUOTE: "I'm a student at a university in Massachusetts, where I have a federal work-study position. Yesterday, I got an email from the office that is responsible for student run organizations (one of which I work for) saying that I need to go to their office and have my finger prints taken for the purposes of clocking in and out of work. This raises huge privacy concerns for me, as it should for everybody else. I am in the process of contacting the local newspaper, getting the word out to students everywhere, and talking directly to the office regarding this. I got an email back with two very contradictory sentences: 'There will be no image of your fingerprints anywhere. No one will have access to your fingerprints. The machine is storing your prints as a means of identifying who you are when you touch it.' Does anybody else attend a school that requires something similar? This is an obvious slippery slope, and something I am not taking lightly. What else should I do?"

-----
What the fuck is going on? requires fingerprint for a federal work-study?
i think this makes privacy violation.
although
QUOTE: 'There will be no image of your fingerprints anywhere. No one will have access to your fingerprints. The machine is storing your prints as a means of identifying who you are when you touch it.'
who know? ;)

Cheers,
June

외국 대학 동영상 강의 (continued...)

외국 대학 동영상 강의

* 여러 대학 강의를 한 곳에 모음
 - Academic Earth: http://www.academicearth.org/


* 기타
동영상 강의
2007/07/12 14:25:27

전과목

오른쪽 위 Other Semasters라고 적힌 combo box를 클릭하면 다른 학기 과목도 볼 수 있다.
내가 보고 있는 거: machine structures, OS, 신호및시스템, 일반생물1, 심리학, 영양학, 해부학,
보고 싶은 거: 프로그램이해(?), 영상처리, DSP, 미시경제, 거시경제, 전자회로, 세포생물학, 일반화학,
mit에서는 http://ocw.mit.edu/index.html 에 대부분 강의를 공유한다. 위 링크는 그 중 동영상강의를 공개하는 과목 목록.
내가 보는 거: 알고리즘, 컴퓨터시스템, 전자회로, 선형대수, 미분방정식, 응용수학, 일반물리1,2,3, 일반생물, 일반화학
보고 싶은 거: 16.885J Aircraft Systems Engineering, Fall 2005, 3.091 Introduction to Solid State Chemistry, Fall 2004
3. 강의 정리한 블로그: http://freescienceonline.blogspot.com/
각종 과학과목을 죄다 정리해두었다. 난 대부분의 강의 사이트 링크를 여기서 얻었다. 일부는 동으로부터, 일부는 google 검색, google video 검색 http://video.google.com/videosearch?q=lecture+genre%3Aeducational 으로부터.
블로거는 물리 전공이지만 theoretical cs랑 math에 관심이 많단다.
4. 플로리다 대학교

Computer

종합
mit사람들이 가르치던데, 대학인지 아닌지도 모르겠다.
내가 보는 거: 프로그램이해(?), OOP(자바강의), 이산수학, 확률
보고 싶은 거: 전산수학, 계산이론, DBMS, AI
대학원 과정의 강의를 일부 동영상으로 공개한다. 2003년 이후의 강의는 워싱턴대에서 배포하는 프로그램을 설치하고 사용하면, 동영상+ppt+필기를 동시에 볼 수 있어서 좋다.
내가 보는 거: 프로그래밍언어론, 컴파일러, AI, HCI, 보안, DBMS, 전자거래
보고 싶은 거: 암호학, 컴퓨터구조, DBMS,


낱개
1. 연세대 마이크로프로세서 강좌: http://mpu.yonsei.ac.kr/Lecture/main_video_lect.htm
무슨 국가지원 사업의 일환으로 찍어뒀단다. 한국말 강의가 많다. 동영상에는 ppt파일만 보인다.
선진 대학에는 이런 과목이 있더라. structures and interpretation of computer programs.
프 로그래밍 언어론의 선수과목이라고 해야 할까_ 프로그래밍언어를 멋있게 수학적으로 배운다. lisp이나 scheme같은 학교용 언어를 단계적으로 배운다. 이 강의에서는 lisp. 이건 1986년에 HP사람들 가르친 강좌래. 책도 온라인에 공개돼있다. http://www-mitpress.mit.edu/sicp/full-text/book/book.html
3. Prof. Shiv가 공개하는 네트워킹 강좌 3개: http://www.ecse.rpi.edu/Homepages/shivkuma/teaching/video_index.html
Instructor는 인도사람같아 보이는데, 영어발음은 적당하면서도 빨라서 괜찮다.
4. 퍼듀대 영상처리1 강좌: http://cobweb.ecn.purdue.edu/~bouman/ee637/lectures05/
5. 하버드대 컴퓨터입문 강좌: http://www.fas.harvard.edu/~cscie1/?page=podcast&type=static
6. 전북대 알고리즘 강좌: http://internet512.chonbuk.ac.kr

Machine Learning
Hi there, I thought you might be interested in reading my shared items using Google Reader. Click the link below to view these items:

Or, if you use a feed reader, you can subscribe to their feed by copying and pasting this feed URL into your feed reader:

Hi there, I thought you might be interested in reading my shared items using Google Reader. Click the link below to view these items:

Or, if you use a feed reader, you can subscribe to their feed by copying and pasting this feed URL into your feed reader:

1. Video Lectures
2. Free Science and Video Lectures Online!

Mathematics
2. 아이다호대: http://www.sci.uidaho.edu/polya/
3. 미국용 공짜교육사이트 대수학강좌: http://www.free-ed.net/free-ed/Math/Algebra/Algebra01_VidLect.asp

다른 과목도 많은데, 모두 미국 시민한테만 보여주나보다.

Physics
3. 짧은 quantum physics

Medicine

세미나

전과목
1. mitworld

Computer
Physics
물리강좌 비디오 모음. 버클리, 칼텍, 프린스턴, 하버드, 스탠포드, 코넬 등 학교 링크가 보인다.
링크를 따라가보면 물리 강좌 외 다른 강의도 많이 보인다.
2. 양자역학: http://bethe.cornell.edu/

Medicine

기타


-----
Cheers,
June

토요일, 2월 20, 2010

How To Pick Any Padlock or Combination Lock

How To Pick Any Padlock or Combination Lock
Source: http://www.youtube.com/watch?v=rRcBNJMoFIw

ㅋㅋㅋ great idea, isn't it?
IMPORTANT: USE AT YOUR OWN RISK
so, shall we go to pick a padlock? ㅋㅋㅋ lol




Damn,,, another one here... ㅎㅎㅎ
Shim a combination lock in under 15 seconds
Source: http://www.youtube.com/watch?v=7jLngskydTo




-----
Cheers,
June

수요일, 2월 10, 2010

How to privilege elevation without UAC Dialog Window in VISTA and higher.

How to privilege elevation without UAC Dialog Window in VISTA and higher.

한번씩 사용하게 되는데 잊어 버릴까봐 적어 둔다. -_-;

Below codes are works very well for me. (VC++, Delphi) ㅋㅋ
You can makes an UAC elevation executor binary for distribute ActiveX.
(confer section [hook] in xxx.inf)

아래 VC++ 와 Delphi 코드는 내가 테스트할 때에는 잘 동작했다.
UAC Elevation 은 아래 코드와 같이 사용하니 편하실 대로 적절히 변경해서 사용하면 될 것이다.
그리고 inf 에서 HOOK 을 사용할 때에도 아래를 보고 하면 된다.

like this... (xxx.inf)
[Add.Code]
test_vista.ocx=test_vista.ocx
uacelevator.exe=uacelevator.exe
;
[...]
...
[uacelevator.exe]
file=thiscab
FileVersion=1,0,0,1
[Setup Hooks]
hook1=hook1
[hook1]
Run=%EXTRACT_DIR%\uacelevator.exe "test_vista.ocx"
;


Codes are here...
Source:
http://stackoverflow.com/questions/923350/delphi-prompt-for-uac-elevation-when-needed
http://pascalfonteneau.developpez.com/articles/delphi/vista/uac/VistaUACandDelphi.pdf

// VC++
// Calls UAC Dialog Window
// Note:
//    http://byung.egloos.com/2869040
BOOL RunAsAdmin( HWND hWnd, LPTSTR lpFile, LPTSTR lpParameters ) {
    SHELLEXECUTEINFO   sei;
    ZeroMemory ( &sei, sizeof(sei) );

    sei.cbSize          = sizeof(SHELLEXECUTEINFOW);
    sei.hwnd            = hWnd;
    sei.fMask           = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI;
    sei.lpVerb          = _TEXT("runas");
    sei.lpFile          = lpFile;
    sei.lpParameters    = lpParameters;
    sei.nShow           = SW_SHOWNORMAL;

    if( ! ShellExecuteEx(&sei) ) {
        printf( "Error: ShellExecuteEx failed 0x%x\n", GetLastError() );
        return FALSE;
    }

    return TRUE;
}

// Delphi
// Without UAC Dialog Window ( * NOTE: DOES NOT WORK!)
// Note:
//    http://stackoverflow.com/questions/923350/delphi-prompt-for-uac-elevation-when-needed
function RunAsAdmin(filename: string);
var
    ProcInfo: PROCESS_INFORMATION;
    StartInfo: TStartupInfo;
begin
  ZeroMemory( @StartInfo, sizeof(StartInfo) );
  StartInfo.cb := sizeof( StartInfo );
  StartInfo.wShowWindow := SW_SHOW;
  if not CreateProcessA(PAnsiChar(fileName), nil, nil, nil, false, CREATE_NEW_CONSOLE, nil, nil, StartInfo, ProcInfo) then

  //if not CreateProcessW(PWideChar(fileNameW), nil, nil, nil, false, CREATE_NEW_CONSOLE, nil, nil, StartInfo, ProcInfo) then
  //or: //if not CreateProcessW(nil,PWideChar(PathName), nil, nil, false, CREATE_NEW_CONSOLE, nil, nil, StartInfo, ProcInfo) then
  //ShowMessage(Format(‘The application could not be started: (%d) %s’,[GetLastError,SysErrorMessage(GetLastError)]));
end;

// Delphi
// Calls UAC Dialog Window
uses
  SysUtils, Windows, ShellApi, ShlObj, ComObj;
type
    ...
function RunAsAdmin(strFilename, strParam, strPath: string; opt: integer; handle: HWND; isVista: boolean);
var
    sellExecuteInfo: TShellExecuteInfo;
begin
    if( isVista ) then begin
sellExecuteInfo.lpVerb := 'runas';
if( handle <> 0 ) then sellExecuteInfo.Wnd := handle;
    end;

    sellExecuteInfo.lpFile := PChar( strFileName );
    sellExecuteInfo.lpParameters := PChar( strParam );
    sellExecuteInfo.lpDirectory := PChar( strPath );
    sellExecuteInfo.nShow := opt; // SW_MINIMIZE, ...

    Result := ShellExecuteEx( @sellExecuteInfo );
end;

RunAsAdmin( 'regsvr32', '/s', '.\' + 'test.ocx', SW_NORMAL, self.handle );


-----
i don't like above ways. i think just show UAC dialog window if needed it,
but why bypass this process?
if you learn more about the permission then i recommended you SHOULD use *NIX system.
so, i hate Windows series.
hmm... but i should work under the Windows for my job. shit...

Cheers,
June

수요일, 2월 03, 2010

Qualcomm Brew MP: Build failed, Debug process stopped.

Qualcomm Brew MP: Build failed, Debug process stopped.

Problem: "Error: Build failed, Debug process stopped." build succeed, but failed.
Source: https://brewmobileplatform.qualcomm.com/bmpforum/posts/list/759.page

This problem is driving me crazy so frequently. -_-;

but these trick are makes me freely... ^___^
1. Clean Solution
2. Clean Project (name of project)
3. quit VC++
4. delete "PROJECTNAME_win32.brewmp" and "PROJECTNAME.suo"(Visual Studio Solution User Options) in your project home directory.
5. then restart VC++

That's it. pretty easy?

These are seems to work well for me.
Thanks.

-----
Regards,
Ho-Jung Kim


-----
my posted message in Brew MP Forum.

Cheers,
June

화요일, 2월 02, 2010

Nokia N900 can running Mac OSX 10.3.x by PearPC

Nokia N900 can running Mac OSX 10.3 by PearPC

Mac OS X 10.3 Installed On Nokia N900 Because It's Possible
Source: http://thenokiablog.com/2010/01/31/mac-os-x-nokia-n900/

Finnish geek Toni Nikkanen(http://www.tuug.fi/~toni/serendipity/index.php?/archives/13-Mac-OS-X-10.3-running-on-the-N900%21.html) shared on video that it’s possible to put Mac OS X 10.3 on the Nokia N900(http://thenokiablog.com/2009/11/13/nokia-n900-review/), although uselessly slow. It took 2 hours to boot up! I don’t know about you, but I’m not patient enough to use an old OS not built for a mobile device. Nevertheless, the project was just for fun to claim the title of making the N900 the first smartphone ever to run a full version of OS X.



-----
Damn, great!

Cheers,
June

Webkit Coding Style Guidelines

Webkit Coding Style Guidelines
Source: http://webkit.org/coding/coding-style.html

WebKit Coding Style Guidelines

Indentation

  1. Use spaces, not tabs. Tabs should only appear in files that require them for semantic meaning, like Makefiles.
  2. The indent size is 4 spaces.

    Right:

    int main()
    {
        return 0;
    }
    

    Wrong:

    int main() 
    {
            return 0;
    }
    
  3. Code inside a namespace should not be indented.

    Right:

    // Document.h
    namespace WebCore {
    
    class Document {
        Document();
        ...
    };
    
    } // namespace WebCore
    
    // Document.cpp
    namespace WebCore {
    
    Document::Document()
    {
        ...
    }
    
    } // namespace WebCore
    

    Wrong:

    // Document.h
    namespace WebCore {
    
        class Document {
            Document();
            ...
        };
    
    } // namespace WebCore
    
    // Document.cpp
    namespace WebCore {
    
        Document::Document()
        {
            ...
        }
    
    } // namespace WebCore
    
  4. A case label should line up with its switch statement. The case statement is indented.

    Right:

    switch (condition) {
    case fooCondition:
    case barCondition:
        i++;
        break;
    default:
        i--;
    }
    

    Wrong:

    switch (condition) {
        case fooCondition:
        case barCondition:
            i++;
            break;
        default:
            i--;
    }
    
  5. Boolean expressions at the same nesting level that span multiple lines should have their operators on the left side of the line instead of the right side.

    Right:

    if (attr->name() == srcAttr
        || attr->name() == lowsrcAttr
        || (attr->name() == usemapAttr && attr->value().domString()[0] != '#'))
        return;
    

    Wrong:

    if (attr->name() == srcAttr ||
        attr->name() == lowsrcAttr ||
        (attr->name() == usemapAttr && attr->value().domString()[0] != '#'))
        return;
    

Spacing

  1. Do not place spaces around unary operators.

    Right:

    i++;
    

    Wrong:

    i ++;
    
  2. Do place spaces around binary and ternary operators.

    Right:

    y = m * x + b;
    f(a, b);
    c = a | b;
    return condition ? 1 : 0;
    

    Wrong:

    y=m*x+b;
    f(a,b);
    c = a|b;
    return condition ? 1:0;
    
  3. Do not place spaces before comma and semicolon.

    Right:

    for (int i = 0; i < 10; i++)
        doSomething();
    
    f(a, b);
    

    Wrong:

    for (int i = 0 ; i < 10 ; i++)
        doSomething();
    
    f(a , b) ;
    
  4. Place spaces between control statements and their parentheses.

    Right:

    if (condition)
        doIt();
    

    Wrong:

    if(condition)
        doIt();
    
  5. Do not place spaces between a function and its parentheses, or between a parenthesis and its content.

    Right:

    f(a, b);
    

    Wrong:

    f (a, b);
    f( a, b );
    

Line breaking

  1. Each statement should get its own line.

    Right:

    x++;
    y++;
    if (condition)
        doIt();
    

    Wrong:

    x++; y++;
    if (condition) doIt();
    
  2. An else statement should go on the same line as a preceding close brace if one is present, else it should line up with the if statement.

    Right:

    if (condition) {
        ...
    } else {
        ...
    }
    
    if (condition)
        doSomething();
    else
        doSomethingElse();
    
    if (condition)
        doSomething();
    else {
        ...
    }
    

    Wrong:

    if (condition) {
        ...
    }
    else {
        ...
    }
    
    if (condition) doSomething(); else doSomethingElse();
    
    if (condition) doSomething(); else {
        ...
    }
    
  3. An else if statement should be written as an if statement when the prior if concludes with a return statement.

    Right:

    if (condition) {
        ...
        return someValue;
    }
    if (condition) {
        ...
    }
    

    Wrong:

    if (condition) {
        ...
        return someValue;
    } else if (condition) {
        ...
    }
    

Braces

  1. Function definitions: place each brace on its own line.

    Right:

    int main()
    {
        ...
    }
    

    Wrong:

    int main() {
        ...
    }
    
  2. Other braces: place the open brace on the line preceding the code block; place the close brace on its own line.

    Right:

    class MyClass {
        ...
    };
    
    namespace WebCore {
        ...
    }
    
    for (int i = 0; i < 10; i++) {
        ...
    }
    

    Wrong:

    class MyClass 
    {
        ...
    };
    
  3. One-line control clauses should not use braces unless comments are included or a single statement spans multiple lines.

    Right:

    if (condition)
        doIt();
    
    if (condition) {
        // Some comment
        doIt();
    }
    
    if (condition) {
        myFunction(reallyLongParam1, reallyLongParam2, ...
            reallyLongParam5);
    }
    

    Wrong:

    if (condition) {
        doIt();
    }
    
    if (condition)
        // Some comment
        doIt();
    
    if (condition)
        myFunction(reallyLongParam1, reallyLongParam2, ...
            reallyLongParam5);
    
  4. Control clauses without a body should use empty braces:

    Right:

    for ( ; current; current = current->next) { }
    

    Wrong:

    for ( ; current; current = current->next);
    

Null, false and 0

  1. In C++, the null pointer value should be written as 0. In C, it should be written as NULL. In Objective-C and Objective-C++, follow the guideline for C or C++, respectively, but usenil to represent a null Objective-C object.
  2. C++ and C bool values should be written as true and false. Objective-C BOOL values should be written as YES and NO.
  3. Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.


    Right:

    if (condition)
        doIt();
        
    if (!ptr)
        return;
    
    if (!count)
        return;
    

    Wrong:

    if (condition == true)
        doIt();
        
    if (ptr == NULL)
        return;
        
    if (count == 0)
        return;
    
  4. In Objective-C, instance variables are initialized to zero automatically. Don't add explicit initializations to nil or NO in an init method.

Floating point literals

  1. Unless required in order to force floating point math, do not append .0.f and .0f to floating point literals.

    Right:

    const double duration = 60;
    
    void setDiameter(float diameter)
    {
        radius = diameter / 2;
    }
    
    setDiameter(10);
    
    const int framesPerSecond = 12;
    double frameDuration = 1.0 / framesPerSecond;
    

    Wrong:

    const double duration = 60.0;
    
    void setDiameter(float diameter)
    {
        radius = diameter / 2.f;
    }
    
    setDiameter(10.f);
    
    const int framesPerSecond = 12;
    double frameDuration = 1 / framesPerSecond; // integer division
    

Names

  1. Use CamelCase. Capitalize the first letter, including all letters in an acronym, in a class, struct, protocol, or namespace name. Lower-case the first letter, including all letters in an acronym, in a variable or function name.

    Right:

    struct Data;
    size_t bufferSize;
    class HTMLDocument;
    String mimeType();
    

    Wrong:

    struct data;
    size_t buffer_size;
    class HtmlDocument;
    String MIMEType();
    
  2. Use full words, except in the rare case where an abbreviation would be more canonical and easier to understand.

    Right:

    size_t characterSize;
    size_t length;
    short tabIndex; // more canonical
    

    Wrong:

    size_t charSize;
    size_t len;
    short tabulationIndex; // bizarre
    
  3. Prefix C++ data members with "m_".

    Right:

    class String {
        ...
        short m_length;
    };
    

    Wrong:

    class String {
        ...
        short length;
    };
    
  4. Prefix Objective-C instance variables with "_".

    Right:

    @class String
        ...
        short _length;
    @end
    

    Wrong:

    @class String
        ...
        short length;
    @end
    
  5. Precede boolean values with words like "is" and "did".

    Right:

    bool isValid;
    bool didSendData;
    

    Wrong:

    bool valid;
    bool sentData;
    
  6. Precede setters with the word "set". Use bare words for getters. Setter and getter names should match the names of the variables being set/gotten.

    Right:

    void setCount(size_t); // sets m_count
    size_t count(); // returns m_count
    

    Wrong:

    void setCount(size_t); // sets m_theCount
    size_t getCount();
    
  7. Use descriptive verbs in function names.

    Right:

    bool convertToASCII(short*, size_t);
    

    Wrong:

    bool toASCII(short*, size_t);
    
  8. Leave meaningless variable names out of function declarations.

    Right:

    void setCount(size_t);
    

    Wrong:

    void setCount(size_t count);
    
  9. Objective-C method names should follow the Cocoa naming guidelines — they should read like a phrase and each piece of the selector should start with a lowercase letter and use intercaps.
  10. Enum members should user InterCaps with an initial capital letter.
  11. Prefer const to #define. Prefer inline functions to macros.
  12. #defined constants should use all uppercase names with words separated by underscores.
  13. Macros that expand to function calls or other non-constant computation: these should be named like functions, and should have parentheses at the end, even if they take no arguments (with the exception of some special macros like ASSERT). Note that usually it is preferable to use an inline function in such cases instead of a macro.


    Right:

    #define WBStopButtonTitle() \
            NSLocalizedString(@"Stop", @"Stop button title")
    

    Wrong:

    #define WB_STOP_BUTTON_TITLE \
            NSLocalizedString(@"Stop", @"Stop button title")
    
    #define WBStopButtontitle \
            NSLocalizedString(@"Stop", @"Stop button title")
    
  14. #define, #ifdef "header guards" should be named exactly the same as the file (including case), replacing the '.' with a '_'.

    Right:

    // HTMLDocument.h
    #ifndef HTMLDocument_h
    #define HTMLDocument_h
    

    Wrong:

    // HTMLDocument.h
    #ifndef _HTML_DOCUMENT_H_
    #define _HTML_DOCUMENT_H_
    

Other Punctuation

  1. Constructors for C++ classes should initialize all of their members using C++ initializer syntax. Each member (and superclass) should be indented on a separate line, with the colon or comma preceding the member on that line.

    Right:

    MyClass::MyClass(Document* doc)
        : MySuperClass()
        , m_myMember(0)
        , m_doc(doc)
    {
    }
    
    MyOtherClass::MyOtherClass()
        : MySuperClass()
    {
    }
    

    Wrong:

    MyClass::MyClass(Document* doc) : MySuperClass()
    {
        m_myMember = 0;
        m_doc = doc;
    }
    
    MyOtherClass::MyOtherClass() : MySuperClass() {}
    
  2. Pointer types in non-C++ code — Pointer types should be written with a space between the type and the * (so the * is adjacent to the following identifier if any).
  3. Pointer and reference types in C++ code — Both pointer types and reference types should be written with no space between the type name and the * or &.

    Right:

    Image* SVGStyledElement::doSomething(PaintInfo& paintInfo)
    {
        SVGStyledElement* element = static_cast(node());
        const KCDashArray& dashes = dashArray();
    

    Wrong:

    Image *SVGStyledElement::doSomething(PaintInfo &paintInfo)
    {
        SVGStyledElement *element = static_cast(node());
        const KCDashArray &dashes = dashArray();
    

#include Statements

  1. All implementation files must #include "config.h" first. Header files should never include "config.h".

    Right:

    // RenderLayer.h
    #include "Node.h"
    #include "RenderObject.h"
    #include "RenderView.h"
    

    Wrong:

    // RenderLayer.h
    #include "config.h"
    
    #include "RenderObject.h"
    #include "RenderView.h"
    #include "Node.h"
    
  2. All implementation files must #include the primary header second, just after "config.h". So for example, Node.cpp should include Node.h first, before other files. This guarantees that each header's completeness is tested. This also assures that each header can be compiled without requiring any other header files be included first.
  3. Other #include statements should be in sorted order (case sensitive, as done by the command-line sort tool or the Xcode sort selection command). Don't bother to organize them in a logical order.

    Right:

    // HTMLDivElement.cpp
    #include "config.h"
    #include "HTMLDivElement.h"
    
    #include "Attribute.h"
    #include "HTMLElement.h"
    #include "QualifiedName.h"
    
    

    Wrong:

    // HTMLDivElement.cpp
    #include "HTMLElement.h"
    #include "HTMLDivElement.h"
    #include "QualifiedName.h"
    #include "Attribute.h"
    

"using" Statements

  1. In header files, do not use "using" statements in namespace (or global) scope.

    Right:

    // wtf/Vector.h
    
    namespace WTF {
    
    class VectorBuffer {
        using std::min;
        ...
    };
    
    } // namespace WTF
    

    Wrong:

    // wtf/Vector.h
    
    namespace WTF {
    
    using std::min;
        
    class VectorBuffer {
        ...
    };
    
    } // namespace WTF
    
  2. In header files in the WTF sub-library, however, it is acceptable to use "using" declarations at the end of the file to import one or more names in the WTF namespace into the global scope.

    Right:

    // wtf/Vector.h
    
    namespace WTF {
    
    } // namespace WTF
    
    using WTF::Vector;
    

    Wrong:

    // wtf/Vector.h
    
    namespace WTF {
    
    } // namespace WTF
    
    using namespace WTF;
    

    Wrong:

    // runtime/UString.h
    
    namespace WTF {
    
    } // namespace WTF
    
    using WTF::PlacementNewAdopt;
    
  3. In C++ implementation files, do not use statements of the form "using std::foo" to import names in the standard template library. Use "using namespace std" instead.

    Right:

    // HTMLBaseElement.cpp
    
    using namespace std;
    
    namespace WebCore {
    
    } // namespace WebCore
    

    Wrong:

    // HTMLBaseElement.cpp
    
    using std::swap;
    
    namespace WebCore {
    
    } // namespace WebCore
    
  4. In implementation files, if a "using namespace" statement is for a nested namespace whose parent namespace is defined in the file, put the statement inside that namespace definition.

    Right:

    // HTMLBaseElement.cpp
    
    namespace WebCore {
    
    using namespace HTMLNames;
    
    } // namespace WebCore
    

    Wrong:

    // HTMLBaseElement.cpp
    
    using namespace WebCore::HTMLNames;
    
    namespace WebCore {
    
    } // namespace WebCore
    
  5. In implementation files, put all other "using" statements at the beginning of the file, before any namespace definitions and after any "include" statements.

    Right:

    // HTMLSelectElement.cpp
    
    using namespace std;
    
    namespace WebCore {
    
    } // namespace WebCore
    

    Wrong:

    // HTMLSelectElement.cpp
    
    namespace WebCore {
    
    using namespace std;
    
    } // namespace WebCore

-----
Cheers,
June