gnoga_2.1.2_5f127c56/demo/chattanooga/chattanooga-db.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- Chattanooga: a simple chat program
-- Copyright (C) 2015 by PragmAda Software Engineering.  All rights reserved.
-- **************************************************************************
--
-- Database: the data stored by the program; currently all in memory
--
-- V1.0B  2015 Jan 05     1st beta release
--
with Ada.Containers.Hashed_Sets;
with UXStrings.Hash;

package Chattanooga.DB is
   use all type Gnoga.String;

   package Contact_Sets is new Ada.Containers.Hashed_Sets
     (Element_Type => String, Hash => UXStrings.Hash, Equivalent_Elements => UXStrings."=");

   type User_Data is record
      Contact  : Contact_Sets.Set;
      App_Data : App_Ptr;
   end record;

   procedure Add
     (User     : in String;
      App_Data : in App_Ptr);
   -- Adds User to DB with App_Data for its UI updates. User's Contact set will be populated with any existing users who have
   -- User in their Contact sets
   -- If Exists (User), raises Constraint_Error

   function Exists
     (User : String)
      return Boolean;
   -- Returns True if User is in the DB; False otherwise

   procedure Remove (User : in String);
   -- Removes User from the DB, if it is in the DB
   -- No effect if User is not in the DB

   function Send
     (From    : String;
      Message : String)
      return Natural;
   -- Sends Message to From's contacts
   -- Returns the number of contacts Message was sent to

   procedure Add_Friend
     (User   : in String;
      Friend : in String);
   -- Adds Friend to User's contact set, and User to Friend's

   procedure Remove_Friend
     (User   : in String;
      Friend : in String);
   -- Removes Friend from User's contact set, and User from Friend's
end Chattanooga.DB;
--
-- This is free software; you can redistribute it and/or modify it under
-- terms of the GNU General Public License as published by the Free Software
-- Foundation; version 2.
-- This software is distributed in the hope that it will be useful, but WITH
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-- for more details. Free Software Foundation, 59 Temple Place - Suite
-- 330, Boston, MA 02111-1307, USA.