SVN / public / code / vorlesung-06 / String.h

Revision 11340
Date
Committerhb1003
Download
// Copyright 2016, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Hannah Bast <bast@cs.uni-freiburg.de>.

#ifndef VORLESUNG_06_STRING_H_
#define VORLESUNG_06_STRING_H_

#include <gtest/gtest.h>

// Gloal count of the number of objects created.
extern int objectCount;

// A simple string class.
class String {
 public:
  // Constructor (creates an empty string).
  String();
  FRIEND_TEST(StringTest, constructor);

  // Copy constructor.
  String(const String& s);

  // Destructor (frees any memory that has been allocated for this object).
  ~String();

  // Set to given string.
  void set(const char* s);
  FRIEND_TEST(StringTest, set);

  // Return the length of the string.
  int length() const;

 private:
  // The contents (characters) of the string.
  char* _contents;

  // The length of the string (size_t is an unsigned int of the "right" size
  // fort the machine).
  int _length;

  // Id of the object (for demonstrating purposes only).
  int _id;
};

#endif  // VORLESUNG_06_STRING_H_