home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 1.ddi / CLASSINC.ZIP / LTIME.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  11.3 KB  |  486 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. //
  4. // This file contains proprietary information of Borland International.
  5. // Copying or reproduction without prior written approval is prohibited.
  6. //
  7. // Copyright (c) 1990
  8. // Borland International
  9. // 1800 Scotts Valley Dr.
  10. // Scotts Valley, CA 95066
  11. // (408) 438-8400
  12. //
  13.  
  14. // Contents ----------------------------------------------------------------
  15. //
  16. //         BaseTime
  17. //         BaseTime::BaseTime                        default constructor
  18. //         BaseTime::BaseTime                        copy constructor
  19. //         BaseTime::BaseTime                        constructor
  20. //         BaseTime::hour
  21. //         BaseTime::minute
  22. //         BaseTime::second
  23. //         BaseTime::hundreths
  24. //
  25. //         BaseTime::setHour
  26. //         BaseTime::setMinute
  27. //         BaseTime::setSecond
  28. //         BaseTime::setHundreths
  29. //
  30. //         Time
  31. //         Time::Time                                default constructor
  32. //         Time::Time                                copy constructor
  33. //         Time::Time                                constructor
  34. //
  35. // Description
  36. //
  37. //      Provides the class BaseTime as an abstract base class for
  38. //      storing and formatting times.
  39. //      times.
  40. //
  41. //      Provides the Time class for storing times and converting them
  42. //      to ASCII strings of the form "1:23:45.67 pm"
  43. //
  44. // End ---------------------------------------------------------------------
  45.  
  46. // Interface Dependencies ---------------------------------------------------
  47.  
  48. #ifndef __LTIME_H
  49. #define __LTIME_H
  50.  
  51. #ifndef __ASSERT_H
  52. #include <assert.h>
  53. #define __ASSERT_H
  54. #endif
  55.  
  56. #ifndef __DOS_H
  57. #include <dos.h>
  58. #define __DOS_H
  59. #endif
  60.  
  61. #ifndef __STRNG_H
  62. #include <strng.h>
  63. #endif
  64.  
  65. // End Interface Dependencies ------------------------------------------------
  66.  
  67.  
  68. // Class //
  69.  
  70. class BaseTime : public Sortable
  71. {
  72. public:
  73.             unsigned hour() const;
  74.             unsigned minute() const;
  75.             unsigned second() const;
  76.             unsigned hundredths() const;
  77.             void         setHour( unsigned char );
  78.             void         setMinute( unsigned char );
  79.             void         setSecond( unsigned char );
  80.             void         setHundredths( unsigned char );
  81.  
  82.     virtual classType       isA() const = 0;
  83.     virtual char            *nameOf() const = 0;
  84.     virtual hashValueType   hashValue() const;
  85.     virtual int             isEqual( const Object& ) const;
  86.     virtual int             isLessThan( const Object& ) const;
  87.     virtual void            printOn( ostream& ) const = 0;
  88. protected:
  89.             BaseTime();
  90.             BaseTime( const BaseTime& );
  91.             BaseTime( unsigned char, unsigned char = 0, unsigned char = 0, unsigned char = 0 );
  92. private:
  93.             unsigned char HH;
  94.             unsigned char MM;
  95.             unsigned char SS;
  96.             unsigned char HD;
  97. };
  98.  
  99. // Description -------------------------------------------------------------
  100. //
  101. //         Defines a base time class.  This class provides a starting place
  102. //         for deriving usuable time classes.
  103. //
  104. // Constructors
  105. //
  106. //         BaseTime()
  107. //
  108. //     Default constructor
  109. //
  110. //         BaseTime( BaseTime& )
  111. //
  112. //     Copy constructor
  113. //
  114. //         BaseTime( H, . . . )
  115. //
  116. //         Constructs a base time object from a parameter list.
  117. //
  118. // Public Members
  119. //
  120. //         hour
  121. //
  122. //         Returns the hour portion of the base time object.
  123. //
  124. //         minute
  125. //
  126. //         Returns the hour portion of the base time object.
  127. //
  128. //         second
  129. //
  130. //         Returns the second portion of the base time object.
  131. //
  132. //         hundreths
  133. //
  134. //         Returns the hundreths portion of the base time object.
  135. //
  136. //         setHour
  137. //
  138. //         Sets the hour portion of the base time object.
  139. //
  140. //         setMinute
  141. //
  142. //         Sets the minute portion of the base time object.
  143. //
  144. //         setHundreths
  145. //
  146. //         Sets the hundreths portion of the base time object.
  147. //
  148. //         operator String()
  149. //
  150. //         Conversion operator to type string.
  151. //
  152. // Private Members
  153. //
  154. //         HH
  155. //
  156. //         The hour portion of the base time object.
  157. //
  158. //         MM
  159. //
  160. //         The minute portion of the base time object.
  161. //
  162. //         SS
  163. //
  164. //         The second portion of the base time object.
  165. //
  166. //         HD
  167. //
  168. //         The hundreths portion of the base time object.
  169. //
  170. // End ---------------------------------------------------------------------
  171.  
  172.  
  173. // Constructor //
  174.  
  175. inline BaseTime::BaseTime()
  176.  
  177. // Summary -----------------------------------------------------------------
  178. //
  179. //         Default constructor. Constructs a base time object.
  180. //
  181. // End ---------------------------------------------------------------------
  182. {
  183.     struct time t;              // From dos.h
  184.     gettime( &t );
  185.     HH = t.ti_hour;
  186.     MM = t.ti_min;
  187.     SS = t.ti_sec;
  188.     HD = t.ti_hund;
  189. }
  190. // End Constructor BaseTime::BaseTime //
  191.  
  192.  
  193. // Constructor //
  194.  
  195. inline BaseTime::BaseTime( const BaseTime& B ) :
  196.     HH(B.HH), MM(B.MM), SS(B.SS), HD(B.HD)
  197.  
  198. // Summary -----------------------------------------------------------------
  199. //
  200. //         Copy constructor.  Constructs a base time object from another
  201. //         base time object.
  202. //
  203. // Functional Description
  204. //
  205. //      We initialized each of the private data members of the class in
  206. //      the prototype, hence the function body is null.
  207. //
  208. // End ---------------------------------------------------------------------
  209. {
  210. }
  211. // End Constructor BaseTime::BaseTime //
  212.  
  213.  
  214. // Constructor //
  215.  
  216. inline BaseTime::BaseTime( unsigned char H, unsigned char M, unsigned char S, unsigned char D )
  217.  
  218. // Summary -----------------------------------------------------------------
  219. //
  220. //         Constructor.  Constructs a base time object from the given
  221. //         parameters.
  222. //
  223. // End ---------------------------------------------------------------------
  224. {
  225.     setHour( H );
  226.     setMinute( M );
  227.     setSecond( S );
  228.     setHundredths( D );
  229. }
  230. // End Constructor BaseTime::BaseTime //
  231.  
  232.  
  233. // Member Function //
  234.  
  235. inline unsigned BaseTime::hour() const
  236.  
  237. // Summary -----------------------------------------------------------------
  238. //
  239. //         Returns the hours portion of a base time object.
  240. //
  241. // End ---------------------------------------------------------------------
  242. {
  243.     return HH;
  244. }
  245. // End Member Function BaseTime::hour //
  246.  
  247.  
  248. // Member Function //
  249.  
  250. inline unsigned BaseTime::minute() const
  251.  
  252. // Summary -----------------------------------------------------------------
  253. //
  254. //         Returns the minutes portion of a base time object.
  255. //
  256. // End ---------------------------------------------------------------------
  257. {
  258.     return MM;
  259. }
  260. // End Member Function BaseTime::minute //
  261.  
  262.  
  263. // Member Function //
  264.  
  265. inline unsigned BaseTime::second() const
  266.  
  267. // Summary -----------------------------------------------------------------
  268. //
  269. //         Returns the seconds portion of a base time object.
  270. //
  271. // End ---------------------------------------------------------------------
  272. {
  273.     return SS;
  274. }
  275. // End Member Function BaseTime::second //
  276.  
  277.  
  278. // Member Function //
  279.  
  280. inline unsigned BaseTime::hundredths() const
  281.  
  282. // Summary -----------------------------------------------------------------
  283. //
  284. //         Returns the hundreths portion of a base time object.
  285. //
  286. // End ---------------------------------------------------------------------
  287. {
  288.     return HD;
  289. }
  290. // End Member Function BaseTime::hundreths //
  291.  
  292.  
  293. // Member Function //
  294.  
  295. inline void BaseTime::setHour( unsigned char anHour )
  296.  
  297. // Summary -----------------------------------------------------------------
  298. //
  299. //         Sets the hour portion of a base time object.
  300. //
  301. // End ---------------------------------------------------------------------
  302. {
  303.     assert( anHour < 24 );
  304.     HH = anHour;
  305. }
  306. // End Member Function BaseTime::setHour //
  307.  
  308.  
  309. // Member Function //
  310.  
  311. inline void BaseTime::setMinute( unsigned char M )
  312.  
  313. // Summary -----------------------------------------------------------------
  314. //
  315. //         Sets the minute portion of a base time object.
  316. //
  317. // End ---------------------------------------------------------------------
  318. {
  319.     assert( M < 60 );
  320.     MM = M;
  321. }
  322. // End Member Function BaseTime::setMinute //
  323.  
  324.  
  325. // Member Function //
  326.  
  327. inline void BaseTime::setSecond( unsigned char S )
  328.  
  329. // Summary -----------------------------------------------------------------
  330. //
  331. //         Sets the second portion of a base time object.
  332. //
  333. // End ---------------------------------------------------------------------
  334. {
  335.     assert( S < 60 );
  336.     SS = S;
  337. }
  338. // End Member Function BaseTime::setSecond //
  339.  
  340.  
  341. // Member Function //
  342.  
  343. inline void BaseTime::setHundredths( unsigned char D )
  344.  
  345. // Summary -----------------------------------------------------------------
  346. //
  347. //         Sets the hunderths portion of a base time object.
  348. //
  349. // End ---------------------------------------------------------------------
  350. {
  351.     assert( D < 100 );
  352.     HD = D;
  353. }
  354. // End Member Function BaseTime::setHundreths //
  355.  
  356.  
  357. // Class //
  358.  
  359. class Time: public BaseTime
  360. {
  361. public:
  362.             Time();
  363.             Time( const Time& );
  364.             Time( unsigned char, unsigned char = 0, unsigned char = 0, 
  365.                   unsigned char = 0 );
  366.     virtual classType       isA() const;
  367.     virtual char            *nameOf() const;
  368.     virtual void            printOn( ostream& ) const;
  369. };
  370.  
  371. // Description -------------------------------------------------------------
  372. //
  373. //         Defines a usable time class.
  374. //
  375. // Constructors
  376. //
  377. //         Time()
  378. //
  379. //         Default constructor
  380. //
  381. //         Time( Time& )
  382. //
  383. //         Copy constructor
  384. //
  385. //         Time( H, . . . )
  386. //
  387. //         Constructs a time object from a parameter list.
  388. //
  389. // Public Members
  390. //
  391. //         operator String()
  392. //
  393. //         Conversion operator to type string.
  394. //
  395. // Inherited Members
  396. //
  397. //         hour
  398. //
  399. //         Inherited from BaseTime
  400. //
  401. //         minute
  402. //
  403. //         Inherited from BaseTime
  404. //
  405. //         second
  406. //
  407. //         Inherited from BaseTime
  408. //
  409. //         hundreths
  410. //
  411. //         Inherited from BaseTime
  412. //
  413. //         setHour
  414. //
  415. //         Inherited from BaseTime
  416. //
  417. //         setMinute
  418. //
  419. //         Inherited from BaseTime
  420. //
  421. //         setHundreths
  422. //
  423. //         Inherited from BaseTime
  424. //
  425. // End ---------------------------------------------------------------------
  426.  
  427.  
  428. // Constructor //
  429.  
  430. inline Time::Time() : BaseTime()
  431.  
  432. // Summary -----------------------------------------------------------------
  433. //
  434. //         Default constructor.
  435. //
  436. // Functional Description
  437. //
  438. //      We construct the Time object using the constructor for BaseTime,
  439. //      hence the body of the constructor is null.
  440. //
  441. // End ---------------------------------------------------------------------
  442. {
  443. }
  444. // End Constructor Time::Time //
  445.  
  446.  
  447. // Constructor //
  448.  
  449. inline Time::Time( const Time& T ) : BaseTime( T )
  450.  
  451. // Summary -----------------------------------------------------------------
  452. //
  453. //         Copy constructor.
  454. //
  455. // Functional Description
  456. //
  457. //      We construct the Time object using the constructor for BaseTime,
  458. //      hence the body of the constructor is null.
  459. //
  460. // End ---------------------------------------------------------------------
  461. {
  462. }
  463. // End Constructor Time::Time //
  464.  
  465.  
  466. // Constructor //
  467.  
  468. inline Time::Time( unsigned char H, unsigned char M, unsigned char S, 
  469.                    unsigned char D ) :  BaseTime( H, M, S, D )
  470.  
  471. // Summary -----------------------------------------------------------------
  472. //
  473. //         Constructor from parameter list.
  474. //
  475. // Functional Description
  476. //
  477. //      We construct the Time object using the constructor for BaseTime,
  478. //      hence the body of the constructor is null.
  479. //
  480. // End ---------------------------------------------------------------------
  481. {
  482. }
  483. // End Constructor Time::Time //
  484.  
  485. #endif  // ifndef __LTIME_H //
  486.