Class Pointer


      1. template class
        1. Pointer< class Type >
    1. Programmer: Ryan Davis
    1. Description:

    1. Provides a safe pointer of any type. It will not
  1. allow you to dereference the pointer if the
  2. address of the pointer is NULL. It will allow you
  3. only to do "pointerish" things with it such as
  4. *, ->, or == but not + or other possibly dangerous
  5. (and not protectable) things...
      1. Public Methods:

          1. Pointer
        1. (Type * pointee = NULL);
        2. This is the constructor. It has a default value of NULL, so it can
  6. be used as the generic constructor as well. This constructor
  7. creates a smart Pointer object that points to the address
  8. passed in through .


      1. Pointer
    1. (const Pointer<Type> &);
    2. This is the copy constructor. It allows us to specify exactly what
  9. happens during a copy of a Pointer object. This isn't entirely
  10. necessary because our object is simple, but it is probably better
  11. to be explicitly obvious rather than not.


      1. ~Pointer
    1. ();
    2. This is the destructor. It doesn't do a thing. This is because the
  12. Pointer object never allocates memory, it just points...


    1. Pointer<Type> &
      1. operator =
    2. (const Pointer<Type> & pointee);
    3. This is the assignment operator. Not really needed since Pointer's
  13. don't have responsibility over what they point to (they don't // allocate or destroy memory), but it is my opinion that it is better
  14. to be explicit rather than suprised. This simply assigns the address
  15. of pointee to this.


    1. Pointer<Type> &
      1. operator =
    2. (Type * pointee);
    3. This is another assignment operator. This one is much like the
  16. previous, except that it allows to assign from a low level pointer,
  17. bypassing an invisible Construction/Copy/Destruction phase.


    1. Type *
      1. asPointer
    2. ();
    3. This conversion operator can change a high level pointer (our // object) to a low level pointer.


    1. Type &
      1. operator *
    2. ();
    3. This operator validates myData to make sure it is not NULL. Then
  18. returns a refernce to the object pointed to.


    1. Type *
      1. operator ->
    2. ();
    3. This operator validates myData to make sure myData is not NULL. It
  19. then returns a pointer to the object pointed to.
  20. WARNING: If you get a compile error, you are using a low level type.
  21. You can NOT use a low level type with this class, because -> is
  22. an illegal concept for low level types:
  23. int a = 42, *b = &a;
  24. b->???; this doesn't work because b->??? is the same as (*b).???
  25. and since a low level type is not a struct so '.' doesn't work...


    1. Boolean operator
      1. =
    2. (const Pointer<Type> &);
    3. This operator compares two addresses to see if they are the same and
  26. returns a Boolean.


    1. Boolean operator
      1. !=
    2. (const Pointer<Type> &);
    3. This operator uses the equality operator == as a function, but
  27. returns the opposite value.


      1. Protected Methods:

        1. void
          1. validate
        2. ();
        3. Validate asserts that the address we point to is not NULL.


      1. Protected Members:


        1. Type *
          1. myData;
        2. myData is the variable we use inside the pointer class. It is a
  28. a pointer of type Type. It cannot be accessed outside the Pointer
  29. class because myData is protected.