• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4  * COPYRIGHT:
5  * Copyright (c) 2002-2006, International Business Machines Corporation and
6  * others. All Rights Reserved.
7  ********************************************************************/
8 
9 /* Created by weiv 05/09/2002 */
10 
11 #ifndef U_TESTFW_DATAMAP
12 #define U_TESTFW_DATAMAP
13 
14 #include "unicode/resbund.h"
15 #include "unicode/testtype.h"
16 
17 
18 
19 U_NAMESPACE_BEGIN
20 class Hashtable;
21 U_NAMESPACE_END
22 
23 /** Holder of test data and settings. Allows addressing of items by name.
24  *  For test cases, names are defined in the "Headers" section. For settings
25  *  and info data, names are keys in data. Currently, we return scalar strings
26  *  and integers and arrays of strings and integers. Arrays should be deposited
27  *  of by the user.
28  */
29 class T_CTEST_EXPORT_API DataMap {
30 public:
31   virtual ~DataMap();
32 
33 protected:
34   DataMap();
35   int32_t utoi(const UnicodeString &s) const;
36 
37 
38 public:
39   /** get the string from the DataMap. Addressed by name
40    *  @param key name of the data field.
41    *  @return a string containing the data
42    */
43   virtual const UnicodeString getString(const char* key, UErrorCode &status) const = 0;
44 
45   /** get the string from the DataMap. Addressed by name
46    *  parses a bundle string into an integer
47    *  @param key name of the data field.
48    *  @return an integer containing the data
49    */
50   virtual int32_t getInt(const char* key, UErrorCode &status) const = 0;
51 
52   /**
53    * Get a signed integer without runtime parsing.
54    * @param key name of the data field.
55    * @param status UErrorCode in/out parameter
56    * @return the integer
57    */
58   virtual int32_t getInt28(const char* key, UErrorCode &status) const = 0;
59 
60   /**
61    * Get an unsigned integer without runtime parsing.
62    * @param key name of the data field.
63    * @param status UErrorCode in/out parameter
64    * @return the integer
65    */
66   virtual uint32_t getUInt28(const char* key, UErrorCode &status) const = 0;
67 
68   /**
69    * Get a vector of integers without runtime parsing.
70    * @param length output parameter for the length of the vector
71    * @param key name of the data field.
72    * @param status UErrorCode in/out parameter
73    * @return the integer vector, do not delete
74    */
75   virtual const int32_t *getIntVector(int32_t &length, const char *key, UErrorCode &status) const = 0;
76 
77   /**
78    * Get binary data without runtime parsing.
79    * @param length output parameter for the length of the data
80    * @param key name of the data field.
81    * @param status UErrorCode in/out parameter
82    * @return the binary data, do not delete
83    */
84   virtual const uint8_t *getBinary(int32_t &length, const char *key, UErrorCode &status) const = 0;
85 
86   /** get an array of strings from the DataMap. Addressed by name.
87    *  The user must dispose of it after usage, using delete.
88    *  @param key name of the data field.
89    *  @return a string array containing the data
90    */
91   virtual const UnicodeString* getStringArray(int32_t& count, const char* key, UErrorCode &status) const = 0;
92 
93   /** get an array of integers from the DataMap. Addressed by name.
94    *  The user must dispose of it after usage, using delete.
95    *  @param key name of the data field.
96    *  @return an integer array containing the data
97    */
98   virtual const int32_t* getIntArray(int32_t& count, const char* key, UErrorCode &status) const = 0;
99 
100   // ... etc ...
101 };
102 
103 // This one is already concrete - it is going to be instantiated from
104 // concrete data by TestData children...
105 class T_CTEST_EXPORT_API RBDataMap : public DataMap{
106 private:
107   Hashtable *fData;
108 
109 public:
110   virtual ~RBDataMap();
111 
112 public:
113   RBDataMap();
114 
115   RBDataMap(UResourceBundle *data, UErrorCode &status);
116   RBDataMap(UResourceBundle *headers, UResourceBundle *data, UErrorCode &status);
117 
118 public:
119   void init(UResourceBundle *data, UErrorCode &status);
120   void init(UResourceBundle *headers, UResourceBundle *data, UErrorCode &status);
121 
122   virtual const ResourceBundle *getItem(const char* key, UErrorCode &status) const;
123 
124   virtual const UnicodeString getString(const char* key, UErrorCode &status) const;
125   virtual int32_t getInt28(const char* key, UErrorCode &status) const;
126   virtual uint32_t getUInt28(const char* key, UErrorCode &status) const;
127   virtual const int32_t *getIntVector(int32_t &length, const char *key, UErrorCode &status) const;
128   virtual const uint8_t *getBinary(int32_t &length, const char *key, UErrorCode &status) const;
129 
130   virtual int32_t getInt(const char* key, UErrorCode &status) const;
131 
132   virtual const UnicodeString* getStringArray(int32_t& count, const char* key, UErrorCode &status) const;
133   virtual const int32_t* getIntArray(int32_t& count, const char* key, UErrorCode &status) const;
134 
135   // ... etc ...
136 };
137 
138 
139 #endif
140 
141