기존 이솝 임베디드 포럼의 지식인 서비스가 게시판 형태로 변경되었습니다.

binder 쪽에 보면 sp<IServiceManager> defaultServiceManager() 와 같이 정의가 되는데

 sp<IServiceManager>  를 C++ 문법적으로 설명좀 부탁드립니다.

감사합니다.

-----------------------------------------------------------

sp<IServiceManager> defaultServiceManager()
{
    if (gDefaultServiceManager != NULL) return gDefaultServiceManager;
   
    {
        AutoMutex _l(gDefaultServiceManagerLock);
        if (gDefaultServiceManager == NULL) {
            gDefaultServiceManager = interface_cast<IServiceManager>(
                ProcessState::self()->getContextObject(NULL));
        }
    }
   
    return gDefaultServiceManager;
}

 -----------------------------------------------------------

----------------sp class 내용------------------

template <typename T>
class sp
{
public:
    inline sp() : m_ptr(0) { }

    sp(T* other);
    sp(const sp<T>& other);
    template<typename U> sp(U* other);
    template<typename U> sp(const sp<U>& other);

    ~sp();
   
    // Assignment

    sp& operator = (T* other);
    sp& operator = (const sp<T>& other);
   
    template<typename U> sp& operator = (const sp<U>& other);
    template<typename U> sp& operator = (U* other);
   
    // Reset
    void clear();
   
    // Accessors

    inline  T&      operator* () const  { return *m_ptr; }
    inline  T*      operator-> () const { return m_ptr;  }
    inline  T*      get() const         { return m_ptr; }

    // Operators
       
    COMPARE(==)
    COMPARE(!=)
    COMPARE(>)
    COMPARE(<)
    COMPARE(<=)
    COMPARE(>=)

private:   
    template<typename Y> friend class sp;

    T*              m_ptr;
};

------------------------------------------------------

탬플릿 문법을 안다고 해도, IServiceManager 클래스가 sp 클래스의 자료형으로 사용된다고 해도 해당  함수가 너무 난해 합니다., 또 어떻게   sp<IServiceManager>가  IServiceManager 클래스를 가르키는 포인터가 될 수 있는지 도무지 이해가 안 갑니다. 


고도리

2011.05.10 20:51:10
*.200.239.234

??? 어떤 문법적인지....


sp<>를 말씀하시는 것인지???


일단 sp는 smart pointer로 불리는 녀석입니다. 실제로는 strong pointer라고 불리는 듯 합니다만...

간단하게 풀어쓰면


IServiceManager *aa = defaultServiceManager();


대략 이런식으로 이해하시면 됩니다.

단 여기서 aa라는 포인터는 delete를 안해도 되는 포인터라고 보시면 됩니다.

김지원

2011.05.10 22:39:32
*.233.71.135

문법적으로는 C++ template을 찾아보시면 될 것이고,

http://winapi.co.kr/에서 C++문법란에서 찾으시면 될 듯 합니다.

http://ootips.org/yonat/4dev/smart-pointers.html

<>안쪽이 sp class내부에서 사용할 Typename(class)입니다.

defaultServiceManager()의 return이 sp<IServiceManager> object라는 의미입니다.

다른말로 sp class의 IServiceManager type을 사용하는 object instance가 return 됩니다.

List of Articles
번호 제목 글쓴이 날짜 조회 수
4568 framework hardware 라이브러리 load시 HMI 를 찾네요?? [1] 휘오른 2011-05-16 797
4567 u - boot 에서 usb 메모리 스틱을 읽으려고 하고 있습니다 [2] 우르멜 2011-05-15 741
4566 u-boot-1.3.4-aesop.100428 관련 [1] 고봉석 2011-05-15 527
4565 [질문]안드로이드 커널 컴파일 시에 드라이버 모듈(Host)이 포함 방... kieslv 2011-05-14 653
4564 u-boot-1.3.4 관련 [1] 고봉석 2011-05-13 534
4563 gpe x-windows filesystem을 nand에 기록해서 부팅시 에러가 납니다 [2] 오형호 2011-05-13 800
4562 카메라 포팅에서 꽉 막혀있습니다. [1] 한승우 2011-05-13 527
4561 커널 이미지(zImage) 올린 후 부팅 실패 (Uncompressing Linux....) file [1] heave_n 2011-05-12 1707
4560 커널 모듈 외부 참조 [1] snamy 2011-05-12 599
4559 Andorid ALSA에 관해서... [2] 꺼북이 2011-05-12 618
4558 u-boot 소스코드 중에.. [1] 준히오빠 2011-05-12 493
4557 아직 시리얼통신 해결하지못해 이렇게 또 질문드려요^~^ [1] 조승현 2011-05-12 570
4556 pxa255-pro3 보드에 안드로이드 포팅해보신분 계신가요? [1] 간지보이 2011-05-11 506
» binder 쪽에 보면 sp<IServiceManager> [2] 꺼북이 2011-05-10 674
4554 안드로이드의 프로세스관련... [1] 테크 2011-05-10 634
4553 [i.MX51] 메모리 초기화시 bad_page 문제 해결 방법? [1] 새희망 2011-05-07 933
4552 vendor폴더 아래의 새로운 products를 컴파일 하려면 어떻게 해야하... [1] 한승우 2011-05-07 518
4551 Android PowerManagerService Wakelock [3] 아틸라 2011-05-07 1563
4550 aesop 6410보드의 usb 1.1 host 관련 질문입니다.. [1] 우르멜 2011-05-06 535
4549 aesop - 6410 보드를 쓰고 있습니다 [2] 우르멜 2011-05-06 471

사용자 로그인